제출 #439640

#제출 시각아이디문제언어결과실행 시간메모리
439640prvocisloCubeword (CEOI19_cubeword)C++17
100 / 100
499 ms17664 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; const int mod = 998244353, abc = 62; void upd(int &a, const int &b) { a += b; if (a >= mod) a -= mod; } int mul(const int &a, const int &b) { return (a * 1ll * b) % (ll)mod; } // 000 001 010 011 100 101 110 111 const int per[8] = { 24, 12, 12, 4, 12, 6, 4, 1 }; int conv(char c) { if ('a' <= c && c <= 'z') return c - 'a'; if ('A' <= c && c <= 'Z') return 26 + c - 'A'; if ('0' <= c && c <= '9') return 26 + 26 + c - '0'; } int cnt[abc][abc][abc], e[abc][abc], ans = 0; void solve(const set<string> &v) { memset(cnt, 0, sizeof(cnt)), memset(e, 0, sizeof(e)); for (const string &i : v) e[conv(i[0])][conv(i.back())]++; for (int c1 = 0; c1 < abc; c1++) for (int c2 = c1; c2 < abc; c2++) for (int c3 = c2; c3 < abc; c3++) for (int ja = 0; ja < abc; ja++) upd(cnt[c1][c2][c3], (e[ja][c1] * 1ll * e[ja][c2] * 1ll * e[ja][c3]) % mod); for (int c1 = 0; c1 < abc; c1++) for (int c2 = 0; c2 < abc; c2++) for (int c3 = 0; c3 < abc; c3++) { vector<int> c = {c1, c2, c3}; sort(c.begin(), c.end()); cnt[c1][c2][c3] = cnt[c[0]][c[1]][c[2]]; } for (int c1 = 0; c1 < abc; c1++) for (int c2 = c1; c2 < abc; c2++) for (int c3 = c2; c3 < abc; c3++) for (int c4 = c3; c4 < abc; c4++) { int pr = mul(mul(cnt[c1][c2][c3], cnt[c2][c3][c4]), mul(cnt[c3][c4][c1], cnt[c4][c1][c2])); int msk = (c1 == c2) | ((c2 == c3) << 1) | ((c3 == c4) << 2); upd(ans, mul(pr, per[msk])); } } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<set<string> > v(11); for (int i = 0; i < n; i++) { string s; cin >> s; v[s.size()].insert(s); reverse(s.begin(), s.end()); v[s.size()].insert(s); } for (int i = 3; i <= 10; i++) if (v[i].size()) solve(v[i]); cout << ans << "\n"; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

cubeword.cpp: In function 'int conv(char)':
cubeword.cpp:18:1: warning: control reaches end of non-void function [-Wreturn-type]
   18 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...