結果

問題 No.2454 Former < Latter
ユーザー hiro71687khiro71687k
提出日時 2023-09-01 23:15:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,311 bytes
コンパイル時間 4,480 ms
コンパイル使用メモリ 261,152 KB
実行使用メモリ 15,516 KB
最終ジャッジ日時 2023-09-01 23:15:21
合計ジャッジ時間 7,402 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 38 ms
11,896 KB
testcase_04 AC 47 ms
14,404 KB
testcase_05 AC 53 ms
13,996 KB
testcase_06 AC 45 ms
14,648 KB
testcase_07 AC 42 ms
13,220 KB
testcase_08 WA -
testcase_09 AC 35 ms
6,500 KB
testcase_10 AC 40 ms
6,696 KB
testcase_11 AC 38 ms
11,840 KB
testcase_12 AC 41 ms
12,068 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 56 ms
10,216 KB
testcase_16 AC 55 ms
9,940 KB
testcase_17 AC 534 ms
5,168 KB
testcase_18 WA -
testcase_19 AC 59 ms
15,516 KB
testcase_20 AC 58 ms
14,204 KB
testcase_21 WA -
testcase_22 AC 38 ms
5,488 KB
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll mod=998244353;
ld inf=10000999999999900;
int main(){
    ll t;
    cin >> t;
    vector<ll>ans;
    for (ll o = 0; o < t; o++)
    {
        ll n;
        cin >> n;
        string s;
        cin >> s;
        vector<ll>ten(n+100,1);
        for (ll i = 1; i < ten.size(); i++)
        {
            ten[i]=ten[i-1]*997;
            ten[i]%=mod;
        }
        vector<ll>hs(n);
        hs[0]=s[0]-'a';
        for (ll i = 1; i <n; i++)
        {
            hs[i]=hs[i-1]*997;
            hs[i]%=mod;
            hs[i]+=(s[i]-'a');
            hs[i]%=mod;
        }
        ll x=0;
        for (ll i = 1; i*2 < n; i++)
        {
            ll y=hs[i-1];
            ll z=hs[i*2-1];
            z+=mod-(hs[i-1]*ten[i])%mod;
            z%=mod;
            if (y==z)
            {
                x++;
            }
        }
        vector<int>sa=suffix_array(s);
        for (ll i = 0; i < n; i++)
        {
            if (sa[i]==0)
            {
                x+=n-i-1;
                break;
            }
        }
        ans.push_back(x);
    }
    for (ll i = 0; i < ans.size(); i++)
    {
        cout << ans[i] << endl;
    }
    
}
0