Submission #489177

#TimeUsernameProblemLanguageResultExecution timeMemory
489177uroskThree Friends (BOI14_friends)C++14
0 / 100
78 ms33640 KiB
// __builtin_popcount(x) broj bitova // __builtin_popcountll(x) // __builtin_clz(x) vodece nule // __builtin_clzll(x) // __builtin_ctz(x) nule na pocetku // __builtin_ctzll(x) // 2000000011 // 2000000033 #include "bits/stdc++.h" #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> #define ld double #define ll long long #define ull unsigned long long #define llinf 100000000000000000LL // 10^17 #define iinf 2000000000 // 2*10^9 #define pb push_back #define popb pop_back #define fi first #define sc second #define endl '\n' #define pii pair<int,int> #define pll pair<ll,ll> #define pld pair<ld,ld> #define sz(a) int(a.size()) #define all(a) a.begin(),a.end() #define rall(a) a.begin(),a.end(),greater<int>() #define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());} #define pi 3.14159265358979323846 #define here cerr<<"---------------------------\n" #define ceri(a,l,r) {for(ll i = l;i<=r;i++) cerr<<a[i]<< " ";cerr<<endl;} #define ceri2(a,l,r,n,m) {for(ll i = l;i<=r;i++){for(ll j = n;j<=m;j++) cerr<<a[i][j]<< " ";cerr<<endl;}} #define yes cout<<"YES"<<endl #define no cout<<"NO"<<endl using namespace std; using namespace __gnu_pbds; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll rnd(ll l,ll r){ return uniform_int_distribution<ll>(l,r)(rng); } void setIO(string inoutname) { freopen((inoutname+".in").c_str(),"r",stdin); freopen((inoutname+".out").c_str(),"w",stdout); } #define mod 1000000007 ll gcd(ll a, ll b) { if(b==0) return a; if(a==0) return b; if(a>=b) return gcd(a%b,b); return gcd(a,b%a); } ll lcm(ll a,ll b){ return (a/gcd(a,b))*b; } ll add(ll a,ll b){ a+=b; if(a<0) a+=mod; if(a>=mod) a%=mod; return a; } ll mul(ll a,ll b){return(a*b)%mod;} #define p 9973 #define maxn 2000005 ll n; string s; ll hsh[maxn]; ll po[maxn]; void hashuj(){ hsh[0] = s[0]-'a'+1; for(ll i = 1;i<n;i++){ hsh[i] = add(mul(hsh[i-1],p),s[i]-'a'+1); } } ll get(ll l,ll r){ if(l>r) return 0; if(l==0) return hsh[r]; return add(hsh[r],-mul(hsh[l-1],po[r-l+1])); } void tc(){ ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0); po[0] = 1; for(ll i = 1;i<=maxn-1;i++) po[i] = mul(po[i-1],p); cin >> n; cin >> s; hashuj(); ll m = (n-1)/2; if(n%2==0){ cout<<"NOT POSSIBLE"<<endl; return; } ll cnt = 0; ll poc = 0; for(ll i = 0;i<n;i++){ if(i<=m){ ll r = get(m+1,n-1); ll l = add(mul(po[m-i],get(0,i-1)),get(i+1,m)); if(l==r) cnt++,poc = m+1;if(l==r) cnt++,poc = m+1; }else{ ll l = get(0,m-1); ll r = add(mul(po[n-i],get(m,i-1)),get(i+1,n-1)); if(l==r) cnt++,poc = m+1;if(l==r) cnt++,poc = 0; } } if(cnt>1) cout<<"NOT UNIQUE"<<endl; if(cnt==0) cout<<"NOT POSSIBLE"<<endl; if(cnt==1) cout<<s.substr(poc,m)<<endl; } int main(){ ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0); //setIO("lol"); int t; t = 1; while(t--){ tc(); } return 0; }

Compilation message (stderr)

friends.cpp: In function 'void tc()':
friends.cpp:103:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  103 |             if(l==r) cnt++,poc = m+1;if(l==r) cnt++,poc = m+1;
      |             ^~
friends.cpp:103:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  103 |             if(l==r) cnt++,poc = m+1;if(l==r) cnt++,poc = m+1;
      |                                      ^~
friends.cpp:107:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  107 |             if(l==r) cnt++,poc = m+1;if(l==r) cnt++,poc = 0;
      |             ^~
friends.cpp:107:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  107 |             if(l==r) cnt++,poc = m+1;if(l==r) cnt++,poc = 0;
      |                                      ^~
friends.cpp: In function 'void setIO(std::string)':
friends.cpp:47:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |  freopen((inoutname+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
friends.cpp:48:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |      freopen((inoutname+".out").c_str(),"w",stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...