4fd800b3a8 2011-02-23 kinaba: #include <iostream> 4fd800b3a8 2011-02-23 kinaba: #include <sstream> 4fd800b3a8 2011-02-23 kinaba: #include <iomanip> 4fd800b3a8 2011-02-23 kinaba: #include <vector> 4fd800b3a8 2011-02-23 kinaba: #include <string> 4fd800b3a8 2011-02-23 kinaba: #include <map> 4fd800b3a8 2011-02-23 kinaba: #include <set> 4fd800b3a8 2011-02-23 kinaba: #include <algorithm> 4fd800b3a8 2011-02-23 kinaba: #include <numeric> 4fd800b3a8 2011-02-23 kinaba: #include <iterator> 4fd800b3a8 2011-02-23 kinaba: #include <functional> 4fd800b3a8 2011-02-23 kinaba: #include <complex> 4fd800b3a8 2011-02-23 kinaba: #include <queue> 4fd800b3a8 2011-02-23 kinaba: #include <stack> 4fd800b3a8 2011-02-23 kinaba: #include <cmath> 4fd800b3a8 2011-02-23 kinaba: #include <cassert> 4fd800b3a8 2011-02-23 kinaba: #include <cstring> 4fd800b3a8 2011-02-23 kinaba: using namespace std; 4fd800b3a8 2011-02-23 kinaba: typedef long long LL; 4fd800b3a8 2011-02-23 kinaba: typedef complex<double> CMP; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: class StonesGame { public: 4fd800b3a8 2011-02-23 kinaba: string winner(int N, int M, int K, int L) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: if( isOneStep(N,M,K,L) ) // M から L に一手でいけるなら先手の勝ち 4fd800b3a8 2011-02-23 kinaba: return "Romeo"; 4fd800b3a8 2011-02-23 kinaba: for(int x=1; x<=N; ++x) 4fd800b3a8 2011-02-23 kinaba: if( isOneStep(N,M,K,x) && !isOneStep(N,x,K,L) ) 4fd800b3a8 2011-02-23 kinaba: return "Draw"; // 先手も後手も勝てない場合 4fd800b3a8 2011-02-23 kinaba: return "Strangelet"; // M からは「Lに一手で行けちゃうx」にしか行けないなら、後手の勝ち 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: bool isOneStep(int N, int M, int K, int L) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: int d = abs(M-L); 4fd800b3a8 2011-02-23 kinaba: if( d<K && (d%2)!=(K%2) ) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: int mid = (M+L)/2; // M と L の真ん中を中心に 4fd800b3a8 2011-02-23 kinaba: int e = mid + K/2; // 右に K/2 4fd800b3a8 2011-02-23 kinaba: int b = e - K+1; // 左に K/2 伸ばした範囲をreverseすればMがLに行けるはず… 4fd800b3a8 2011-02-23 kinaba: return 1<=b && e<=N; // そんな範囲で大丈夫か 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: return false; 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: }; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: // BEGIN CUT HERE 4fd800b3a8 2011-02-23 kinaba: #include <ctime> 4fd800b3a8 2011-02-23 kinaba: double start_time; string timer() 4fd800b3a8 2011-02-23 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 4fd800b3a8 2011-02-23 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 4fd800b3a8 2011-02-23 kinaba: { os << "{ "; 4fd800b3a8 2011-02-23 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 4fd800b3a8 2011-02-23 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 4fd800b3a8 2011-02-23 kinaba: void verify_case(const string& Expected, const string& Received) { 4fd800b3a8 2011-02-23 kinaba: bool ok = (Expected == Received); 4fd800b3a8 2011-02-23 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 4fd800b3a8 2011-02-23 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 4fd800b3a8 2011-02-23 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 4fd800b3a8 2011-02-23 kinaba: #define END verify_case(_, StonesGame().winner(N, M, K, L));} 4fd800b3a8 2011-02-23 kinaba: int main(){ 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: CASE(0) 4fd800b3a8 2011-02-23 kinaba: int N = 3; 4fd800b3a8 2011-02-23 kinaba: int M = 1; 4fd800b3a8 2011-02-23 kinaba: int K = 1; 4fd800b3a8 2011-02-23 kinaba: int L = 2; 4fd800b3a8 2011-02-23 kinaba: string _ = "Draw"; 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: CASE(1) 4fd800b3a8 2011-02-23 kinaba: int N = 5; 4fd800b3a8 2011-02-23 kinaba: int M = 1; 4fd800b3a8 2011-02-23 kinaba: int K = 2; 4fd800b3a8 2011-02-23 kinaba: int L = 2; 4fd800b3a8 2011-02-23 kinaba: string _ = "Romeo"; 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: CASE(2) 4fd800b3a8 2011-02-23 kinaba: int N = 5; 4fd800b3a8 2011-02-23 kinaba: int M = 5; 4fd800b3a8 2011-02-23 kinaba: int K = 2; 4fd800b3a8 2011-02-23 kinaba: int L = 3; 4fd800b3a8 2011-02-23 kinaba: string _ = "Strangelet"; 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: CASE(3) 4fd800b3a8 2011-02-23 kinaba: int N = 5; 4fd800b3a8 2011-02-23 kinaba: int M = 5; 4fd800b3a8 2011-02-23 kinaba: int K = 2; 4fd800b3a8 2011-02-23 kinaba: int L = 2; 4fd800b3a8 2011-02-23 kinaba: string _ = "Draw"; 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: CASE(4) 4fd800b3a8 2011-02-23 kinaba: int N = 1000000; 4fd800b3a8 2011-02-23 kinaba: int M = 804588; 4fd800b3a8 2011-02-23 kinaba: int K = 705444; 4fd800b3a8 2011-02-23 kinaba: int L = 292263; 4fd800b3a8 2011-02-23 kinaba: string _ = "Romeo"; 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: CASE(5) 4fd800b3a8 2011-02-23 kinaba: int N = 1000000; 4fd800b3a8 2011-02-23 kinaba: int M = 100000; 4fd800b3a8 2011-02-23 kinaba: int K = 500000; 4fd800b3a8 2011-02-23 kinaba: int L = 600000; 4fd800b3a8 2011-02-23 kinaba: string _ = "Strangelet"; 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: CASE(6) 4fd800b3a8 2011-02-23 kinaba: int N = 5; 4fd800b3a8 2011-02-23 kinaba: int M = 1; 4fd800b3a8 2011-02-23 kinaba: int K = 3; 4fd800b3a8 2011-02-23 kinaba: int L = 5; 4fd800b3a8 2011-02-23 kinaba: string _ = "Strangelet"; 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: /* 4fd800b3a8 2011-02-23 kinaba: CASE(7) 4fd800b3a8 2011-02-23 kinaba: int N = ; 4fd800b3a8 2011-02-23 kinaba: int M = ; 4fd800b3a8 2011-02-23 kinaba: int K = ; 4fd800b3a8 2011-02-23 kinaba: int L = ; 4fd800b3a8 2011-02-23 kinaba: string _ = ; 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: */ 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: // END CUT HERE