#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("00")
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
ll time() {return chrono::system_clock().now().time_since_epoch().count();}
mt19937 rnd(time());
const int inf = 1e9;
const ll inf64 = 1e18;
#define ft first
#define fin(x) ifstream cin("x.in");
#define fout(x) ofstream cout("x.out");
#define sd second
#define pb push_back
#define sz(x) (int)x.size()
int steps[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int grid[10001][10001];
bool bad[10001][10001];
int n, m;
void dfs(int x, int y, int who, int to)
{
if (bad[x][y] || x < 0 || x >= n || y >= m || y < 0)
return;
grid[x][y] = to;
bad[x][y] = true;
for (int i = 0; i < 4; i++)
{
int cx = x + steps[i][0];
int cy = y + steps[i][1];
if (cx < 0 || cy < 0 || cx >= n || cy >= m || bad[cx][cy])
continue;
if (grid[cx][cy] == who)
dfs(cx, cy, who, to);
}
}
void solve()
{
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> grid[i][j];
int q;
cin >> q;
while (q--)
{
int x, y;
int to;
cin >> x >> y >> to;
x--; y--;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
bad[i][j] = false;
dfs(x, y, grid[x][y], to);
}
for (int i = 0; i < n; i++, cout << '\n')
for (int j = 0; j < m; j++)
cout << grid[i][j] << " ";
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef _LOCAL_
system("color a");
#endif // _LOCAL_
int t = 1;
while (t--)
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
2 ms |
620 KB |
Output is correct |
3 |
Correct |
310 ms |
620 KB |
Output is correct |
4 |
Correct |
355 ms |
1132 KB |
Output is correct |
5 |
Correct |
1070 ms |
1644 KB |
Output is correct |
6 |
Correct |
1764 ms |
1644 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3057 ms |
620 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3078 ms |
2156 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3067 ms |
3436 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |