Submission #1232764

#TimeUsernameProblemLanguageResultExecution timeMemory
1232764Tenis0206Cubeword (CEOI19_cubeword)C++20
0 / 100
88 ms15540 KiB
#include <bits/stdc++.h> using namespace std; const int Mod = 998244353; int n; int cnt[15][155][155]; int tri[155][155][155]; int sqr[75][75][75][75]; vector<int> lst; int get_val(int val) { int st = 1; int dr = lst.size(); int poz = 0; while(st <= dr) { int mij = (st + dr) >> 1; if(lst[mij - 1] <= val) { poz = mij; st = mij + 1; } else { dr = mij - 1; } } return poz; } int main() { ios::sync_with_stdio(false); cin.tie(0); #ifdef home freopen("nr.in","r",stdin); freopen("nr.out","w",stdout); #endif // home cin>>n; set<string> l; for(int i=1;i<=n;i++) { string s; cin>>s; l.insert(s); reverse(s.begin(), s.end()); l.insert(s); lst.push_back(s.front()); lst.push_back(s.back()); } sort(lst.begin(), lst.end()); vector<int> ch; for(auto it=l.begin();it!=l.end();it++) { string s = *it; ++cnt[s.size()][get_val(s.front())][get_val(s.back())]; ch.push_back(get_val(s.front())); ch.push_back(get_val(s.back())); } sort(ch.begin(), ch.end()); vector<int> aux; for(auto it : ch) { if(aux.empty() || it != aux.back()) { aux.push_back(it); } } ch = aux; long long rez = 0; for(int len=3;len<=10;len++) { for(auto a : ch) { for(int h : ch) { for(auto f : ch) { tri[a][h][f] = 0; } } } for(auto a : ch) { for(auto h : ch) { for(auto f : ch) { for(auto e : ch) { tri[a][h][f] += 1LL * cnt[len][a][e] * cnt[len][h][e] % Mod * cnt[len][f][e] % Mod; tri[a][h][f] %= Mod; } } } } for(auto a : ch) { for(auto h : ch) { for(auto f : ch) { for(auto c : ch) { sqr[a][f][h][c] = 1LL * tri[a][h][f] * tri[a][h][c] % Mod; } } } } for(auto a : ch) { for(auto h : ch) { for(auto f : ch) { for(auto c : ch) { rez += 1LL * sqr[a][f][h][c] * sqr[c][h][f][a] % Mod; rez %= Mod; } } } } } cout<<rez<<'\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...