Submission #379377

#TimeUsernameProblemLanguageResultExecution timeMemory
379377YJUCubeword (CEOI19_cubeword)C++14
100 / 100
340 ms17232 KiB
#include<bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector,Ofast") using namespace std; typedef long long ll; typedef pair<ll,ll> pll; typedef long double ld; const ll N=62; const ll MOD=998244353; const ll INF=(1LL<<58); const ld pi=acos(-1); #define REP(i,n) for(int i=0;i<n;++i) #define REP1(i,n) for(int i=1;i<=n;++i) #define pb push_back #define mp make_pair #define ff first #define ss second #define lwb lower_bound #define SZ(_a) (ll)_a.size() #define ALL(_a) _a.begin(),_a.end() ll ans,cnt[11][N][N],n,ccc[11][N][N][N],fac[5],is[N]; string s; vector<string> v; ll rev(char ch){ if('a'<=ch&&ch<='z')return (ll)ch-'a'; if('A'<=ch&&ch<='Z')return (ll)26+ch-'A'; return (ll)52+ch-'0'; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); fac[0]=1; REP1(i,4)fac[i]=fac[i-1]*i; cin>>n; REP(i,n){ cin>>s; v.pb(s); reverse(s.begin(),s.end()); v.pb(s); } sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); for(auto i:v){ ++cnt[SZ(i)][rev(i[0])][rev(i[SZ(i)-1])]; } for(int len=3;len<=10;++len){ REP(i,N)REP(j,i+1)REP(k,j+1){ REP(chose,N){ ccc[len][i][j][k]+=cnt[len][i][chose]*cnt[len][j][chose]*cnt[len][k][chose]%MOD; if(ccc[len][i][j][k]>=MOD)ccc[len][i][j][k]-=MOD; } } } for(int len=3;len<=10;++len){ REP(i,N)REP(j,i+1)REP(k,j+1)REP(l,k+1){ ++is[i];++is[j];++is[k];++is[l]; ll val=fac[4]; if(is[i])val/=fac[is[i]],is[i]=0; if(is[j])val/=fac[is[j]],is[j]=0; if(is[k])val/=fac[is[k]],is[k]=0; if(is[l])val/=fac[is[l]],is[l]=0; ll a=ccc[len][i][j][k],b=ccc[len][i][j][l],c=ccc[len][i][k][l],d=ccc[len][j][k][l]; ans+=(a*b%MOD*c%MOD*d%MOD)*val; ans%=MOD; } } cout<<ans<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...