# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
321232 | phathnv | Cubeword (CEOI19_cubeword) | C++11 | 157 ms | 6756 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second
#define taskname "Cubeword"
using namespace std;
typedef long long ll;
typedef pair <int, int> ii;
const int L = 8;
const int M = 62;
const int MOD = 998244353;
int n, adj[L][M][M], cnt[L][M][M][M];
int ind(char ch){
if ('a' <= ch && ch <= 'z')
return ch - 'a';
if ('A' <= ch && ch <= 'Z')
return ch - 'A' + 26;
return ch - '0' + 52;
}
void readInput(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i = 1; i <= n; i++){
string s;
cin >> s;
int fr = ind(s.front());
int bk = ind(s.back());
int len = s.size();
if (fr != bk){
adj[len - 3][fr][bk]++;
adj[len - 3][bk][fr]++;
} else {
string tmp = s;
reverse(tmp.begin(), tmp.end());
adj[len - 3][fr][bk] += 2 - (tmp == s);
}
}
}
void add(int &x, const int &y){
x += y;
x -= (x >= MOD) * MOD;
}
int cntWays(int a, int b, int c, int d){
if (a == b && b == c && c == d)
return 1;
if ((a == b && b == c) || (b == c && c == d))
return 4;
if (a == b && c == d)
return 6;
if (a == b || b == c || c == d)
return 12;
return 24;
}
void solve(){
int res = 0;
for(int len = 0; len < L; len++)
for(int r = 0; r < M; r++)
for(int a = 0; a < M; a++)
for(int b = a; b < M; b++)
for(int c = b; c < M; c++){
add(cnt[len][a][b][c], (ll) adj[len][r][a] * adj[len][r][b] * adj[len][r][c] % MOD);
}
for(int len = 0; len < L; len++)
for(int a = 0; a < M; a++)
for(int b = a; b < M; b++)
for(int c = b; c < M; c++)
for(int d = c; d < M; d++){
int val = (ll) cnt[len][a][b][c] * cnt[len][a][b][d] % MOD * cnt[len][a][c][d] % MOD * cnt[len][b][c][d] % MOD;
add(res, (ll) val * cntWays(a, b, c, d) % MOD);
}
cout << res;
}
int main(){
if (fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
readInput();
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |