QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#519139 | #6305. Chinese Checker | chengning0909 | WA | 4ms | 3816kb | C++14 | 4.5kb | 2024-08-14 16:34:56 | 2024-08-14 16:34:57 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 30, M = 210; // 17 * 13
int T, n, f[N][N], x[M], y[M], len[N];
bool vis[N][N], t[N][N];
queue<pii> que;
bool F(int x, int y) {
return 1 <= x && x <= 17 && f[x][1] <= y && y <= f[x][len[x]] && (y & 1) == (f[x][1] & 1);
}
void Record(int x, int y, int f) {
if (!F(x, y) || vis[x][y] || t[x][y] == f) return ;
vis[x][y] = 1, que.push({x, y});
}
void bfs(int sx, int sy) {
for (Record(sx, sy, 0); !que.empty(); ) {
auto [x, y] = que.front(); que.pop();
for (int k = 1; k <= 13; k++) {
int nx = x + k, ny = y + k;
if (F(nx, ny) && t[nx][ny]) {
bool flag = 1;
for (int tmp = k + 1; tmp <= 2 * k; tmp++) {
int tx = x + tmp, ty = y + tmp;
flag &= F(tx, ty) && !t[tx][ty];
}
if (flag) Record(nx + k, ny + k, 1);
break;
}
}
for (int k = 1; k <= 13; k++) {
int nx = x - k, ny = y - k;
if (F(nx, ny) && t[nx][ny]) {
bool flag = 1;
for (int tmp = k + 1; tmp <= 2 * k; tmp++) {
int tx = x - tmp, ty = y - tmp;
flag &= F(tx, ty) && !t[tx][ty];
}
if (flag) Record(nx - k, ny - k, 1);
break;
}
}
for (int k = 1; k <= 13; k++) {
int nx = x - k, ny = y + k;
if (F(nx, ny) && t[nx][ny]) {
bool flag = 1;
for (int tmp = k + 1; tmp <= 2 * k; tmp++) {
int tx = x - tmp, ty = y + tmp;
flag &= F(tx, ty) && !t[tx][ty];
}
if (flag) Record(nx - k, ny + k, 1);
break;
}
}
for (int k = 1; k <= 13; k++) {
int nx = x + k, ny = y - k;
if (F(nx, ny) && t[nx][ny]) {
bool flag = 1;
for (int tmp = k + 1; tmp <= 2 * k; tmp++) {
int tx = x + tmp, ty = y - tmp;
flag &= F(tx, ty) && !t[tx][ty];
}
if (flag) Record(nx + k, ny - k, 1);
break;
}
}
for (int k = 1; k <= 13; k++) {
int nx = x, ny = y + 2 * k;
if (F(nx, ny) && t[nx][ny]) {
bool flag = 1;
for (int tmp = k + 1; tmp <= 2 * k; tmp++) {
int tx = x, ty = y + 2 * tmp;
flag &= F(tx, ty) && !t[tx][ty];
}
if (flag) Record(nx, ny + k, 1);
break;
}
}
for (int k = 1; k <= 13; k++) {
int nx = x, ny = y - 2 * k;
if (F(nx, ny) && t[nx][ny]) {
bool flag = 1;
for (int tmp = k + 1; tmp <= 2 * k; tmp++) {
int tx = x, ty = y - 2 * tmp;
flag &= F(tx, ty) && !t[tx][ty];
}
if (flag) Record(nx, ny - k, 1);
break;
}
}
}
}
void Solve() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x[i] >> y[i], y[i] = f[x[i]][y[i]];
t[x[i]][y[i]] = 1;
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
bfs(x[i], y[i]);
for (int j = 1; j <= 17; j++) {
for (int k = 1; k <= len[j]; k++) {
ans += vis[j][f[j][k]];
vis[j][f[j][k]] = 0;
}
}
}
for (int j = 1; j <= 17; j++) {
for (int k = 1; k <= len[j]; k++) {
t[j][f[j][k]] = 0;
}
}
cout << ans - n << '\n';
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
f[1][1] = 13, f[2][1] = 12, f[3][1] = 11, f[4][1] = 10;
f[5][1] = 1, f[6][1] = 2, f[7][1] = 3, f[8][1] = 4;
f[9][1] = 5;
f[10][1] = 4, f[11][1] = 3, f[12][1] = 2, f[13][1] = 1;
f[14][1] = 10, f[15][1] = 11, f[16][1] = 12, f[17][1] = 13;
for (int i = 1; i <= 17; i++) {
for (int j = 2; j <= 13; j++) f[i][j] = f[i][j - 1] + 2;
}
len[1] = 1, len[2] = 2, len[3] = 3, len[4] = 4;
len[5] = 13, len[6] = 12, len[7] = 11, len[8] = 10;
len[9] = 9;
len[10] = 10, len[11] = 11, len[12] = 12, len[13] = 13;
len[14] = 4, len[15] = 3, len[16] = 2, len[17] = 1;
cin >> T;
while (T--) Solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
input:
5 1 1 1 2 1 1 2 1 2 9 4 9 6 10 1 1 2 1 2 2 3 1 3 2 3 3 4 1 4 2 4 3 4 4 10 1 1 2 1 2 2 5 7 3 2 3 3 4 1 4 2 4 3 4 4
output:
0 1 2 6 13
result:
ok 5 number(s): "0 1 2 6 13"
Test #2:
score: -100
Wrong Answer
time: 4ms
memory: 3816kb
input:
100 81 1 1 16 1 11 4 13 8 12 3 12 12 11 1 4 2 9 5 8 10 5 5 9 7 3 2 14 1 7 11 13 7 10 2 8 3 9 8 10 6 12 10 6 7 11 2 7 3 13 12 8 6 17 1 10 5 5 12 13 9 13 1 9 4 5 10 11 8 13 4 5 4 9 1 7 8 5 6 13 13 5 1 9 3 8 8 8 5 13 2 13 5 11 3 9 2 6 4 3 3 8 2 13 11 8 7 5 7 6 10 11 9 10 3 11 10 6 3 7 1 4 4 15 2 7 2 3 ...
output:
135 174 118 168 207 184 93 27 288 58 2 96 58 60 18 88 186 215 6 103 44 109 351 11 66 165 201 243 97 57 152 227 16 9 70 105 274 176 32 115 156 33 7 73 41 101 19 90 237 81 140 129 0 63 83 32 14 3 26 86 101 19 223 81 122 2 38 0 197 74 62 435 0 171 54 50 41 195 29 25 256 247 4 115 55 2 110 10 28 126 196...
result:
wrong answer 1st numbers differ - expected: '190', found: '135'