QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#524050 | #5112. Where Am I? | Andycipation | WA | 1076ms | 349564kb | C++20 | 2.4kb | 2024-08-19 09:21:06 | 2024-08-19 09:21:08 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int w, h;
cin >> w >> h;
auto InRange = [&](int x, int y) {
return 0 <= x && x < w && 0 <= y && y < h;
};
vector<vector<int>> a(w, vector<int>(h));
for (int row = 0; row < h; row++) {
int y = h - 1 - row;
for (int x = 0; x < w; x++) {
char c;
cin >> c;
a[x][y] = (c == 'X');
}
}
vector<vector<int>> tree(1, vector<int>(2, -1));
vector<int> sz(1, h * w);
auto MakeNode = [&] {
int id = tree.size();
tree.emplace_back(2, -1);
sz.push_back(0);
return id;
};
int shiftX = 0, shiftY = 0;
vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};
int dir = -1;
int cnt = 0;
int rem = 0;
vector<vector<int>> alive(w, vector<int>(h, true));
vector<vector<int>> node(w, vector<int>(h, 0));
int cnt_alive = h * w;
vector<pair<int, int>> last;
int total_steps = 0;
int steps = 0;
while (true) {
last.clear();
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
if (!alive[x][y]) {
continue;
}
last.emplace_back(x, y);
int xx = x + shiftX;
int yy = y + shiftY;
int d = (InRange(xx, yy) ? a[xx][yy] : 0);
if (tree[node[x][y]][d] == -1) {
tree[node[x][y]][d] = MakeNode();
}
node[x][y] = tree[node[x][y]][d];
sz[node[x][y]] += 1;
}
}
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
if (!alive[x][y]) {
continue;
}
if (sz[node[x][y]] == 1) {
alive[x][y] = false;
cnt_alive -= 1;
total_steps += steps;
}
}
}
if (cnt_alive == 0) {
break;
}
if (rem == 0) {
cnt += 1;
rem = (cnt + 1) / 2;
dir = (dir + 1) % 4;
}
rem -= 1;
shiftX += dx[dir];
shiftY += dy[dir];
steps += 1;
}
cout.precision(10);
cout << fixed;
cout << (double) total_steps / (h * w) << '\n';
cout << steps << '\n';
int k = last.size();
for (int i = 0; i < k; i++) {
auto [x, y] = last[i];
cout << "(" << x + 1 << "," << y + 1 << ")" << " \n"[i == k - 1];
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3848kb
input:
1 1 X
output:
0.0000000000 0 (1,1)
result:
ok correct!
Test #2:
score: 0
Accepted
time: 0ms
memory: 3716kb
input:
2 1 .X
output:
0.0000000000 0 (1,1) (2,1)
result:
ok correct!
Test #3:
score: 0
Accepted
time: 0ms
memory: 3872kb
input:
2 1 X.
output:
0.0000000000 0 (1,1) (2,1)
result:
ok correct!
Test #4:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
1 2 . X
output:
0.0000000000 0 (1,1) (1,2)
result:
ok correct!
Test #5:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
1 2 X .
output:
0.0000000000 0 (1,1) (1,2)
result:
ok correct!
Test #6:
score: 0
Accepted
time: 0ms
memory: 3728kb
input:
2 1 XX
output:
3.0000000000 3 (1,1) (2,1)
result:
ok correct!
Test #7:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
3 3 XXX X.X XXX
output:
3.1111111111 5 (3,1) (3,2)
result:
ok correct!
Test #8:
score: 0
Accepted
time: 413ms
memory: 349564kb
input:
100 100 ..X....X....X....X....X....X....X....X....X....X....X....X....X....X....X....X....X....X....X....X.. .................................................................................................... X............................................................................................
output:
4757.9471000000 9704 (50,1) (50,100)
result:
ok correct!
Test #9:
score: 0
Accepted
time: 1067ms
memory: 6144kb
input:
100 100 X................................................................................................... .................................................................................................... .............................................................................................
output:
19735.3199000000 39599 (100,1) (100,2)
result:
ok correct!
Test #10:
score: 0
Accepted
time: 1076ms
memory: 6176kb
input:
100 100 .................................................................................................... .................................................................................................... .............................................................................................
output:
19865.6699000000 39500 (100,1) (100,2)
result:
ok correct!
Test #11:
score: -100
Wrong Answer
time: 983ms
memory: 231924kb
input:
100 100 X................................................................................................... .X.................................................................................................. ..X..........................................................................................
output:
11855.6392000000 39302 (99,100) (100,99)
result:
wrong answer Read (99,100) but expected (100,99)