# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
160780 | luciocf | PIN (CEOI10_pin) | C++14 | 1076 ms | 8720 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e4+10;
long long ans;
int qtd[40][40][40][40];
char s[maxn][4];
void add_0(int ind, int x_0, int x_1, int x_2, int x_3)
{
for (int a = 0; a < 40; a++)
for (int b = 0; b < 40; b++)
for (int c = 0; c < 40; c++)
for (int d = 0; d < 40; d++)
ans += 1ll*qtd[a][b][c][d];
}
void add_1(int ind, int x_0, int x_1, int x_2, int x_3)
{
for (int mask = 0; mask < (1<<4); mask++)
{
if (__builtin_popcount(mask) != 1) continue;
int pos;
for (int i = 0; i < 4; i++)
if (mask&(1<<i))
pos = i;
int x_0 = ( (s[ind][0] >= '0' && s[ind][0] <= '9') ? (26 + (int)(s[ind][0]-'0')) : (int)(s[ind][0]-'a'));
int x_1 = ( (s[ind][1] >= '0' && s[ind][1] <= '9') ? (26 + (int)(s[ind][1]-'0')) : (int)(s[ind][1]-'a'));
int x_2 = ( (s[ind][2] >= '0' && s[ind][2] <= '9') ? (26 + (int)(s[ind][2]-'0')) : (int)(s[ind][2]-'a'));
int x_3 = ( (s[ind][3] >= '0' && s[ind][3] <= '9') ? (26 + (int)(s[ind][3]-'0')) : (int)(s[ind][3]-'a'));
for (int a = 0; a < 40; a++)
{
for (int b = 0; b < 40; b++)
{
for (int c = 0; c < 40; c++)
{
if (pos == 0)
ans += 1ll*qtd[x_0][a][b][c];
else if (pos == 1)
ans += 1ll*qtd[a][x_1][b][c];
else if (pos == 2)
ans += 1ll*qtd[a][b][x_2][c];
else
ans += 1ll*qtd[a][b][c][x_3];
}
}
}
}
}
void add_2(int ind, int x_0, int x_1, int x_2, int x_3)
{
for (int mask = 0; mask < (1<<4); mask++)
{
if (__builtin_popcount(mask) != 2) continue;
int pos_0 = -1, pos_1;
for (int i = 0; i < 4; i++)
{
if (mask&(1<<i) && pos_0 == -1)
pos_0 = i;
else if (mask&(1<<i))
pos_1 = i;
}
for (int a = 0; a < 40; a++)
{
for (int b = 0; b < 40; b++)
{
if (pos_0 == 0 && pos_1 == 1)
ans += 1ll*qtd[x_0][x_1][a][b];
else if (pos_0 == 0 && pos_1 == 2)
ans += 1ll*qtd[x_0][a][x_2][b];
else if (pos_0 == 0 && pos_1 == 3)
ans += 1ll*qtd[x_0][a][b][x_3];
else if (pos_0 == 1 && pos_1 == 2)
ans += 1ll*qtd[a][x_1][x_2][b];
else if (pos_0 == 1 && pos_1 == 3)
ans += 1ll*qtd[a][x_1][b][x_3];
else if (pos_0 == 2 && pos_1 == 3)
ans += 1ll*qtd[a][b][x_2][x_3];
}
}
}
}
void add_3(int ind, int x_0, int x_1, int x_2, int x_3)
{
for (int mask = 0; mask < (1<<4); mask++)
{
if (__builtin_popcount(mask) != 3) continue;
int pos_0 = -1, pos_1 = -1, pos_2;
for (int i = 0; i < 4; i++)
{
if (mask&(1<<i) && pos_0 == -1)
pos_0 = i;
else if (mask&(1<<i) && pos_1 == -1)
pos_1 = i;
else if (mask&(1<<i))
pos_2 = i;
}
for (int a = 0; a < 40; a++)
{
if (pos_0 == 0 && pos_1 == 1 && pos_2 == 2)
ans += 1ll*qtd[x_0][x_1][x_2][a];
else if (pos_0 == 0 && pos_1 == 1 && pos_2 == 3)
ans += 1ll*qtd[x_0][x_1][a][x_3];
else if (pos_0 == 0 && pos_1 == 2 && pos_2 == 3)
ans += 1ll*qtd[x_0][a][x_2][x_3];
else if (pos_0 == 1 && pos_1 == 2 && pos_2 == 3)
ans += 1ll*qtd[a][x_1][x_2][x_3];
}
}
}
int main(void)
{
int n, d;
scanf("%d %d", &n, &d);
for (int i = 0; i < n; i++)
{
int x_0, x_1, x_2, x_3;
for (int j = 0; j < 4; j++)
{
scanf(" %c", &s[i][j]);
int x = (int)(s[i][j]-'a');
if (s[i][j] >= '0' && s[i][j] <= '9')
x = 26+(int)(s[i][j]-'0');
if (j == 0) x_0 = x;
else if (j == 1) x_1 = x;
else if (j == 2) x_2 = x;
else x_3 = x;
}
qtd[x_0][x_1][x_2][x_3]++;
}
for (int i = 0; i < n; i++)
{
int x_0, x_1, x_2, x_3;
for (int j = 0; j < 4; j++)
{
int x = (int)(s[i][j]-'a');
if (s[i][j] >= '0' && s[i][j] <= '9')
x = 26+(int)(s[i][j]-'0');
if (j == 0) x_0 = x;
else if (j == 1) x_1 = x;
else if (j == 2) x_2 = x;
else x_3 = x;
}
qtd[x_0][x_1][x_2][x_3]--;
if (d == 1) add_3(i, x_0, x_1, x_2, x_3);
else if (d == 2) add_2(i, x_0, x_1, x_2, x_3);
else if (d == 3) add_1(i, x_0, x_1, x_2, x_3);
else add_0(i, x_0, x_1, x_2, x_3);
}
printf("%lld\n", ans);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |