QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#369699 | #6305. Chinese Checker | ucup-team1191# | WA | 81ms | 3608kb | C++20 | 4.7kb | 2024-03-28 16:44:01 | 2024-03-28 16:44:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define TIME (clock() * 1.0 / CLOCKS_PER_SEC)
struct Pos {
int x, y, z;
Pos() = default;
Pos(int x, int y, int z) : x(x), y(y), z(z) {}
};
vector<vector<Pos>> table;
const vector<Pos> dirs = {Pos(1, -1, 0), Pos(-1, 1, 0), Pos(1, 0, -1), Pos(-1, 0, 1), Pos(0, 1, -1), Pos(0, -1, 1)};
bool cell[20][20];
bool used[20][20];
bool was[20][20];
map<tuple<int, int, int>, pair<int, int>> mp;
bool decode(Pos& pos, pair<int, int>& into) {
auto it = mp.find(make_tuple(pos.x, pos.y, pos.z));
if (it == mp.end()) {
return false;
}
into = it->second;
return true;
}
int cnt;
void dfs(int x, int y) {
used[x][y] = true;
was[x][y] = true;
for (int d = 0; d < dirs.size(); d++) {
Pos pos = table[x][y];
pair<int, int> sym;
for (int i = 0; ; i++) {
pos.x += dirs[d].x;
pos.y += dirs[d].y;
pos.z += dirs[d].z;
if (!decode(pos, sym)) {
break;
}
if (!cell[sym.first][sym.second]) {
continue;
}
Pos into = Pos(2 * pos.x - table[x][y].x, 2 * pos.y - table[x][y].y, 2 * pos.z - table[x][y].z);
pair<int, int> nw;
if (!decode(into, nw)) {
break;
}
if (!used[nw.first][nw.second] && !cell[nw.first][nw.second]) {
dfs(nw.first, nw.second);
}
break;
}
}
used[x][y] = false;
}
void solve() {
int n;
cin >> n;
memset(cell, 0, sizeof(cell));
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
x--, y--;
cell[x][y] = true;
}
int ans = 0;
for (int x = 0; x < 20; x++) {
for (int y = 0; y < 20; y++) {
if (cell[x][y]) {
memcpy(used, cell, sizeof(used));
memset(was, 0, sizeof(was));
cell[x][y] = false;
dfs(x, y);
cell[x][y] = true;
cnt = 0;
for (int i = 0; i < 20; i++) {
for (int j = 0; j < 20; j++) {
if (was[i][j]) {
cnt++;
}
}
}
ans += cnt - 1;
}
}
}
cout << ans << "\n";
}
int main() {
#ifdef ONPC
freopen("input", "r", stdin);
#endif
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
table.resize(17);
for (int i = -4; i <= 4; i++) {
table[8].emplace_back(i, -i, 0);
}
for (int r = 7; r >= 4; r--) {
table[r] = table[r + 1];
for (auto& pos : table[r]) {
pos.y += 1;
pos.z -= 1;
}
table[r].emplace_back(table[r].back());
table[r].back().x += 1;
table[r].back().y -= 1;
}
for (int r = 9; r <= 12; r++) {
table[r] = table[r - 1];
for (auto& pos : table[r]) {
pos.x -= 1;
pos.z += 1;
}
table[r].emplace_back(table[r].back());
table[r].back().x += 1;
table[r].back().y -= 1;
}
table[3].emplace_back(table[4][4]);
table[3].back().x += 1;
table[3].back().z -= 1;
for (int r = 2; r >= 0; r--) {
table[r].emplace_back(table[r + 1].back());
table[r].back().x += 1;
table[r].back().z -= 1;
}
for (int r = 0; r <= 3; r++) {
for (int i = 0; i < r; i++) {
table[r].emplace_back(table[r].back());
table[r].back().x += 1;
table[r].back().y -= 1;
}
}
table[13].emplace_back(table[12][4]);
table[13].back().y -= 1;
table[13].back().z += 1;
for (int r = 14; r <= 16; r++) {
table[r].emplace_back(table[r - 1].back());
table[r].back().y -= 1;
table[r].back().z += 1;
}
for (int r = 13; r <= 16; r++) {
for (int i = 0; i < 16 - r; i++) {
table[r].emplace_back(table[r].back());
table[r].back().x += 1;
table[r].back().y -= 1;
}
}
for (int x = 0; x < (int)table.size(); x++) {
for (int y = 0; y < (int)table[x].size(); y++) {
mp[make_tuple(table[x][y].x, table[x][y].y, table[x][y].z)] = make_pair(x, y);
}
}
/*for (int i = 0; i < table.size(); i++) {
cout << table[i].size() << "\n";
}*/
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3600kb
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: 81ms
memory: 3608kb
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:
361 643 344 720 620 408 209 45 508 93 1 371 117 131 25 202 606 482 10 273 187 243 647 16 112 465 494 674 313 93 308 471 25 10 153 306 609 399 53 322 576 50 10 333 80 292 33 245 576 137 312 492 0 120 130 90 22 5 99 229 218 26 622 232 323 4 68 0 415 144 148 517 0 564 100 112 92 457 90 34 778 645 7 372...
result:
wrong answer 1st numbers differ - expected: '190', found: '361'