QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#290298 | #6305. Chinese Checker | zzuqy# | WA | 0ms | 3976kb | C++14 | 2.7kb | 2023-12-24 18:11:28 | 2023-12-24 18:11:29 |
Judging History
answer
#include <bits/stdc++.h>
const int len[18] = {0, 1, 2, 3, 4, 13, 12, 11, 10, 9, 10, 11, 12, 13, 4, 3, 2, 1};
const int sum[18] = {0, 1, 3, 6, 10, 23, 35, 46, 56, 65, 75, 86, 98, 111, 115, 118, 120, 121};
const int di[6] = {-1, -1, 0, 0, 1, 1};
const int dj[6] = {-1, 1, -1, 1, -1, 1};
inline int getId(std::pair<int, int>u) {
if (u.second < 1 || u.second > len[u.first]) {
return -1;
}
return sum[u.first - 1] + u.second;
}
inline std::pair<int, int> getPair(int id) {
for (int i = 1; i < 18; i++) {
if (sum[i] >= id) {
return std::make_pair(i, id - sum[i - 1]);
}
}
return std::make_pair(17, id - sum[16]);
}
inline void move(std::pair<int, int> &u, int di, int dj) {
if (di == 0) {
u.second += dj;
} else if (di == -1) {
u.first--;
if (u.first <= 3) {
u.second--;
} else if (u.first == 4) {
u.second -= 5;
} else if (u.first >= 9 && u.first <= 12) {
u.second--;
} else if (u.first == 13) {
u.second += 4;
}
if (dj == 1) {
u.second++;
}
} else if (di == 1) {
u.first++;
if (u.first == 5) {
u.second += 4;
} else if (u.first >= 6 && u.first <= 9) {
u.second--;
} else if (u.first == 14) {
u.second -= 5;
} else if (u.first >= 15) {
u.second--;
}
if (dj == 1) {
u.second++;
}
}
if (getId(u) == -1) {
u.first = -1;
}
}
#define N 132
int n;
int have[N], vis[N];
inline int calc(int s) {
static int que[N], left, right;
left = right = 0;
que[0] = s;
std::memset(vis, 0, sizeof vis);
vis[s] = 1;
int ans = 0;
have[s] = 0;
while (left <= right) {
int u = que[left++];
for (int k = 0; k < 6; k++) {
// puts(">>>>>>>>>>>>>");
std::pair<int, int>_u = getPair(u);
int st = 0;
while (_u.first != -1) {
// printf("%d %d\n", _u.first, _u.second);
if (!have[getId(_u)]) {
st++;
move(_u, di[k], dj[k]);
continue;
}
if (!st) {
break;
}
int ff = 1;
while (st--) {
move(_u, di[k], dj[k]);
if (_u.first == -1 || have[getId(_u)]) {
ff = 0;
break;
}
}
if (!ff || vis[getId(_u)]) {
break;
}
ans++;
printf("%d %d -> %d %d\n", getPair(s).first, getPair(s).second, _u.first, _u.second);
vis[getId(_u)] = 1;
que[++right] = getId(_u);
break;
}
}
}
have[s] = 1;
return ans;
}
int main() {
int $;
scanf("%d", &$);
while ($--) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int x, y;
scanf("%d%d", &x, &y);
have[getId(std::make_pair(x, y))] = 1;
}
int ans = 0;
for (int i = 1; i <= 121; i++) {
if (have[i]) {
ans += calc(i);
}
}
printf("%d\n", ans);
std::memset(have, 0, sizeof have);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3976kb
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 1 -> 3 1 1 9 4 -> 9 8 9 6 -> 9 2 2 3 1 -> 5 5 3 1 -> 5 7 3 2 -> 5 6 3 2 -> 5 8 3 3 -> 5 7 3 3 -> 5 9 6 1 1 -> 3 1 1 1 -> 5 5 1 1 -> 5 9 2 1 -> 6 4 3 2 -> 5 6 3 2 -> 5 8 3 3 -> 3 1 3 3 -> 5 9 3 3 -> 5 5 4 2 -> 6 7 4 3 -> 6 6 5 7 -> 3 1 5 7 -> 5 5 13
result:
wrong answer 3rd numbers differ - expected: '2', found: '1'