Submission #198640

#TimeUsernameProblemLanguageResultExecution timeMemory
198640arnold518Cubeword (CEOI19_cubeword)C++14
84 / 100
561 ms18772 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e5; const int MAXS = 52; const ll MOD = 998244353; int N; ll ans, cnt[70][70], D[70][70][70]; vector<string> S, T[15]; int convert(char s) { if('a'<=s && s<='z') return s-'a'; if('A'<=s && s<='Z') return s-'A'+26; if('0'<=s && s<='9') return s-'0'+52; } int main() { int i, j, p, q, k; ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>N; for(i=1; i<=N; i++) { string s, t; cin>>s; t=s; reverse(t.begin(), t.end()); S.push_back(s); S.push_back(t); } sort(S.begin(), S.end()); S.erase(unique(S.begin(), S.end()), S.end()); for(i=0; i<S.size(); i++) T[S[i].size()].push_back(S[i]); for(k=3; k<=10; k++) { vector<string> V=T[k]; if(V.empty()) continue; for(i=0; i<MAXS; i++) for(j=0; j<MAXS; j++) cnt[i][j]=0; for(i=0; i<V.size(); i++) cnt[convert(V[i][0])][convert(V[i][V[i].size()-1])]++; for(i=0; i<MAXS; i++) for(j=i; j<MAXS; j++) for(p=j; p<MAXS; p++) { D[i][j][p]=0; for(q=0; q<MAXS; q++) { D[i][j][p]+=cnt[i][q]*cnt[j][q]%MOD*cnt[p][q]%MOD; D[i][j][p]%=MOD; } } for(i=0; i<MAXS; i++) for(j=i+1; j<MAXS; j++) for(p=j+1; p<MAXS; p++) for(q=p+1; q<MAXS; q++) { ans+=24*D[i][j][p]%MOD*D[i][j][q]%MOD*D[i][p][q]%MOD*D[j][p][q]%MOD; ans%=MOD; } for(i=0; i<MAXS; i++) for(j=i, p=j+1; p<MAXS; p++) for(q=p+1; q<MAXS; q++) { ans+=12*D[i][j][p]%MOD*D[i][j][q]%MOD*D[i][p][q]%MOD*D[j][p][q]%MOD; ans%=MOD; } for(i=0; i<MAXS; i++) for(j=i+1; j<MAXS; j++) for(p=j, q=p+1; q<MAXS; q++) { ans+=12*D[i][j][p]%MOD*D[i][j][q]%MOD*D[i][p][q]%MOD*D[j][p][q]%MOD; ans%=MOD; } for(i=0; i<MAXS; i++) for(j=i+1; j<MAXS; j++) for(p=j+1; p<MAXS; p++) { q=p; ans+=12*D[i][j][p]%MOD*D[i][j][q]%MOD*D[i][p][q]%MOD*D[j][p][q]%MOD; ans%=MOD; } for(i=0; i<MAXS; i++) for(j=i, p=j+1; p<MAXS; p++) { q=p; ans+=6*D[i][j][p]%MOD*D[i][j][q]%MOD*D[i][p][q]%MOD*D[j][p][q]%MOD; ans%=MOD; } for(i=0; i<MAXS; i++) for(j=i+1; j<MAXS; j++) { p=q=j; ans+=4*D[i][j][p]%MOD*D[i][j][q]%MOD*D[i][p][q]%MOD*D[j][p][q]%MOD; ans%=MOD; } for(i=0; i<MAXS; i++) for(j=p=i, q=p+1; q<MAXS; q++) { ans+=4*D[i][j][p]%MOD*D[i][j][q]%MOD*D[i][p][q]%MOD*D[j][p][q]%MOD; ans%=MOD; } for(i=0; i<MAXS; i++) { j=p=q=i; ans+=D[i][j][p]%MOD*D[i][j][q]%MOD*D[i][p][q]%MOD*D[j][p][q]%MOD; ans%=MOD; } } cout<<ans; }

Compilation message (stderr)

cubeword.cpp: In function 'int main()':
cubeword.cpp:42:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0; i<S.size(); i++) T[S[i].size()].push_back(S[i]);
           ~^~~~~~~~~
cubeword.cpp:50:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(i=0; i<V.size(); i++) cnt[convert(V[i][0])][convert(V[i][V[i].size()-1])]++;
            ~^~~~~~~~~
cubeword.cpp: In function 'int convert(char)':
cubeword.cpp:21:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...