4a28d1c3b1 2015-02-18 kinaba: #include <iostream> 4a28d1c3b1 2015-02-18 kinaba: #include <sstream> 4a28d1c3b1 2015-02-18 kinaba: #include <iomanip> 4a28d1c3b1 2015-02-18 kinaba: #include <vector> 4a28d1c3b1 2015-02-18 kinaba: #include <string> 4a28d1c3b1 2015-02-18 kinaba: #include <map> 4a28d1c3b1 2015-02-18 kinaba: #include <set> 4a28d1c3b1 2015-02-18 kinaba: #include <algorithm> 4a28d1c3b1 2015-02-18 kinaba: #include <numeric> 4a28d1c3b1 2015-02-18 kinaba: #include <iterator> 4a28d1c3b1 2015-02-18 kinaba: #include <functional> 4a28d1c3b1 2015-02-18 kinaba: #include <complex> 4a28d1c3b1 2015-02-18 kinaba: #include <queue> 4a28d1c3b1 2015-02-18 kinaba: #include <stack> 4a28d1c3b1 2015-02-18 kinaba: #include <cmath> 4a28d1c3b1 2015-02-18 kinaba: #include <cassert> 4a28d1c3b1 2015-02-18 kinaba: #include <tuple> 4a28d1c3b1 2015-02-18 kinaba: using namespace std; 4a28d1c3b1 2015-02-18 kinaba: typedef long long LL; 4a28d1c3b1 2015-02-18 kinaba: typedef complex<double> CMP; 4a28d1c3b1 2015-02-18 kinaba: 4a28d1c3b1 2015-02-18 kinaba: class Decipherability { public: 4a28d1c3b1 2015-02-18 kinaba: string check(string s, int K) 4a28d1c3b1 2015-02-18 kinaba: { 4a28d1c3b1 2015-02-18 kinaba: return has_unique_ans(s, s.size()-K) ? "Certain" : "Uncertain"; 4a28d1c3b1 2015-02-18 kinaba: } 4a28d1c3b1 2015-02-18 kinaba: 4a28d1c3b1 2015-02-18 kinaba: bool has_unique_ans(const string& s, int R) 4a28d1c3b1 2015-02-18 kinaba: { 4a28d1c3b1 2015-02-18 kinaba: if(R == 0) 4a28d1c3b1 2015-02-18 kinaba: return true; 4a28d1c3b1 2015-02-18 kinaba: 4a28d1c3b1 2015-02-18 kinaba: for(int a=0; a<s.size(); ++a) 4a28d1c3b1 2015-02-18 kinaba: for(int b=a+1; b<s.size(); ++b) if(s[a] == s[b]) { 4a28d1c3b1 2015-02-18 kinaba: if(a + 1 + (s.size()-b-1) >= R) 4a28d1c3b1 2015-02-18 kinaba: return false; 4a28d1c3b1 2015-02-18 kinaba: } 4a28d1c3b1 2015-02-18 kinaba: return true; 4a28d1c3b1 2015-02-18 kinaba: } 4a28d1c3b1 2015-02-18 kinaba: }; 4a28d1c3b1 2015-02-18 kinaba: 4a28d1c3b1 2015-02-18 kinaba: // BEGIN CUT HERE 4a28d1c3b1 2015-02-18 kinaba: #include <ctime> 4a28d1c3b1 2015-02-18 kinaba: double start_time; string timer() 4a28d1c3b1 2015-02-18 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 4a28d1c3b1 2015-02-18 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 4a28d1c3b1 2015-02-18 kinaba: { os << "{ "; 4a28d1c3b1 2015-02-18 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 4a28d1c3b1 2015-02-18 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 4a28d1c3b1 2015-02-18 kinaba: void verify_case(const string& Expected, const string& Received) { 4a28d1c3b1 2015-02-18 kinaba: bool ok = (Expected == Received); 4a28d1c3b1 2015-02-18 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 4a28d1c3b1 2015-02-18 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 4a28d1c3b1 2015-02-18 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 4a28d1c3b1 2015-02-18 kinaba: #define END verify_case(_, Decipherability().check(s, K));} 4a28d1c3b1 2015-02-18 kinaba: int main(){ 4a28d1c3b1 2015-02-18 kinaba: 4a28d1c3b1 2015-02-18 kinaba: CASE(0) 4a28d1c3b1 2015-02-18 kinaba: string s = "snuke"; 4a28d1c3b1 2015-02-18 kinaba: int K = 2; 4a28d1c3b1 2015-02-18 kinaba: string _ = "Certain"; 4a28d1c3b1 2015-02-18 kinaba: END 4a28d1c3b1 2015-02-18 kinaba: CASE(1) 4a28d1c3b1 2015-02-18 kinaba: string s = "aba"; 4a28d1c3b1 2015-02-18 kinaba: int K = 1; 4a28d1c3b1 2015-02-18 kinaba: string _ = "Certain"; 4a28d1c3b1 2015-02-18 kinaba: END 4a28d1c3b1 2015-02-18 kinaba: CASE(2) 4a28d1c3b1 2015-02-18 kinaba: string s = "aba"; 4a28d1c3b1 2015-02-18 kinaba: int K = 2; 4a28d1c3b1 2015-02-18 kinaba: string _ = "Uncertain"; 4a28d1c3b1 2015-02-18 kinaba: END 4a28d1c3b1 2015-02-18 kinaba: CASE(3) 4a28d1c3b1 2015-02-18 kinaba: string s = "abcdabcd"; 4a28d1c3b1 2015-02-18 kinaba: int K = 3; 4a28d1c3b1 2015-02-18 kinaba: string _ = "Certain"; 4a28d1c3b1 2015-02-18 kinaba: END 4a28d1c3b1 2015-02-18 kinaba: CASE(4) 4a28d1c3b1 2015-02-18 kinaba: string s = "koukyoukoukokukikou"; 4a28d1c3b1 2015-02-18 kinaba: int K = 2; 4a28d1c3b1 2015-02-18 kinaba: string _ = "Uncertain"; 4a28d1c3b1 2015-02-18 kinaba: END 4a28d1c3b1 2015-02-18 kinaba: CASE(5) 4a28d1c3b1 2015-02-18 kinaba: string s = "wolfsothe"; 4a28d1c3b1 2015-02-18 kinaba: int K = 8; 4a28d1c3b1 2015-02-18 kinaba: string _ = "Uncertain"; 4a28d1c3b1 2015-02-18 kinaba: END 4a28d1c3b1 2015-02-18 kinaba: CASE(6) 4a28d1c3b1 2015-02-18 kinaba: string s = "aa"; 4a28d1c3b1 2015-02-18 kinaba: int K = 2; 4a28d1c3b1 2015-02-18 kinaba: string _ = "Certain"; 4a28d1c3b1 2015-02-18 kinaba: END 4a28d1c3b1 2015-02-18 kinaba: /* 4a28d1c3b1 2015-02-18 kinaba: CASE(7) 4a28d1c3b1 2015-02-18 kinaba: string s = ; 4a28d1c3b1 2015-02-18 kinaba: int K = ; 4a28d1c3b1 2015-02-18 kinaba: string _ = ; 4a28d1c3b1 2015-02-18 kinaba: END 4a28d1c3b1 2015-02-18 kinaba: CASE(8) 4a28d1c3b1 2015-02-18 kinaba: string s = ; 4a28d1c3b1 2015-02-18 kinaba: int K = ; 4a28d1c3b1 2015-02-18 kinaba: string _ = ; 4a28d1c3b1 2015-02-18 kinaba: END 4a28d1c3b1 2015-02-18 kinaba: */ 4a28d1c3b1 2015-02-18 kinaba: } 4a28d1c3b1 2015-02-18 kinaba: // END CUT HERE