제출 #38077

#제출 시각아이디문제언어결과실행 시간메모리
38077wzy세 명의 친구들 (BOI14_friends)C++14
0 / 100
443 ms74284 KiB
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define int long long // LEMBRAR DE TROCAR CASO PROBLEMA DE MEMORIA #define pii pair<int,int> #define eps (int) 1e9 #define mp make_pair #define pb push_back int base = 137 , mod = 1000000007 , ivi = 58394161; int hs[3000000], pot[3000000] , inv[3000000]; int gethash(int l , int r){ if(l > r) return 0; int hashlow = hs[r]; if(l) hashlow -= hs[l-1]; hashlow += mod*mod; hashlow %= mod; hashlow *= inv[l]; hashlow %= mod; return hashlow; } int32_t main(){ /*ios::sync_with_stdio(false); cin.tie(0) , cout.tie(0); */ int n; scanf("%lld" , &n); string s; s.resize(n); scanf("%s" , &s[0]); if(n%2 == 0 || n == 1){ printf("NOT POSSIBLE\n"); return 0; } pot[0] = 1 , pot[1] = base, inv[0] = 1 , inv[1] = ivi; for(int i = 2 ; i < 3000000; i ++){ pot[i] = pot[i-1] * base; inv[i] = inv[i-1] * ivi; inv[i] %= mod; pot[i] %= mod; } hs[0] = (s[0] - 'A' + 1); for(int i = 1 ; i < n; i ++){ hs[i] = (s[i] - 'A' + 1)*pot[i]; hs[i] += hs[i-1]; hs[i] += mod*mod; hs[i] %= mod; } vector<int> can_r; for(int i = 0 ; i < n; i ++){ if(n/2 == i){ if(gethash(0 , i-1) == gethash(i + 1 , n-1)) can_r.pb(i); } if(i < n/2){ if((gethash(n/2 + 1 , n-1)%mod) == ((gethash(0 , i -1) + gethash(i + 1 , n/2)*pot[i])%mod)) can_r.pb(i) ; } if(i > n/2){ if((gethash(0 , n/2 - 1)%mod) == ( (gethash(n/2 , i-1) + gethash(i + 1 , n -1)*pot[i - n/2]))) can_r.pb(i) ; } } if(can_r.size() == 0) printf("NOT POSSIBLE\n"); if(can_r.size() > 1) printf("NOT UNIQUE\n"); if(can_r.size() == 1){ int conta = n - 1; conta /= 2; int tt = 0; while(conta){ if(tt++ == can_r[0]) continue; printf("%c" , s[tt-1]); conta--; } } }

컴파일 시 표준 에러 (stderr) 메시지

friends.cpp: In function 'int32_t main()':
friends.cpp:29:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld" , &n);
                    ^
friends.cpp:32:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s" , &s[0]);
                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...