# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
349239 | Bill_00 | Cubeword (CEOI19_cubeword) | C++14 | 1032 ms | 39732 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define N 100001
#define MOD 998244353
#define ll long long
#define pb push_back
const int M=62;
using namespace std;
unordered_map<string,bool>um;
string a[N];
ll cnt[M][M][11],dp[M][M][M][11];
ll ans;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for(int i=1;i<=n;++i){
cin >> a[i];
int k=a[i].size();
char s=a[i][0],t=a[i][k-1];
int ss,tt;
if('a'<=s && s<='z') ss=s-'a';
if('A'<=s && s<='Z') ss=s-'A'+26;
if('0'<=s && s<='9') ss=s-'0'+52;
if('a'<=t && t<='z') tt=t-'a';
if('A'<=t && t<='Z') tt=t-'A'+26;
if('0'<=t && t<='9') tt=t-'0'+52;
if(um[a[i]]==0) cnt[ss][tt][k]++;
um[a[i]]=1;
reverse(a[i].begin(),a[i].end());
if(um[a[i]]==0){
um[a[i]]=1;
cnt[tt][ss][k]++;
}
}
for(int i=0;i<M;++i){
for(int j=0;j<M;++j){
for(int k=0;k<M;++k){
for(int p=0;p<M;++p){
for(int num=3;num<=10;++num){
ll res=1;
res*=cnt[i][p][num];
res*=cnt[j][p][num];
if(res>=MOD)res%=MOD;
res*=cnt[k][p][num];
dp[i][j][k][num]+=res;
if(dp[i][j][k][num]>=MOD) dp[i][j][k][num]%=MOD;
}
}
}
}
}
for(int i=0;i<M;++i){
for(int j=0;j<M;++j){
for(int k=0;k<M;++k){
for(int p=0;p<M;++p){
for(int num=3;num<=10;++num){
ll res=1;
res*=dp[i][j][k][num];
res*=dp[i][j][p][num];
if(res>=MOD)res%=MOD;
res*=dp[i][k][p][num];
if(res>=MOD)res%=MOD;
res*=dp[j][k][p][num];
ans+=res;
if(ans>=MOD)ans%=MOD;
}
}
}
}
}
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |