Submission #653136

#TimeUsernameProblemLanguageResultExecution timeMemory
653136aryan12Three Friends (BOI14_friends)C++17
100 / 100
12 ms8096 KiB
#include <bits/stdc++.h> using namespace std; #define int long long mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); string s, t; int l, r, i, pos, n; bool f1, f2; bool check() { pos = 0; for(i = l; i <= r; i++) { if(pos != t.size() && t[pos] == s[i]) { pos++; } } return (pos == t.size()); } void Solve() { cin >> n; cin >> s; if(n % 2 == 0) { cout << "NOT POSSIBLE\n"; return; } t = s.substr(0, n / 2); l = n / 2; r = n - 1; f1 = check(); t = s.substr(n - n / 2, n / 2); l = 0; r = n / 2; f2 = check(); if(!f1 && !f2) { cout << "NOT POSSIBLE\n"; } else if(f1 && f2 && s.substr(0, n / 2) != s.substr(n - n / 2, n / 2)) { cout << "NOT UNIQUE\n"; } else if(f1) { cout << s.substr(0, n / 2) << "\n"; } else { cout << s.substr(n - n / 2, n / 2) << "\n"; } } int32_t main() { auto begin = std::chrono::high_resolution_clock::now(); ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; //cin >> t; while(t--) { Solve(); } auto end = std::chrono::high_resolution_clock::now(); auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin); cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; return 0; }

Compilation message (stderr)

friends.cpp: In function 'bool check()':
friends.cpp:14:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |         if(pos != t.size() && t[pos] == s[i]) {
      |            ~~~~^~~~~~~~~~~
friends.cpp:18:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     return (pos == t.size());
      |             ~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...