QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#290292 | #6305. Chinese Checker | zzuqy# | WA | 5ms | 3712kb | C++14 | 2.7kb | 2023-12-24 17:34:52 | 2023-12-24 17:34:52 |
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 122
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;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3620kb
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: 5ms
memory: 3712kb
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:
190 376 217 492 381 235 151 39 329 91 1 144 103 67 25 137 489 296 10 214 92 189 263 16 102 243 304 461 186 84 220 281 26 8 104 181 429 291 51 165 276 47 10 164 79 181 30 145 333 122 200 307 0 105 115 54 22 5 62 159 167 26 450 163 215 4 52 0 251 110 101 432 0 359 75 105 78 353 70 28 500 363 9 190 90 ...
result:
wrong answer 3rd numbers differ - expected: '211', found: '217'