ADDED SRM/635-U/1A-U.cpp Index: SRM/635-U/1A-U.cpp ================================================================== --- SRM/635-U/1A-U.cpp +++ SRM/635-U/1A-U.cpp @@ -0,0 +1,132 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +typedef complex CMP; + +class SimilarRatingGraph { public: + double maxLength(vector date, vector rating) + { + const int N = date.size(); + double best = 0.0; + + for(int s=0; s+1 +double start_time; string timer() + { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } +template ostream& operator<<(ostream& os, const vector& v) + { os << "{ "; + for(typename vector::const_iterator it=v.begin(); it!=v.end(); ++it) + os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } +void verify_case(const double& Expected, const double& Received) { + bool ok = (abs(Expected - Received) < 1e-9); + if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; + cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } +#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); +#define END verify_case(_, SimilarRatingGraph().maxLength(date, rating));} +int main(){ + +CASE(0) + int date_[] = {1,2,4,8,16,32}; + vector date(date_, date_+sizeof(date_)/sizeof(*date_)); + int rating_[] = {1,2,4,8,16,32}; + vector rating(rating_, rating_+sizeof(rating_)/sizeof(*rating_)); + double _ = 42.42640687119285; +END +CASE(1) + int date_[] = {81,104,120,124,134,137}; + vector date(date_, date_+sizeof(date_)/sizeof(*date_)); + int rating_[] = {1866,2332,2510,2678,2876,3002}; + vector rating(rating_, rating_+sizeof(rating_)/sizeof(*rating_)); + double _ = 168.04761230080004; +END +CASE(2) + int date_[] = {10,11,13,15,19}; + vector date(date_, date_+sizeof(date_)/sizeof(*date_)); + int rating_[] = {10,14,15,23,25}; + vector rating(rating_, rating_+sizeof(rating_)/sizeof(*rating_)); + double _ = 12.7183472062349; +END +CASE(3) + int date_[] = {1,2,3,4}; + vector date(date_, date_+sizeof(date_)/sizeof(*date_)); + int rating_[] = {1700,1800,1750,1850}; + vector rating(rating_, rating_+sizeof(rating_)/sizeof(*rating_)); + double _ = 100.00499987500625; +END +CASE(4) + int date_[] = {1,2,3,4}; + vector date(date_, date_+sizeof(date_)/sizeof(*date_)); + int rating_[] = {1,4,9,16}; + vector rating(rating_, rating_+sizeof(rating_)/sizeof(*rating_)); + double _ = 0.0; +END +CASE(5) + int date_[] = {5,11,25,58,92,162,255,350,458,566,677,792,919,1051,1189,1331,1489,1673,1882,2093,2315,2541,2771,3012,3254,3524,3797,4087,4379,4675,4973,5278,5588,5904,6225,6550,6888,7249,7612,8018,8428,8847,9267,9688,10109,10530,10964,11407,11870,12340,12811,13288,13768,14249,14734,15242,15774,16306,16847,17400,17966,18533,19108,19692,20278,20871,21471,22074,22679,23297,23916,24553,25190,25829,26472,27135,27814,28497,29181,29865,30555,31272,31994,32729,33487,34246,35005,35764,36537,37326,38119,38913,39725,40538,41360,42185,43010,43840,44671,45509,46350,47205,48063,48932,49807,50691,51577,52464,53289,54119,54950,55788,56629,57484,58342,59211,60086,60970,61856,62743,63568,64398,65388}; + vector date(date_, date_+sizeof(date_)/sizeof(*date_)); + int rating_[] = {1505,1462,1436,1416,1463,1421,1411,1450,1497,1465,1423,1394,1391,1367,1358,1323,1310,1279,1268,1279,1311,1342,1359,1387,1414,1376,1424,1382,1373,1335,1359,1318,1275,1266,1227,1203,1168,1163,1184,1144,1169,1207,1250,1235,1209,1162,1124,1148,1168,1202,1190,1155,1179,1194,1195,1195,1203,1240,1218,1245,1220,1190,1208,1180,1182,1148,1139,1126,1152,1159,1147,1158,1112,1091,1101,1116,1123,1086,1126,1110,1128,1085,1132,1145,1135,1140,1117,1081,1120,1131,1081,1032,1071,1102,1071,1065,1068,1027,980,947,987,968,959,980,990,974,1003,996,999,958,911,878,918,899,890,911,921,905,934,927,930,889,844}; + vector rating(rating_, rating_+sizeof(rating_)/sizeof(*rating_)); + double _ = 11940.179271014536; +END +/* +CASE(6) + int date_[] = ; + vector date(date_, date_+sizeof(date_)/sizeof(*date_)); + int rating_[] = ; + vector rating(rating_, rating_+sizeof(rating_)/sizeof(*rating_)); + double _ = ; +END +CASE(7) + int date_[] = ; + vector date(date_, date_+sizeof(date_)/sizeof(*date_)); + int rating_[] = ; + vector rating(rating_, rating_+sizeof(rating_)/sizeof(*rating_)); + double _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/635-U/1B.cpp Index: SRM/635-U/1B.cpp ================================================================== --- SRM/635-U/1B.cpp +++ SRM/635-U/1B.cpp @@ -0,0 +1,160 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +typedef complex CMP; + +class StoryFromTCO { public: + int minimumChanges(vector places, vector cutoff) + { + const int N = places.size(); + vector> cp; + for(int i=0; i lm(N); // i-th place candidate can be put at >=lm[i] + for(int i=0; i v) + { + const int N = v.size(); + const int HOLE = 0x7fffffff; + int ans = 0; + multiset stock; + for(int i=0; ii; --k) + if(v[k]<=i) { + stock.insert(v[k]); + v[k] = HOLE; + break; + } + } + + if(stock.empty() || !(*stock.begin()<=i)) + return -1; + + ++ans; + if(v[i] != HOLE) stock.insert(v[i]); + v[i] = *stock.begin(); + stock.erase(stock.begin()); + } + return ans; + } +}; + +// BEGIN CUT HERE +#include +double start_time; string timer() + { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } +template ostream& operator<<(ostream& os, const vector& v) + { os << "{ "; + for(typename vector::const_iterator it=v.begin(); it!=v.end(); ++it) + os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } +void verify_case(const int& Expected, const int& Received) { + bool ok = (Expected == Received); + if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; + cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } +#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); +#define END verify_case(_, StoryFromTCO().minimumChanges(places, cutoff));} +int main(){ + +CASE(0) + int places_[] = {20,100,500,50}; + vector places(places_, places_+sizeof(places_)/sizeof(*places_)); + int cutoff_[] = {7500,2250,150,24}; + vector cutoff(cutoff_, cutoff_+sizeof(cutoff_)/sizeof(*cutoff_)); + int _ = 3; +END +CASE(1) + int places_[] = {5,4,3,2,1}; + vector places(places_, places_+sizeof(places_)/sizeof(*places_)); + int cutoff_[] = {5,4,3,2,1}; + vector cutoff(cutoff_, cutoff_+sizeof(cutoff_)/sizeof(*cutoff_)); + int _ = 0; +END +CASE(2) + int places_[] = {1,5,5,5}; + vector places(places_, places_+sizeof(places_)/sizeof(*places_)); + int cutoff_[] = {8,6,4,2}; + vector cutoff(cutoff_, cutoff_+sizeof(cutoff_)/sizeof(*cutoff_)); + int _ = -1; +END +CASE(3) + int places_[] = {3,1,5}; + vector places(places_, places_+sizeof(places_)/sizeof(*places_)); + int cutoff_[] = {6,4,2}; + vector cutoff(cutoff_, cutoff_+sizeof(cutoff_)/sizeof(*cutoff_)); + int _ = 3; +END +CASE(4) + int places_[] = {14,11,42,9,19}; + vector places(places_, places_+sizeof(places_)/sizeof(*places_)); + int cutoff_[] = {11,16,37,41,47} +; + vector cutoff(cutoff_, cutoff_+sizeof(cutoff_)/sizeof(*cutoff_)); + int _ = 4; +END +CASE(5) + int places_[] = {4,1,3,3,2,4,5,5,4,4}; + vector places(places_, places_+sizeof(places_)/sizeof(*places_)); + int cutoff_[] = {3,3,5,2,4,4,5,4,3,5}; + vector cutoff(cutoff_, cutoff_+sizeof(cutoff_)/sizeof(*cutoff_)); + int _ = 6; +END +CASE(6) + int places_[] = {213,177,237,444,497,315,294,104,522,635,13,26,22,276,88,249,374,17,42,245,80,553,121,625,62,105, +53,132,178,250,18,210,492,181,2,99,29,21,62,218,188,584,702,63,41,79,28,452,2}; + vector places(places_, places_+sizeof(places_)/sizeof(*places_)); + int cutoff_[] = {33,40,41,48,74,84,117,125,126,164,197,197,201,218,222,231,244,277,290,309,321,321,360,376,440, +442,465,477,491,513,639,645,647,675,706,710,726,736,736,765,801,838,845,854,863,865,887,902,908}; + vector cutoff(cutoff_, cutoff_+sizeof(cutoff_)/sizeof(*cutoff_)); + int _ = 23; +END +/* +CASE(7) + int places_[] = ; + vector places(places_, places_+sizeof(places_)/sizeof(*places_)); + int cutoff_[] = ; + vector cutoff(cutoff_, cutoff_+sizeof(cutoff_)/sizeof(*cutoff_)); + int _ = ; +END +CASE(8) + int places_[] = ; + vector places(places_, places_+sizeof(places_)/sizeof(*places_)); + int cutoff_[] = ; + vector cutoff(cutoff_, cutoff_+sizeof(cutoff_)/sizeof(*cutoff_)); + int _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/635-U/1C-U.cpp Index: SRM/635-U/1C-U.cpp ================================================================== --- SRM/635-U/1C-U.cpp +++ SRM/635-U/1C-U.cpp @@ -0,0 +1,154 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +typedef complex CMP; + +static const unsigned MODVAL = 1000000009; +struct mint +{ + unsigned val; + mint():val(0){} + mint(int x):val(x%MODVAL) {} + mint(unsigned x):val(x%MODVAL) {} + mint(LL x):val(x%MODVAL) {} +}; +mint& operator+=(mint& x, mint y) { return x = x.val+y.val; } +mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; } +mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; } +mint operator+(mint x, mint y) { return x+=y; } +mint operator-(mint x, mint y) { return x-=y; } +mint operator*(mint x, mint y) { return x*=y; } + +mint POW(mint x, LL e) { mint v=1; for(;e;x*=x,e>>=1) if(e&1) v*=x; return v; } +mint& operator/=(mint& x, mint y) { return x *= POW(y, MODVAL-2); } +mint operator/(mint x, mint y) { return x/=y; } + +class ColourHolic { public: + int countSequences(vector n) + { + mint ans = 0; + for(int c=0; c<4; ++c) if(n[c]) { + n[c]--; + ans += calc(c, n); + n[c]++; + } + return ans.val; + } + + map memo; + mint calc(int cp, vector& n) + { + if(n[0]+n[1]+n[2]+n[3]==0) + return 1; + + vector nn; + for(int c=0; c<4; ++c) if(c!=cp) + nn.push_back(n[c]); + sort(nn.begin(), nn.end()); + LL key = n[cp]; + for(int v: nn) + key=key*50001+v; + if(memo.count(key)) + return memo[key]; + + int tot = accumulate(n.begin(), n.end(), 0); + int ma = max(nn.front(), nn.back()); + if(ma*2 > tot+1) + return 0; + + mint ans = 0; + for(int c=0; c<4; ++c) if(c!=cp && n[c]) { + n[c]--; + ans += calc(c, n); + n[c]++; + } + return memo[key] = ans; + } +}; + +// BEGIN CUT HERE +#include +double start_time; string timer() + { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } +template ostream& operator<<(ostream& os, const vector& v) + { os << "{ "; + for(typename vector::const_iterator it=v.begin(); it!=v.end(); ++it) + os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } +void verify_case(const int& Expected, const int& Received) { + bool ok = (Expected == Received); + if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; + cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } +#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); +#define END verify_case(_, ColourHolic().countSequences(n));} +int main(){ + +CASE(0) + int n_[] = {1,0,2,3}; + vector n(n_, n_+sizeof(n_)/sizeof(*n_)); + int _ = 10; +END +CASE(1) + int n_[] = {1,1,1,1}; + vector n(n_, n_+sizeof(n_)/sizeof(*n_)); + int _ = 24; +END +CASE(2) + int n_[] = {42,42,42,9001}; + vector n(n_, n_+sizeof(n_)/sizeof(*n_)); + int _ = 0; +END +CASE(3) + int n_[] = {8,0,0,8}; + vector n(n_, n_+sizeof(n_)/sizeof(*n_)); + int _ = 2; +END +CASE(4) + int n_[] = {0,5,1,3}; + vector n(n_, n_+sizeof(n_)/sizeof(*n_)); + int _ = 4; +END +CASE(5) + int n_[] = {4,2,1,3}; + vector n(n_, n_+sizeof(n_)/sizeof(*n_)); + int _ = 1074; +END +CASE(6) + int n_[] = {15,900,357,22}; + vector n(n_, n_+sizeof(n_)/sizeof(*n_)); + int _ = 0; +END +CASE(7) + int n_[] = {110,30000,200,29999}; + vector n(n_, n_+sizeof(n_)/sizeof(*n_)); + int _ = 118115350; +END +/* +CASE(8) + int n_[] = ; + vector n(n_, n_+sizeof(n_)/sizeof(*n_)); + int _ = ; +END +CASE(9) + int n_[] = ; + vector n(n_, n_+sizeof(n_)/sizeof(*n_)); + int _ = ; +END +*/ +} +// END CUT HERE