제출 #1124072

#제출 시각아이디문제언어결과실행 시간메모리
1124072JanPham세 명의 친구들 (BOI14_friends)C++20
0 / 100
1100 ms96440 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second #define TranLeThanhTam "TranLeThanhTam" #define all(v) v.begin(),v.end() #define reset(a,i) memset(a,i,sizeof(a)) #define FOR(i,a,b) for (int i = (a), _b = (b); i <= _b; ++i) #define FORD(i,a,b) for (int i = (a), _b = (b); i >= _b; --i) #define compact(v) sort(all(v)), v.erase(unique(all(v)), end(v)) #define sz(v) (int) v.size() #define MASK(i) (1 << (i)) typedef long long ll; typedef long double lb; typedef pair<ll,ll> pll; typedef pair<int,int> pii; const int Thanh_Tam = 2 * 1e6 + 17; const int inf = 1e9 + 17; const long long infll = 1e18 + 17; const int MOD = 1e9 + 7; const int Log = 18; const int dx[4] = {-1, 0, 0, 1}; const int dy[4] = {0, -1, 1, 0}; const int max_block_size = 270; const ll P = 311; const int maxA = 1e2 + 17; const int addi = 1e9; const char dir[4] = {'W', 'S', 'N', 'E'}; const int Mod[3] = {998244353, MOD, 759186269}; ll mul(ll a, ll b, ll mod); ll binpow(ll a, ll b, ll mod) { ll res = 1; while (b > 0) { if (b & 1) res = mul(res,a,mod); b >>= 1; a = mul(a,a,mod); } return res; } ll add(ll a, ll b, ll mod) { return (a + b) % mod; } ll sub(ll a, ll b, ll mod) { return (a - b + mod) % mod; } ll mul(ll a, ll b, ll mod) { return ((a % mod) * (b % mod)) % mod; } ll div(ll a, ll b, ll mod) { return mul(a, binpow(b, mod - 2, mod), mod); } mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); ll rand_range(ll l, ll r) { return uniform_int_distribution<ll>(l,r)(rng); } int n, ans = 0; string s, res; ll Pow[Thanh_Tam][3], pref[Thanh_Tam][3]; ll get(int l, int r, int type) { return div(sub(pref[r][type], pref[l - 1][type], Mod[type]), Pow[l - 1][type], Mod[type]); } void ThanhTam() { cin >> n >> s; s = ' ' + s; if ((n + 1) & 1) { cout << "NOT POSSIBLE"; return; } FOR(j,0,2) Pow[0][j] = 1; FOR(i,1,n) FOR(j,0,2) { Pow[i][j] = mul(Pow[i - 1][j], P, Mod[j]); pref[i][j] = add(pref[i - 1][j], mul(s[i] - 'A', Pow[i][j], Mod[j]), Mod[j]); } int Mid = (n + 1) >> 1; FOR(i,1,Mid) { bool possible = true; FOR(j,0,2) { ll value_left = add(get(1, i - 1, j), mul(get(i + 1, Mid, j), Pow[i - 1][j], Mod[j]), Mod[j]), value_right = get(Mid + 1, n, j); if (value_left != value_right) possible = false; } ans += possible; if (ans > 1) { cout << "NOT UNIQUE"; return; } if (possible) res = s.substr(Mid + 1, n - Mid); } FOR(i,Mid + 1, n) { bool possible = true; FOR(j,0,2) { ll value_left = get(1, Mid - 1, j), value_right = add(get(Mid, i - 1, j), mul(get(i + 1, n, j), Pow[i - Mid][j], Mod[j]), Mod[j]); if (value_left != value_right) possible = false; } ans += possible; if (ans > 1) { cout << "NOT UNIQUE"; return; } if (possible) res = s.substr(1, Mid - 1); } if (ans == 0) { cout << "NOT POSSIBLE"; return; } cout << res; return; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); if (fopen(TranLeThanhTam".inp","r")) { freopen(TranLeThanhTam".inp","r",stdin); freopen(TranLeThanhTam".out","w",stdout); } int t = 1; //cin >> t; while (t--) ThanhTam(); return 0; }

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

friends.cpp: In function 'int main()':
friends.cpp:140:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  140 |         freopen(TranLeThanhTam".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
friends.cpp:141:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  141 |         freopen(TranLeThanhTam".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...