結果
問題 | No.238 Mr. K's Another Gift |
ユーザー | 沙耶花 |
提出日時 | 2021-11-18 22:26:49 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 100 ms / 2,000 ms |
コード長 | 2,478 bytes |
コンパイル時間 | 3,858 ms |
コンパイル使用メモリ | 265,784 KB |
実行使用メモリ | 7,596 KB |
最終ジャッジ日時 | 2023-08-27 16:59:33 |
合計ジャッジ時間 | 8,005 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,384 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 6 ms
4,380 KB |
testcase_05 | AC | 76 ms
6,848 KB |
testcase_06 | AC | 52 ms
7,380 KB |
testcase_07 | AC | 83 ms
7,420 KB |
testcase_08 | AC | 84 ms
7,596 KB |
testcase_09 | AC | 60 ms
7,440 KB |
testcase_10 | AC | 1 ms
4,376 KB |
testcase_11 | AC | 1 ms
4,376 KB |
testcase_12 | AC | 1 ms
4,376 KB |
testcase_13 | AC | 4 ms
4,376 KB |
testcase_14 | AC | 60 ms
5,816 KB |
testcase_15 | AC | 100 ms
7,504 KB |
testcase_16 | AC | 99 ms
7,472 KB |
testcase_17 | AC | 97 ms
7,376 KB |
testcase_18 | AC | 98 ms
7,532 KB |
testcase_19 | AC | 97 ms
7,440 KB |
testcase_20 | AC | 1 ms
4,376 KB |
testcase_21 | AC | 1 ms
4,376 KB |
testcase_22 | AC | 1 ms
4,376 KB |
testcase_23 | AC | 2 ms
4,376 KB |
testcase_24 | AC | 5 ms
4,380 KB |
testcase_25 | AC | 6 ms
4,380 KB |
testcase_26 | AC | 53 ms
7,380 KB |
testcase_27 | AC | 68 ms
7,488 KB |
testcase_28 | AC | 7 ms
7,564 KB |
testcase_29 | AC | 66 ms
7,424 KB |
testcase_30 | AC | 1 ms
4,380 KB |
testcase_31 | AC | 2 ms
4,384 KB |
testcase_32 | AC | 2 ms
4,376 KB |
testcase_33 | AC | 11 ms
4,380 KB |
testcase_34 | AC | 87 ms
7,160 KB |
testcase_35 | AC | 97 ms
7,528 KB |
testcase_36 | AC | 97 ms
7,556 KB |
testcase_37 | AC | 97 ms
7,380 KB |
testcase_38 | AC | 97 ms
7,428 KB |
testcase_39 | AC | 96 ms
7,456 KB |
testcase_40 | AC | 1 ms
4,376 KB |
testcase_41 | AC | 1 ms
4,376 KB |
testcase_42 | AC | 1 ms
4,376 KB |
ソースコード
#include <stdio.h> #include <bits/stdc++.h> #include <atcoder/all> using namespace atcoder; using mint = modint1000000007; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000001 struct rolling_hash{ long long t_hash; static vector<long long> power; static const long long MOD = (1LL<<61)-1; static const long long b = 123456; int sz; rolling_hash(){ sz = 0; t_hash = 0; } rolling_hash(char c){ sz = 1; t_hash = b*c; } long long mul(__int128 x,__int128 y){ __int128 t = x*y; t = (t>>61) + (t&MOD); if(t>=MOD)t -= MOD; return t; } long long get_pow(int sz){ if(power.size()>sz)return power[sz]; while(power.size()<=sz){ if(power.size()==0)power.push_back(1); else power.push_back(mul(power.back(),b)); } return power.back(); } rolling_hash &operator+=(const rolling_hash &another){ (*this).t_hash = mul((*this).t_hash,get_pow(another.sz)); (*this).t_hash += another.t_hash; if((*this).t_hash>=MOD)(*this).t_hash -= MOD; (*this).sz += another.sz; return (*this); } rolling_hash operator+(const rolling_hash &another)const{ return (rolling_hash(*this)+=another); } rolling_hash &operator-=(const rolling_hash &another){ (*this).t_hash += MOD - mul(another.t_hash,get_pow((*this).sz-another.sz)); if((*this).t_hash>=MOD)(*this).t_hash -= MOD; (*this).sz -= another.sz; return (*this); } rolling_hash operator-(const rolling_hash &another)const{ return (rolling_hash(*this)-=another); } bool operator<(const rolling_hash &another)const{ if((*this).t_hash!=another.t_hash)return (*this).t_hash<another.t_hash; return (*this).sz<another.sz; } bool operator==(const rolling_hash &another)const{ return ((*this).t_hash==another.t_hash && (*this).sz==another.sz); } }; vector<long long> rolling_hash::power; int main(){ string s; cin>>s; int n; n = s.size(); vector<rolling_hash> R(n+1); rep(i,n){ R[i+1] = R[i] + rolling_hash(s[i]); } reverse(s.begin(),s.end()); vector<rolling_hash> R2(n+1); rep(i,n){ R2[i+1] = R2[i] + rolling_hash(s[i]); } reverse(s.begin(),s.end()); rep(i,n+1){ rep(j,26){ rolling_hash X = R[i]; X += rolling_hash('a'+j); X += R.back() - R[i]; rolling_hash Y = R2[n-i]; Y += rolling_hash('a'+j); Y += R2.back() - R2[n-i]; if(X==Y){ s.insert(s.begin()+i,'a'+j); cout<<s<<endl; return 0; } } } cout<<"NA"<<endl; return 0; }