QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#637556 | #7034. Honeycomb | nekoyellow | WA | 1901ms | 7492kb | C++20 | 2.8kb | 2024-10-13 13:20:01 | 2024-10-13 13:20:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
void solve() {
int r, c;
scanf("%d %d", &r, &c); getchar();
vector<vector<char>> a(4*r+3, vector<char>(6*c+3));
for (int i = 0; i < 4*r+3; i++) {
for (int j = 0; j <= 6*c+3; j++) {
char c = getchar();
if (c == '\n') break;
a[i][j] = c;
}
}
// for (auto &row: a) {
// for (auto c: row) cout << c;
// cout << endl;
// }
auto id = [](int i, int j) {
return i*10000+j;
};
int s, t;
map<int, set<int>> g;
auto addedge = [&](int u, int v) {
g[u].emplace(v);
g[v].emplace(u);
};
for (int i = 2; i < 4*r+2; i += 4) {
for (int j = 4; j < 6*c+3; j += 12) {
// cout << i << ' ' << j << endl;
int x = i, y = j;
int u = id(i, j);
if (a[x][y] == 'S') s = u;
else if (a[x][y] == 'T') t = u;
else if (a[x][y] != ' ') continue;
if (a[x-2][y] == ' ') addedge(u, id(i-4, j));
if (a[x-1][y-3] == ' ') addedge(u, id(i-2, j-6));
if (a[x+1][y-3] == ' ') addedge(u, id(i+2, j-6));
if (a[x+2][y] == ' ') addedge(u, id(i+4, j));
if (a[x+1][y+3] == ' ') addedge(u, id(i+2, j+6));
if (a[x-1][y+3] == ' ') addedge(u, id(i-2, j+6));
}
}
for (int i = 4; i < 4*r+2; i += 4) {
for (int j = 10; j < 6*c+3; j += 12) {
// cout << i << ' ' << j << endl;
int x = i, y = j;
int u = id(i, j);
if (a[x][y] == 'S') s = u;
else if (a[x][y] == 'T') t = u;
else if (a[x][y] != ' ') continue;
if (a[x-2][y] == ' ') addedge(u, id(i-4, j));
if (a[x-1][y-3] == ' ') addedge(u, id(i-2, j-6));
if (a[x+1][y-3] == ' ') addedge(u, id(i+2, j-6));
if (a[x+2][y] == ' ') addedge(u, id(i+4, j));
if (a[x+1][y+3] == ' ') addedge(u, id(i+2, j+6));
if (a[x-1][y+3] == ' ') addedge(u, id(i-2, j+6));
}
}
// cout << s << ' ' << t << endl;
// for (auto &[u, adj]: g) {
// cout << u << ' ';
// for (auto v: adj) cout << ' ' << v;
// cout << endl;
// }
map<int, int> dist; dist[s] = 0;
queue<int> q; q.push(s);
set<int> vis; vis.emplace(s);
while (q.size()) {
int u = q.front(); q.pop();
for (auto v: g[u]) {
if (vis.count(v)) continue;
dist[v] = dist[u]+1;
if (v == t) break;
q.push(v);
vis.emplace(v);
}
}
printf("%d\n", (dist.count(t) ? dist[t]+1 : -1));
}
int main() {
int t;
scanf("%d", &t);
for (; t; t--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3848kb
input:
1 3 4 +---+ +---+ / \ / \ + +---+ +---+ \ \ / \ + + S +---+ T + / \ / / + +---+ + + \ \ / \ +---+ +---+ + / / + +---+ + + \ ...
output:
7
result:
ok single line: '7'
Test #2:
score: -100
Wrong Answer
time: 1901ms
memory: 7492kb
input:
400 67 89 +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ ...
output:
100 132 9 72 57 53 89 153 404 72 10 3 199 600 33 212 49 29 528 20 23 53 280 24 52 96 546 33 490 126 13 360 265 222 47 183 300 257 16 82 100 48 184 15 65 15 65 79 32 9 94 81 156 14 74 110 46 556 192 179 109 215 12 225 247 103 109 328 118 80 83 416 224 51 37 65 55 235 32 48 20 137 522 350 245 92 222 4...
result:
wrong answer 1st lines differ - expected: '91', found: '100'