結果
問題 | No.1859 ><<< |
ユーザー | 👑 CleyL |
提出日時 | 2023-07-06 12:23:35 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 498 ms / 2,000 ms |
コード長 | 2,315 bytes |
コンパイル時間 | 1,052 ms |
コンパイル使用メモリ | 93,228 KB |
実行使用メモリ | 57,544 KB |
最終ジャッジ日時 | 2024-07-20 07:39:42 |
合計ジャッジ時間 | 19,894 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 21 ms
27,008 KB |
testcase_01 | AC | 21 ms
26,880 KB |
testcase_02 | AC | 21 ms
26,880 KB |
testcase_03 | AC | 20 ms
26,880 KB |
testcase_04 | AC | 498 ms
57,544 KB |
testcase_05 | AC | 463 ms
57,420 KB |
testcase_06 | AC | 450 ms
57,420 KB |
testcase_07 | AC | 439 ms
57,416 KB |
testcase_08 | AC | 444 ms
57,416 KB |
testcase_09 | AC | 443 ms
57,544 KB |
testcase_10 | AC | 67 ms
31,744 KB |
testcase_11 | AC | 240 ms
44,392 KB |
testcase_12 | AC | 213 ms
42,136 KB |
testcase_13 | AC | 122 ms
36,096 KB |
testcase_14 | AC | 273 ms
45,852 KB |
testcase_15 | AC | 391 ms
52,888 KB |
testcase_16 | AC | 436 ms
55,080 KB |
testcase_17 | AC | 355 ms
48,296 KB |
testcase_18 | AC | 454 ms
54,572 KB |
testcase_19 | AC | 309 ms
47,324 KB |
testcase_20 | AC | 365 ms
53,028 KB |
testcase_21 | AC | 432 ms
56,772 KB |
testcase_22 | AC | 420 ms
55,344 KB |
testcase_23 | AC | 358 ms
52,364 KB |
testcase_24 | AC | 405 ms
56,268 KB |
testcase_25 | AC | 405 ms
55,016 KB |
testcase_26 | AC | 380 ms
53,296 KB |
testcase_27 | AC | 412 ms
54,892 KB |
testcase_28 | AC | 393 ms
54,192 KB |
testcase_29 | AC | 396 ms
53,996 KB |
testcase_30 | AC | 371 ms
52,632 KB |
testcase_31 | AC | 367 ms
52,500 KB |
testcase_32 | AC | 430 ms
56,408 KB |
testcase_33 | AC | 374 ms
52,500 KB |
testcase_34 | AC | 394 ms
54,484 KB |
testcase_35 | AC | 452 ms
56,880 KB |
testcase_36 | AC | 469 ms
56,636 KB |
testcase_37 | AC | 388 ms
53,028 KB |
testcase_38 | AC | 453 ms
57,280 KB |
testcase_39 | AC | 452 ms
56,872 KB |
testcase_40 | AC | 414 ms
55,884 KB |
testcase_41 | AC | 431 ms
56,752 KB |
testcase_42 | AC | 357 ms
52,360 KB |
testcase_43 | AC | 435 ms
55,152 KB |
testcase_44 | AC | 403 ms
55,164 KB |
ソースコード
#include <iostream>#include <map>#include <vector>using namespace std;struct charSet{int base = 2;int encode(char c){return (c == '<' ? 0 : 1);}};struct RollingHash{charSet C;string t;const long long MOD1 = 1000000007;const long long MOD2 = 998244353;vector<int> stringIdx[1000001];map<pair<long long, long long>, int> hashIdx;int idxSize;RollingHash(string s, int n){idxSize = 0;long long val1 = 0;long long val2 = 0;long long baseMOD1 = 1;long long baseMOD2 = 1;for(int i = 0; n > i; i++){baseMOD1 = (baseMOD1*C.base)%MOD1;baseMOD2 = (baseMOD2*C.base)%MOD2;val1 = (val1*C.base + C.encode(s[i]))%MOD1;val2 = (val2*C.base + C.encode(s[i]))%MOD2;}for(int i = n; s.size() >= i; i++){if(!hashIdx[make_pair(val1, val2)]){hashIdx[make_pair(val1, val2)] = hashIdx.size();}stringIdx[hashIdx[make_pair(val1, val2)]].push_back(i-n);if(i!=s.size()){val1 = ((val1*C.base + C.encode(s[i]))%MOD1 - (baseMOD1 * C.encode(s[i-n]))%MOD1 + MOD1)%MOD1;val2 = ((val2*C.base + C.encode(s[i]))%MOD2 - (baseMOD2 * C.encode(s[i-n]))%MOD2 + MOD2)%MOD2;}}idxSize = hashIdx.size();}RollingHash(string s, string x): RollingHash(s, (int)x.size()){t = x;}pair<long long, long long> hash(string x){long long val1 = 0;long long val2 = 0;for(int i = 0; x.size() > i; i++){val1 = (val1*C.base + C.encode(x[i]))%MOD1;val2 = (val2*C.base + C.encode(x[i]))%MOD2;}return make_pair(val1, val2);}vector<int> search(){return search(t);}vector<int> search(string x){auto hashedString = hash(x);return stringIdx[hashIdx[hashedString]];}int distMax(){int distMx = 0;for(int i = 1; idxSize >= i; i++){distMx = max(distMx, stringIdx[i][stringIdx[i].size()-1]-stringIdx[i][0]);}return distMx;}};int main(){int n;cin>>n;vector<int> A(n);for(int i = 0; n > i; i++){cin>>A[i];}string c = "";for(int i = 0; 2*n > i;i++){c.push_back((A[(i)%n] < A[(i+1)%n] ? '<' : '>'));}string s;cin>>s;RollingHash B(c, n-1);auto z = B.search(s);if(z.size()){cout << z[0] << endl;}else{cout << -1 << endl;}}