Submission #1003948

# Submission time Handle Problem Language Result Execution time Memory
1003948 2024-06-20T20:43:43 Z vjudge1 Paint (COI20_paint) C++17
8 / 100
3000 ms 15040 KB
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define ff first
#define ss second
const int maxn = 1e3+5;

vector<vector<int>> mtx, mark;
int dx[4] = {1,-1,0,0}, dy[4] = {0,0,1,-1};
int n,m;

bool valid(int x, int y){
	return (x>0 && y>0 && x<=n && y<=m && !mark[x][y]);
}

void dfs(int x, int y, int cor){
	// cout << x << " " << y << endl;
	mark[x][y]=true;

	for(int i=0; i<4; i++){
		int vx = x+dx[i];
		int vy = y+dy[i];
		if(valid(vx,vy) && mtx[x][y]==mtx[vx][vy]) dfs(vx,vy,cor);
	}

	mtx[x][y]=cor;
}

int main(){
	cin >> n >> m;
	mtx.resize(n+5);
	mark.resize(n+5);
	for(int i=1; i<=n; i++) mtx[i].resize(m+5), mark[i].resize(m+5);
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			int x; cin >> x;
			mtx[i][j]=x;
		}
	}

	int q; cin >> q;
	for(int i=1; i<=q; i++){
		int x,y,c; cin >> x >> y >> c;
		dfs(x,y,c);
		for(int j=1; j<=n; j++){
			for(int k=1; k<=m; k++) mark[j][k]=false;
		}
	}

	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			cout << mtx[i][j] << " ";
		}
		cout << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 21 ms 348 KB Output is correct
4 Correct 28 ms 348 KB Output is correct
5 Correct 238 ms 852 KB Output is correct
6 Correct 404 ms 1112 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1635 ms 852 KB Output is correct
2 Execution timed out 3041 ms 1764 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3055 ms 15040 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3073 ms 3632 KB Time limit exceeded
2 Halted 0 ms 0 KB -