Submission #1003950

# Submission time Handle Problem Language Result Execution time Memory
1003950 2024-06-20T20:46:26 Z vjudge1 Paint (COI20_paint) C++17
0 / 100
9 ms 2140 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef complex<double> cd;

const int MAXN = 5e5+10;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);

int n, m;
vector<vector<int>> grid;
int d[4]={0, 0, -1, 1};

void dfs(int x, int y, int c, int nova){
	grid[x][y]=nova;
	
	for(int i=0;i<4;i++){
		int dx=x+d[i], dy=y+d[3-i];
		if(dx<0 || dx>=n || dy<0 || dy>=m || grid[dx][dy]!=c) continue;
		dfs(dx, dy, c, nova);
	}
}

void solve(){
	cin >> n >> m;
	grid.resize(n, vector<int>(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, c; cin >> x >> y >> c;
		if(c==grid[x][y]) continue;
		dfs(x, y, grid[x][y], c);
	}
	
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			cout << grid[i][j] << " \n"[j==m-1];
}

int32_t main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	
	int tt=1;
	//~ cin >> tt;
	while(tt--) solve();
	return 0;
}



# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 916 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 2140 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 1880 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -