Submission #91722

#TimeUsernameProblemLanguageResultExecution timeMemory
91722MercenaryThree Friends (BOI14_friends)C++14
100 / 100
20 ms10096 KiB
#include<bits/stdc++.h> using namespace std; #define taskname "TEST" #define pb push_back typedef long double ld; typedef long long ll; const int maxn = 2e6 + 5; const int mod = 1e9 + 9; const int base = 33; int n; string s; string can(string need , int st , int en) { string res = ""; int it = 0;int ok = 1; for(int i = st ; i <= en && res.size() < n / 2 ; ++i) { if(need[it] == s[i]) res.pb(s[i]) , ++it; else { if(ok == 0)return "-1"; ok = 0; } } return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); if(fopen(taskname".INP","r")) freopen(taskname".INP", "r",stdin) , freopen(taskname".OUT", "w",stdout); cin >> n >> s; if(n % 2 == 0)return cout << "NOT POSSIBLE" , 0; s = " " + s; string res1 = can(s.substr(1,n/2),n/2+1,n); string res2 = can(s.substr(n/2+2,n/2),1,n/2+1); if(res1 == "-1" && res2 == "-1")cout << "NOT POSSIBLE"; else if(res1 == "-1")cout << res2; else if(res2 == "-1")cout << res1; else if(res1 == res2)cout << res1; else cout << "NOT UNIQUE"; }

Compilation message (stderr)

friends.cpp: In function 'std::__cxx11::string can(std::__cxx11::string, int, int)':
friends.cpp:19:44: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = st ; i <= en && res.size() < n / 2 ; ++i)
                                 ~~~~~~~~~~~^~~~~~~
friends.cpp: In function 'int main()':
friends.cpp:37:44: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(taskname".INP", "r",stdin) ,
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
         freopen(taskname".OUT", "w",stdout);
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
friends.cpp:37:44: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...