結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 42 ms
13,216 KB
testcase_08 WA -
testcase_09 AC 35 ms
6,816 KB
testcase_10 AC 41 ms
6,608 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 56 ms
10,188 KB
testcase_16 AC 56 ms
9,928 KB
testcase_17 AC 520 ms
5,240 KB
testcase_18 WA -
testcase_19 AC 62 ms
15,536 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 38 ms
5,432 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=998244353999;
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