Submission #1135990

#TimeUsernameProblemLanguageResultExecution timeMemory
1135990AvianshCubeword (CEOI19_cubeword)C++20
21 / 100
1195 ms15728 KiB
#include <bits/stdc++.h> using namespace std; int mod = 998244353; bool palindrome(string s){ int n = s.size(); for(int i = 0;i<n;i++){ if(s[i]!=s[n-i-1]){ return 0; } } return 1; } signed main(){ ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; map<array<char,2>,long long> num[11]; unordered_set<char>poss; unordered_set<string>done; for(int i = 0;i<n;i++){ string s; cin >> s; if(done.find(s)!=done.end()){ continue; } num[s.size()][{s[0],s[s.size()-1]}]++; poss.insert(s[0]); poss.insert(s[s.size()-1]); done.insert(s); if(!palindrome(s)){ num[s.size()][{s[s.size()-1],s[0]}]++; reverse(s.begin(),s.end()); done.insert(s); } } vector<char>pos; for(char a : poss){ pos.push_back(a); } long long ans = 0; for(int len = 0;len<11;len++){ map<array<char,3>,long long>val; for(int i = 0;i<pos.size();i++){ for(int j = 0;j<pos.size();j++){ for(int k = 0;k<pos.size();k++){ for(int cor = 0;cor<pos.size();cor++){ array<char,3>curr = {pos[i],pos[j],pos[k]}; val[curr]+=(((1LL*num[len][{pos[cor],curr[0]}]*num[len][{pos[cor],curr[1]}])%mod)*num[len][{pos[cor],curr[2]}])%mod; val[curr]%=mod; } } } } for(pair<array<char,3>,long long>p1:val){ if(p1.second==0){ continue; } for(pair<array<char,3>,long long>p2:val){ if(p2.second==0){ continue; } long long mid = ((((((((((num[len][{p1.first[0],p2.first[0]}]*num[len][{p1.first[0],p2.first[1]}])%mod)*num[len][{p1.first[1],p2.first[1]}])%mod)*num[len][{p1.first[1],p2.first[2]}])%mod)*num[len][{p1.first[2],p2.first[2]}])%mod)*num[len][{p1.first[2],p2.first[0]}])%mod); ans+=(((((1LL*p1.second)%mod)*p2.second)%mod)*(mid))%mod; ans%=mod; } } } cout << ans; 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...