이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
namespace
{
const int N = 11, K = 128, MOD = 998244353;
int cnt[N][K][K]{}, res[K][K][K]{};
const string charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
inline void addmod(int &x, int y)
{
x += y;
if (x > MOD)
{
x -= MOD;
}
}
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
vector<string> a(n);
for (int i = 0; i < n; i++)
{
string s;
cin >> s;
string ss = s;
reverse(ss.begin(), ss.end());
if (ss < s)
{
swap(s, ss);
}
a[i] = s;
}
sort(a.begin(), a.end());
a.resize(unique(a.begin(), a.end()) - a.begin());
n = a.size();
for (int i = 0; i < n; i++)
{
string s = a[i], ss = s;
reverse(ss.begin(), ss.end());
if (s == ss)
{
cnt[s.size()][s[0]][ss[0]]++;
}
else
{
cnt[s.size()][s[0]][ss[0]]++;
cnt[s.size()][ss[0]][s[0]]++;
}
}
int ans = 0;
for (int t = 3; t < N; t++)
{
for (int i : charset)
{
for (int j : charset)
{
for (int k : charset)
{
res[i][j][k] = 0;
}
}
}
for (int l : charset)
{
for (int i : charset)
{
if (cnt[t][i][l] == 0)
{
continue;
}
for (int j : charset)
{
if (cnt[t][j][l] == 0)
{
continue;
}
for (int k : charset)
{
if (cnt[t][k][l] == 0)
{
continue;
}
// (res[i][j][k] += 1ll * cnt[t][i][l] * cnt[t][j][l] * cnt[t][k][l]) %= MOD;
addmod(res[i][j][k], 1ll * cnt[t][i][l] * cnt[t][j][l] * cnt[t][k][l] % MOD);
}
}
}
}
for (int i : charset)
{
for (int j : charset)
{
for (int k : charset)
{
if (res[i][j][k] == 0)
{
continue;
}
for (int l : charset)
{
// (ans += res[i][j][k] * res[i][j][l] % MOD * res[i][k][l] % MOD * res[j][k][l]) %= MOD;
addmod(ans, res[i][j][k] * res[i][j][l] % MOD * res[i][k][l] % MOD * res[j][k][l] % MOD);
}
}
}
}
}
cout << ans << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
cubeword.cpp: In function 'int main()':
cubeword.cpp:47:31: warning: array subscript has type 'char' [-Wchar-subscripts]
47 | cnt[s.size()][s[0]][ss[0]]++;
| ^
cubeword.cpp:47:38: warning: array subscript has type 'char' [-Wchar-subscripts]
47 | cnt[s.size()][s[0]][ss[0]]++;
| ^
cubeword.cpp:51:31: warning: array subscript has type 'char' [-Wchar-subscripts]
51 | cnt[s.size()][s[0]][ss[0]]++;
| ^
cubeword.cpp:51:38: warning: array subscript has type 'char' [-Wchar-subscripts]
51 | cnt[s.size()][s[0]][ss[0]]++;
| ^
cubeword.cpp:52:32: warning: array subscript has type 'char' [-Wchar-subscripts]
52 | cnt[s.size()][ss[0]][s[0]]++;
| ^
cubeword.cpp:52:38: warning: array subscript has type 'char' [-Wchar-subscripts]
52 | cnt[s.size()][ss[0]][s[0]]++;
| ^
# | 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... |