ADDED SRM/TCO13-2C-U/1A.cpp Index: SRM/TCO13-2C-U/1A.cpp ================================================================== --- SRM/TCO13-2C-U/1A.cpp +++ SRM/TCO13-2C-U/1A.cpp @@ -0,0 +1,137 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +typedef long double LD; +typedef complex CMP; + +class DancingFoxes { public: + int minimalDays(vector friendship) + { + static const int INF = 0x1fffffff; + int N = friendship.size(); + vector< vector > M(N, vector(N)); + for(int i=0; i1; ++s) + d -= (d+1)/3; + return s; + } +}; + +// 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(_, DancingFoxes().minimalDays(friendship));} +int main(){ + +CASE(0) + string friendship_[] = {"NNY", + "NNY", + "YYN"}; + vector friendship(friendship_, friendship_+sizeof(friendship_)/sizeof(*friendship_)); + int _ = 1; +END +CASE(1) + string friendship_[] = {"NNNNN", + "NNYYY", + "NYNYY", + "NYYNY", + "NYYYN"}; + vector friendship(friendship_, friendship_+sizeof(friendship_)/sizeof(*friendship_)); + int _ = -1; +END +CASE(2) + string friendship_[] = {"NNYYNN", + "NNNNYY", + "YNNNYN", + "YNNNNY", + "NYYNNN", + "NYNYNN"}; + vector friendship(friendship_, friendship_+sizeof(friendship_)/sizeof(*friendship_)); + int _ = 2; +END +CASE(3) + string friendship_[] = {"NNYNNNNYN", + "NNNNYNYNN", + "YNNYNYNNN", + "NNYNYNYYN", + "NYNYNNNNY", + "NNYNNNYNN", + "NYNYNYNNN", + "YNNYNNNNY", + "NNNNYNNYN"}; + vector friendship(friendship_, friendship_+sizeof(friendship_)/sizeof(*friendship_)); + int _ = 3; +END +CASE(4) + string friendship_[] = {"NY", + "YN"}; + vector friendship(friendship_, friendship_+sizeof(friendship_)/sizeof(*friendship_)); + int _ = 0; +END +CASE(5) + string friendship_[] = { +"NNYNNNNNN", +"NNNNNNNNY", +"YNNYNNNNN", +"NNYNYNNNN", +"NNNYNYNNN", +"NNNNYNYNN", +"NNNNNYNYN", +"NNNNNNYNY", +"NYNNNNNYN" +}; + vector friendship(friendship_, friendship_+sizeof(friendship_)/sizeof(*friendship_)); + int N = friendship.size(); + int idx[] = {0,8,1,2,3,4,5,6,7}; + for(int y=0; y friendship(friendship_, friendship_+sizeof(friendship_)/sizeof(*friendship_)); + int _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/TCO13-2C-U/1B.cpp Index: SRM/TCO13-2C-U/1B.cpp ================================================================== --- SRM/TCO13-2C-U/1B.cpp +++ SRM/TCO13-2C-U/1B.cpp @@ -0,0 +1,281 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +typedef long double LD; +typedef complex CMP; + +class TheMountain { public: + int minSum(int H, int W, vector Y, vector X, vector V) + { + const int N = Y.size(); + static const int INF = 0x3fffffff; + int best = INF; + + vector< vector > fixed(H, vector(W, 0)); + for(int i=0; i > td(H, vector(W)); + vector td_sum(H); + int td_end = 0; + for(int y=0; yx; --a) { + int req = 1; + if(0<=a+1&&a+1 > bu(H, vector(W)); + vector bu_sum(H); + int bu_begin = H; + for(int y=H-1; y>=0; --y) + { + for(int a=0; ax; --a) { + int req = 1; + if(0<=a+1&&a+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 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(_, TheMountain().minSum(n, m, rowIndex, columnIndex, element));} +int main(){ + +CASE(0) + int n = 2; + int m = 3; + int rowIndex_[] = {0, 0, 0, 1, 1, 1}; + vector rowIndex(rowIndex_, rowIndex_+sizeof(rowIndex_)/sizeof(*rowIndex_)); + int columnIndex_[] = {0, 1, 2, 0, 1, 2}; + vector columnIndex(columnIndex_, columnIndex_+sizeof(columnIndex_)/sizeof(*columnIndex_)); + int element_[] = {4, 6, 9, 1, 3, 6}; + vector element(element_, element_+sizeof(element_)/sizeof(*element_)); + int _ = 29; +END +CASE(1) + int n = 2; + int m = 3; + int rowIndex_[] = {1, 0, 1}; + vector rowIndex(rowIndex_, rowIndex_+sizeof(rowIndex_)/sizeof(*rowIndex_)); + int columnIndex_[] = {2, 2, 0}; + vector columnIndex(columnIndex_, columnIndex_+sizeof(columnIndex_)/sizeof(*columnIndex_)); + int element_[] = {5, 7, 6}; + vector element(element_, element_+sizeof(element_)/sizeof(*element_)); + int _ = 40; +END +CASE(2) + int n = 3; + int m = 3; + int rowIndex_[] = {0, 0, 2, 2}; + vector rowIndex(rowIndex_, rowIndex_+sizeof(rowIndex_)/sizeof(*rowIndex_)); + int columnIndex_[] = {0, 2, 2, 0}; + vector columnIndex(columnIndex_, columnIndex_+sizeof(columnIndex_)/sizeof(*columnIndex_)); + int element_[] = {1, 1, 1, 1}; + vector element(element_, element_+sizeof(element_)/sizeof(*element_)); + int _ = 15; +END +CASE(3) + int n = 2; + int m = 2; + int rowIndex_[] = {0, 0, 1, 1}; + vector rowIndex(rowIndex_, rowIndex_+sizeof(rowIndex_)/sizeof(*rowIndex_)); + int columnIndex_[] = {0, 1, 1, 0}; + vector columnIndex(columnIndex_, columnIndex_+sizeof(columnIndex_)/sizeof(*columnIndex_)); + int element_[] = {5, 8, 5, 8}; + vector element(element_, element_+sizeof(element_)/sizeof(*element_)); + int _ = -1; +END +CASE(4) + int n = 1; + int m = 3; + int rowIndex_[] = {0}; + vector rowIndex(rowIndex_, rowIndex_+sizeof(rowIndex_)/sizeof(*rowIndex_)); + int columnIndex_[] = {1}; + vector columnIndex(columnIndex_, columnIndex_+sizeof(columnIndex_)/sizeof(*columnIndex_)); + int element_[] = {1}; + vector element(element_, element_+sizeof(element_)/sizeof(*element_)); + int _ = -1; +END +CASE(5) + int n = 123; + int m = 45; + int rowIndex_[] = {2, 3, 5, 7, 11}; + vector rowIndex(rowIndex_, rowIndex_+sizeof(rowIndex_)/sizeof(*rowIndex_)); + int columnIndex_[] = {13, 17, 19, 23, 29}; + vector columnIndex(columnIndex_, columnIndex_+sizeof(columnIndex_)/sizeof(*columnIndex_)); + int element_[] = {100, 200, 300, 400, 500}; + vector element(element_, element_+sizeof(element_)/sizeof(*element_)); + int _ = 367047; +END +CASE(6) + int n = 200; + int m = 200; + int rowIndex_[] = {5}; + vector rowIndex(rowIndex_, rowIndex_+sizeof(rowIndex_)/sizeof(*rowIndex_)); + int columnIndex_[] = {8}; + vector columnIndex(columnIndex_, columnIndex_+sizeof(columnIndex_)/sizeof(*columnIndex_)); + int element_[] = {666}; + vector element(element_, element_+sizeof(element_)/sizeof(*element_)); + int _ = 5737554; +END +CASE(7) + int n = 10; + int m = 10; + int rowIndex_[] = {0, 8, 7}; + vector rowIndex(rowIndex_, rowIndex_+sizeof(rowIndex_)/sizeof(*rowIndex_)); + int columnIndex_[] = {3, 1, 9}; + vector columnIndex(columnIndex_, columnIndex_+sizeof(columnIndex_)/sizeof(*columnIndex_)); + int element_[] = {5, 4, 7}; + vector element(element_, element_+sizeof(element_)/sizeof(*element_)); + int _ = 593; +END +CASE(8) + int n = 200; + int m = 200; + int rowIndex_[] = {129,99,142,33,111,174,169,176,83,143,70,116,193,139,7,35,111,4,189,111,170,29,16,87,115,4,60,71,37,138,128,38,61,176,187,66,64,84,120,104,124,129,91,137,114,187,97,115,151,140}; + vector rowIndex(rowIndex_, rowIndex_+sizeof(rowIndex_)/sizeof(*rowIndex_)); + int columnIndex_[] = {191,148,194,13,90,17,185,163,17,170,193,165,140,158,85,15,56,91,9,68,153,83,9,97,74,40,160,165,49,151,173,98,123,44,139,164,66,112,141,172,91,147,71,167,123,53,189,86,71,171}; + vector columnIndex(columnIndex_, columnIndex_+sizeof(columnIndex_)/sizeof(*columnIndex_)); + int element_[] = {953,216,307,197,970,590,659,153,79,262,628,153,106,904,888,249,224,839,29,327,664,619,387,325,865,849,516,313,649,135,713,585,347,279,702,837,682,817,844,981,401,410,982,891,167,102,646,73,784,455}; + vector element(element_, element_+sizeof(element_)/sizeof(*element_)); + int _ = -1; +END +/* +CASE(9) + int n = ; + int m = ; + int rowIndex_[] = ; + vector rowIndex(rowIndex_, rowIndex_+sizeof(rowIndex_)/sizeof(*rowIndex_)); + int columnIndex_[] = ; + vector columnIndex(columnIndex_, columnIndex_+sizeof(columnIndex_)/sizeof(*columnIndex_)); + int element_[] = ; + vector element(element_, element_+sizeof(element_)/sizeof(*element_)); + int _ = ; +END +*/ +} +// END CUT HERE ADDED YNGraph.rb Index: YNGraph.rb ================================================================== --- YNGraph.rb +++ YNGraph.rb @@ -0,0 +1,19 @@ +STDERR.print "Number of nodes? " +V = gets.to_i + +STDERR.print "Directed (u/d)? " +D = (gets.chomp.downcase=="d"); + +ES = [] +loop do + STDERR.print "Edge (u v)? " + edge = gets.split.map(&:to_i) + break if edge.size==0 + ES << edge +end + +V.times do |y| + puts (0...V).map{|x| + (D ? ES.index([y,x]) : ES.index([y,x]) || ES.index([x,y])) ? "Y" : "N" + }*"" +end