Submission #1026588

#TimeUsernameProblemLanguageResultExecution timeMemory
1026588hasan2006Three Friends (BOI14_friends)C++17
100 / 100
15 ms26880 KiB
#include <bits/stdc++.h> using namespace std; #define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define rall(s) s.rbegin(),s.rend() #define all(s) s.begin(),s.end() #define pb push_back #define se second #define fi first #define ll long long #define ld long double #define YES cout<<"YES\n" #define Yes cout<<"Yes\n" #define yes cout<<"yes\n" #define NO cout<<"NO\n" #define No cout<<"No\n" #define no cout<<"no\n" const int N = 2e6 + 9 , mod = 1e9 + 7; ll b[N] , c[N]; void solve() { ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ; cin>>n; string a; cin>>a; if(n % 2 == 0){ cout<<"NOT POSSIBLE"; return; } set<int>st; if(a.substr(1 , n / 2) == a.substr(1 + n / 2 , n / 2)){ st.insert(1); } if(a.substr(0 , n / 2) == a.substr(n / 2 , n / 2)){ st.insert(0); } if(a.substr(0 , n / 2) == a.substr(n / 2 + 1 , n / 2)){ st.insert(0); } r = n ; for(i = n / 2; i >= 0; i--) b[i] = ((a[i] == a[--r]) && (i == n / 2 || b[i + 1])); r = n / 2; for(i = 0; i <= n / 2; i++) c[i] = ((a[i] == a[++r]) && (i == 0 || c[i - 1])); for(i = 1; i < n / 2; i++) if(b[i + 1] && c[i - 1]){ st.insert(n / 2 + 1); break; } string d = a; a = a.substr(n / 2 , n / 2 + 1) + a.substr(0 , n / 2); r = n ; for(i = n / 2; i >= 0; i--) b[i] = ((a[i] == a[--r]) && (i == n / 2 || b[i + 1])); r = n / 2; for(i = 0; i <= n / 2; i++) c[i] = ((a[i] == a[++r]) && (i == 0 || c[i - 1])); for(i = 1; i < n / 2; i++) if(b[i + 1] && c[i - 1]){ st.insert(0); break; } set<string>ss; for(auto it : st) ss.insert(d.substr(it , n / 2)); if(ss.size() == 1) cout<<*ss.begin(); else if(!ss.size()) cout<<"NOT POSSIBLE"; else cout<<"NOT UNIQUE"; } int main(){ TL; /*#ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif*/ int t = 1; // cin>>t; while(t--) { solve(); } } // Author : حسن

Compilation message (stderr)

friends.cpp: In function 'void solve()':
friends.cpp:26:12: warning: unused variable 'q' [-Wunused-variable]
   26 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |            ^
friends.cpp:26:20: warning: unused variable 'j' [-Wunused-variable]
   26 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                    ^
friends.cpp:26:23: warning: unused variable 'l' [-Wunused-variable]
   26 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                       ^
friends.cpp:26:30: warning: unused variable 'x' [-Wunused-variable]
   26 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                              ^
friends.cpp:26:34: warning: unused variable 'y' [-Wunused-variable]
   26 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                  ^
friends.cpp:26:38: warning: unused variable 's' [-Wunused-variable]
   26 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                      ^
friends.cpp:26:46: warning: unused variable 'f' [-Wunused-variable]
   26 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                              ^
friends.cpp:26:50: warning: unused variable 'k' [-Wunused-variable]
   26 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                                  ^
friends.cpp:26:54: warning: unused variable 'm' [-Wunused-variable]
   26 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                                      ^
friends.cpp:26:58: warning: unused variable 'mn' [-Wunused-variable]
   26 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                                          ^~
friends.cpp:26:69: warning: unused variable 'mx' [-Wunused-variable]
   26 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                                                     ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...