# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
381362 |
2021-03-25T07:01:18 Z |
NONAME |
Paint (COI20_paint) |
C++17 |
|
3000 ms |
1260 KB |
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> inline bool chmin(T& a, const T b) {a = min(a, b); return (a == b);}
template <typename T> inline bool chmax(T& a, const T b) {a = max(a, b); return (a == b);}
const int steps[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int man = (int)(2e5 + 500);
int n, m;
int a[man];
bool was[man];
int to(int x, int y) {
return (x * m) + y;
}
void btool(int x, int y, int c) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
was[to(i, j)] = false;
}
}
queue <array <int, 2> > q;
q.push({x, y});
was[to(x, y)] = true;
while (!q.empty()) {
auto cur = q.front();
q.pop();
for (int i = 0; i < 4; ++i) {
int cx = cur[0] + steps[i][0];
int cy = cur[1] + steps[i][1];
if ((cx >= 0) && (cx < n) && (cy >= 0) && (cy < m) && !was[to(cx, cy)] && (a[to(cx, cy)] == a[to(x, y)])) {
was[to(cx, cy)] = true;
q.push({cx, cy});
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
a[to(i, j)] = (was[to(i, j)] ? c : a[to(i, j)]);
}
}
}
void solve() {
cin >> n >> m;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> a[to(i, j)];
}
}
int q;
cin >> q;
while (q--) {
int x, y, c;
cin >> x >> y >> c;
--x, --y;
btool(x, y, c);
}
for (int i = 0; i < n; ++i, cout << "\n") {
for (int j = 0; j < m; ++j) {
cout << a[to(i, j)] << " ";
}
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef _LOCAL
system("color a");
freopen("in.txt", "r", stdin);
#endif
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
69 ms |
492 KB |
Output is correct |
4 |
Correct |
94 ms |
620 KB |
Output is correct |
5 |
Correct |
569 ms |
620 KB |
Output is correct |
6 |
Correct |
762 ms |
620 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3087 ms |
1260 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3077 ms |
1260 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3076 ms |
1132 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |