Submission #53375058
Source Code Expand
Copy
#include<bits/stdc++.h>using namespace std;#define int long longconst int mod=998244353;#define ll long long#include<array>struct Shash{const ll base[2]={29,31};const ll hashmod[2]={(ll)1e9,998244353};#define fi first#define se secondarray<vector<ll>,2>hsh,pwMod;void init(string s){int n=s.size();s=' '+s;hsh[0].resize(n+1),hsh[1].resize(n+1);pwMod[0].resize(n+1),pwMod[1].resize(n+1);for(int i=0;i<2;i++){pwMod[i][0]=1;for(int j=1;j<=n;j++){pwMod[i][j]=pwMod[i][j-1]*base[i]%hashmod[i];hsh[i][j]=(hsh[i][j-1]*base[i]+s[j])%hashmod[i];
#include<bits/stdc++.h> using namespace std; #define int long long const int mod=998244353; #define ll long long #include<array> struct Shash{ const ll base[2]={29,31}; const ll hashmod[2]={(ll)1e9,998244353}; #define fi first #define se second array<vector<ll>,2>hsh,pwMod; void init(string s){ int n=s.size();s=' '+s; hsh[0].resize(n+1),hsh[1].resize(n+1); pwMod[0].resize(n+1),pwMod[1].resize(n+1); for(int i=0;i<2;i++){ pwMod[i][0]=1; for(int j=1;j<=n;j++){ pwMod[i][j]=pwMod[i][j-1]*base[i]%hashmod[i]; hsh[i][j]=(hsh[i][j-1]*base[i]+s[j])%hashmod[i]; } } } pair<ll,ll>get(int l,int r){ pair<ll,ll>ans; ans.fi=(hsh[0][r]-hsh[0][l-1]*pwMod[0][r-l+1])%hashmod[0]; ans.se=(hsh[1][r]-hsh[1][l-1]*pwMod[1][r-l+1])%hashmod[1]; ans.fi=(ans.fi+hashmod[0])%hashmod[0]; ans.se=(ans.se+hashmod[1])%hashmod[1]; return ans; } bool same(int la,int ra,int lb,int rb){ return get(la,ra)==get(lb,rb); } }; const int N=3e5+10; map<pair<int,int>,set<int>>mp[N]; void solve(){ int n;cin>>n; vector<string>a(n); for(auto&i:a)cin>>i; Shash h; for(int j=0;j<n;j++){ int len=a[j].size(); h.init(a[j]); for(int i=0;i<len;i++){ mp[i+1][h.get(1,i+1)].insert(j); } } int ans=0; for(int j=0;j<n-1;j++){ int pre=ans; int len=a[j].size(); h.init(a[j]); vector<int>st(len+2); for(int i=0;i<len;i++){ mp[i+1][h.get(1,i+1)].erase(j); st[i+1]=mp[i+1][h.get(1,i+1)].size(); } for(int i=0;i<=len;i++){ st[i]-=st[i+1]; } for(int i=1;i<=len;i++){ ans+=i*st[i]; // cout<<i<<" "<<st[i]<<endl; } // cout<<ans-pre<<endl; } cout<<ans; } signed main(){ ios::sync_with_stdio(0);cin.tie(0); solve(); }
Submission Info
Submission Time | |
---|---|
Task | E - Yet Another Sigma Problem |
User | chronicle12345 |
Language | C++ 20 (gcc 12.2) |
Score | 500 |
Code Size | 2081 Byte |
Status | AC |
Exec Time | 203 ms |
Memory | 70244 KB |
Compile Error
Main.cpp: In function ‘void solve()’: Main.cpp:53:13: warning: unused variable ‘pre’ [-Wunused-variable] 53 | int pre=ans; | ^~~
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 500 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00_sample_01.txt, 00_sample_02.txt |
All | 00_sample_01.txt, 00_sample_02.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt, 01_test_30.txt, 01_test_31.txt, 01_test_32.txt, 01_test_33.txt, 01_test_34.txt, 01_test_35.txt, 01_test_36.txt, 01_test_37.txt, 01_test_38.txt, 01_test_39.txt, 01_test_40.txt, 02_test_01.txt, 02_test_02.txt, 02_test_03.txt, 02_test_04.txt, 02_test_05.txt, 02_test_06.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_sample_01.txt | AC | 6 ms | 17624 KB |
00_sample_02.txt | AC | 7 ms | 17540 KB |
01_test_01.txt | AC | 93 ms | 32828 KB |
01_test_02.txt | AC | 93 ms | 32924 KB |
01_test_03.txt | AC | 92 ms | 32936 KB |
01_test_04.txt | AC | 97 ms | 32924 KB |
01_test_05.txt | AC | 98 ms | 32932 KB |
01_test_06.txt | AC | 100 ms | 32748 KB |
01_test_07.txt | AC | 101 ms | 32920 KB |
01_test_08.txt | AC | 77 ms | 32164 KB |
01_test_09.txt | AC | 76 ms | 32116 KB |
01_test_10.txt | AC | 76 ms | 32112 KB |
01_test_11.txt | AC | 200 ms | 53304 KB |
01_test_12.txt | AC | 197 ms | 53292 KB |
01_test_13.txt | AC | 203 ms | 53880 KB |
01_test_14.txt | AC | 203 ms | 54224 KB |
01_test_15.txt | AC | 201 ms | 53236 KB |
01_test_16.txt | AC | 54 ms | 31940 KB |
01_test_17.txt | AC | 111 ms | 40596 KB |
01_test_18.txt | AC | 96 ms | 35824 KB |
01_test_19.txt | AC | 44 ms | 53904 KB |
01_test_20.txt | AC | 110 ms | 40604 KB |
01_test_21.txt | AC | 143 ms | 36056 KB |
01_test_22.txt | AC | 146 ms | 36004 KB |
01_test_23.txt | AC | 145 ms | 36044 KB |
01_test_24.txt | AC | 119 ms | 33192 KB |
01_test_25.txt | AC | 119 ms | 33224 KB |
01_test_26.txt | AC | 120 ms | 33184 KB |
01_test_27.txt | AC | 147 ms | 35600 KB |
01_test_28.txt | AC | 147 ms | 35560 KB |
01_test_29.txt | AC | 167 ms | 38204 KB |
01_test_30.txt | AC | 166 ms | 38248 KB |
01_test_31.txt | AC | 84 ms | 32192 KB |
01_test_32.txt | AC | 71 ms | 32128 KB |
01_test_33.txt | AC | 52 ms | 32032 KB |
01_test_34.txt | AC | 124 ms | 65244 KB |
01_test_35.txt | AC | 44 ms | 54008 KB |
01_test_36.txt | AC | 59 ms | 70244 KB |
01_test_37.txt | AC | 52 ms | 62144 KB |
01_test_38.txt | AC | 7 ms | 17504 KB |
01_test_39.txt | AC | 7 ms | 17700 KB |
01_test_40.txt | AC | 87 ms | 33016 KB |
02_test_01.txt | AC | 89 ms | 42092 KB |
02_test_02.txt | AC | 202 ms | 43784 KB |
02_test_03.txt | AC | 201 ms | 43760 KB |
02_test_04.txt | AC | 201 ms | 42448 KB |
02_test_05.txt | AC | 203 ms | 42352 KB |
02_test_06.txt | AC | 203 ms | 42356 KB |