# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
211491 | Lawliet | Cubeword (CEOI19_cubeword) | C++17 | 487 ms | 26628 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
const int MAXS = 10;
const int MAXL = 65;
const int MAXN = 100010;
const int MOD = 998244353;
int n;
int qtd[MAXL][MAXL][MAXS];
lli ans[MAXL][MAXL][MAXL][MAXS];
lli result;
vector< int > p;
set< string > s;
int conv(char a)
{
if( 'a' <= a && a <= 'z' ) return a - 'a';
if( 'A' <= a && a <= 'Z' ) return 'z' - 'a' + 1 + a - 'A';
return 'z' - 'a' + 1 + 'Z' - 'A' + 1 + a - '0';
}
int qtdPermutations()
{
int ans = 24;
int curFat = 1;
int curNum = 1;
for(int i = 1 ; i < 4 ; i++)
{
if( p[i] != p[i - 1] )
{
ans /= curFat;
curNum = 0;
curFat = 1;
}
curFat *= ++curNum;
}
ans /= curFat;
return ans;
}
void backtracking(int i)
{
if( i == 4 )
{
for(int sz = 3 ; sz <= 10 ; sz++)
{
lli t = qtdPermutations();
t *= ans[ p[0] ][ p[1] ][ p[2] ][sz]; t %= MOD;
t *= ans[ p[0] ][ p[1] ][ p[3] ][sz]; t %= MOD;
t *= ans[ p[0] ][ p[2] ][ p[3] ][sz]; t %= MOD;
t *= ans[ p[1] ][ p[2] ][ p[3] ][sz]; t %= MOD;
result += t;
result %= MOD;
}
return;
}
int lim = 0;
if( !p.empty() ) lim = p.back();
for(int k = lim ; k <= conv( '9' ) ; k++)
{
p.push_back( k );
backtracking( i + 1 );
p.pop_back();
}
}
int main()
{
cin >> n;
for(int i = 1 ; i <= n ; i++)
{
string t;
cin >> t;
s.insert( t );
reverse( t.begin() , t.end() );
s.insert( t );
}
for(auto it = s.begin() ; it != s.end() ; it++)
{
string curT = *it;
int first = conv( curT[0] );
int last = conv( curT.back() );
int sz = curT.size();
qtd[first][last][sz]++;
}
for(int a = 0 ; a <= conv( '9' ) ; a++)
{
for(int b = a ; b <= conv( '9' ) ; b++)
{
for(int c = b ; c <= conv( '9' ) ; c++)
{
for(int sz = 3 ; sz <= 10 ; sz++)
{
for(int k = 0 ; k <= conv( '9' ) ; k++)
{
lli aux = 1;
aux *= qtd[a][k][sz];
aux *= qtd[b][k][sz];
aux *= qtd[c][k][sz];
ans[a][b][c][sz] += aux;
ans[a][b][c][sz] %= MOD;
}
}
}
}
}
backtracking( 0 );
printf("%lld\n",result);
}
컴파일 시 표준 에러 (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... |