QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#90099 | #5789. Watersheds | ChatGPT | 0 | 5ms | 3444kb | C++23 | 2.3kb | 2023-03-22 13:13:44 | 2023-03-22 13:13:46 |
Judging History
answer
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
const int MAXN = 105;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
int T, H, W, label;
int alt[MAXN][MAXN], basin[MAXN][MAXN];
char ans[MAXN][MAXN];
vector<pair<int, int>> sinks;
void dfs(int x, int y) {
if (basin[x][y] != -1) return;
int nx = -1, ny = -1, min_alt = alt[x][y];
for (int i = 0; i < 4; i++) {
int tx = x + dx[i], ty = y + dy[i];
if (tx < 0 || tx >= H || ty < 0 || ty >= W) continue;
if (alt[tx][ty] < min_alt) {
nx = tx;
ny = ty;
min_alt = alt[tx][ty];
}
}
if (nx == -1 && ny == -1) {
// this cell is a sink
basin[x][y] = label;
sinks.emplace_back(x, y);
return;
}
dfs(nx, ny);
basin[x][y] = basin[nx][ny];
}
void solve() {
cin >> H >> W;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> alt[i][j];
}
}
memset(basin, -1, sizeof(basin));
label = 0;
sinks.clear();
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (basin[i][j] == -1) {
dfs(i, j);
label++;
}
}
}
sort(sinks.begin(), sinks.end(), [](const pair<int, int>& a, const pair<int, int>& b) {
if (alt[a.first][a.second] != alt[b.first][b.second]) {
return alt[a.first][a.second] < alt[b.first][b.second];
} else if (a.first != b.first) {
return a.first < b.first;
} else {
return a.second < b.second;
}
});
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
ans[i][j] = 'a' + basin[i][j];
}
}
cout << "Case #" << ++T << ":\n";
for (const auto& p : sinks) {
ans[p.first][p.second] = 'a' + (int)(distance(sinks.begin(), lower_bound(sinks.begin(), sinks.end(), p)) % 26);
}
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cout << ans[i][j] << " ";
}
cout << "\n";
}
}
int main() {
int tests;
cin >> tests;
while (tests--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 3352kb
input:
100 4 4 9 6 9 9 1 3 6 2 9 5 9 4 8 7 9 5 3 3 6 1 0 7 3 4 7 3 0 1 10 0 1 2 3 4 5 6 7 8 7 2 7 4 3 4 5 5 4 3 3 2 3 4 5 5 4 3 3 8 1 0 2 8 6 1 0 4 4 4 1 5 7 8 2 7 3 8 7 8 1 7 8 1 0 8 6 6 7 6 7 8 7 6 6 5 6 7 6 5 5 4 5 6 5 4 4 3 4 5 6 5 5 4 5 6 7 6 6 5 6 7 8 7 4 4 6 6 9 7 5 2 1 6 4 3 7 1 9 7 7 4 3 3 9 3 9 5...
output:
Case #1: a a a d a a d b a a d d a a d d Case #2: a a a a a a d d b Case #3: a a a a a a a a a b Case #4: a a a a d d a a c a a a d d Case #5: a a a b b a b b b Case #6: a a c c a a c c a c c c c c c c Case #7: a a a a d d a a a a d d a a a a d a a c a a d d a a a a d d a a a a...
result:
wrong answer 2nd lines differ - expected: 'a a a b', found: 'a a a d '
Subtask #2:
score: 0
Wrong Answer
Test #2:
score: 0
Wrong Answer
time: 5ms
memory: 3444kb
input:
100 5 13 4510 4512 3024 3026 2430 2429 2425 2429 4081 4080 4064 382 378 4500 4515 3019 3009 3018 2434 2424 2438 4080 4077 4061 4081 362 4515 4519 3758 3744 3750 2435 2432 4645 4658 4036 4023 4501 367 4516 3111 3109 3748 87 92 1930 1910 1927 3912 4499 4497 4511 3112 3108 3107 3099 3111 3112 1921 1917...
output:
Case #1: a b b c c c c c c f f f f a b b a c c a c c l m f g a p b b s s s l l l g f f p p p s j s s j l l | | f p p p j s s l l l l | | j Case #2: a a c a c c e e h h h e h Case #3: a a a a e e e g g g g g k k h k h n n h Case #4: a b b b b b b b d d a e e e e a g f g a b...
result:
wrong answer 2nd lines differ - expected: 'a b b c c c c c c d d d d', found: 'a b b c c c c c c f f f f '