提出 #15789169


ソースコード 拡げる

/*input
6
b
a
abc
c
d
ab
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=2e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=1000004099;
const ld PI=3.14159265358979323846;
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define MP make_pair
ll mult(ll a,ll b){
    ll res=0LL;
    while(b){
        if(b&1) res=(res+a)%MOD;
        a=(a+a)%MOD;
        b>>=1;
    }
    return res%MOD;
}
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
string arr[maxn];
unordered_map<int,int> mp;
int cnt[26];
int32_t main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n;
    cin>>n;
    ll ans=0;
    ll inv=(mypow(26,MOD-2));
    REP(i,n){
        cin>>arr[i];
        string s=arr[i];
        reverse(ALL(s));
        ll hsh=0;
        REP(j,sz(s)){
            hsh=(hsh*26LL+(s[j]-'a'))%MOD;
        }
        mp[hsh]++;
    }
    REP(i,n){
        string s=arr[i];
        string suff="";
        REP(j,sz(s)) cnt[s[j]-'a']++;
        ll hsh=0;
        for(int j=sz(s)-1;j>=0;j--){
            REP(k,26){
                if(cnt[k]){
                    hsh=(hsh*26LL+k)%MOD;
                    ans+=mp[hsh];
                    hsh-=k;
                    hsh+=MOD;
                    hsh%=MOD;
                    hsh*=inv;
                    hsh%=MOD;
                }
            }
            cnt[s[j]-'a']--;
            hsh=(hsh*26LL+(s[j]-'a'))%MOD;
        }
        REP(j,26) cnt[j]=0;
    }   
    cout<<ans-n;
}

提出情報

提出日時
問題 B - First Second
ユーザ zaneyu
言語 C++ (GCC 9.2.1)
得点 0
コード長 2588 Byte
結果 WA
実行時間 3338 ms
メモリ 997184 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 700
結果
AC × 2
AC × 10
WA × 10
TLE × 6
セット名 テストケース
Sample s1.txt, s2.txt
All 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, s1.txt, s2.txt
ケース名 結果 実行時間 メモリ
001.txt AC 12 ms 9740 KiB
002.txt AC 15 ms 9740 KiB
003.txt WA 9 ms 9864 KiB
004.txt WA 32 ms 12788 KiB
005.txt WA 256 ms 29652 KiB
006.txt TLE 3328 ms 613920 KiB
007.txt TLE 3324 ms 496280 KiB
008.txt WA 334 ms 29112 KiB
009.txt WA 183 ms 19368 KiB
010.txt TLE 3326 ms 521888 KiB
011.txt TLE 3338 ms 997184 KiB
012.txt WA 1503 ms 144880 KiB
013.txt WA 2777 ms 339916 KiB
014.txt TLE 3326 ms 506816 KiB
015.txt AC 675 ms 46972 KiB
016.txt AC 686 ms 24564 KiB
017.txt AC 169 ms 12176 KiB
018.txt AC 494 ms 12348 KiB
019.txt AC 631 ms 11552 KiB
020.txt WA 770 ms 67320 KiB
021.txt WA 876 ms 76320 KiB
022.txt WA 1485 ms 138696 KiB
023.txt AC 716 ms 77076 KiB
024.txt TLE 3332 ms 683180 KiB
s1.txt AC 14 ms 9796 KiB
s2.txt AC 11 ms 9736 KiB