Submission #367735

# Submission time Handle Problem Language Result Execution time Memory
367735 2021-02-18T07:42:13 Z arnold518 Paint (COI20_paint) C++14
0 / 100
25 ms 10024 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 10000;

const int dy[] = {-1, 1, 0, 0};
const int dx[] = {0, 0, -1, 1};

int N, M, Q;
vector<vector<int>> A;

int f(int y, int x)
{
	return x+(y-1)*M;
}

struct UF
{
	int par[MAXN+10];
	int Find(int x)
	{
		if(x==par[x]) return x;
		return par[x]=Find(par[x]);
	}
	void Union(int x, int y)
	{
		x=Find(x); y=Find(y);
		par[x]=y;
	}
}uf;

struct Data
{
	int y, x, c;
};
Data B[MAXN+10];

vector<vector<int>> vis;

int main()
{
	scanf("%d%d", &N, &M);
	A=vector<vector<int>>(N+10, vector<int>(M+10));
	vis=vector<vector<int>>(N+10, vector<int>(M+10));

	for(int i=1; i<=N; i++)
	{
		for(int j=1; j<=M; j++)
		{
			scanf("%d", &A[i][j]);
		}
	}

	for(int i=1; i<=N*M; i++) uf.par[i]=i;
	for(int i=1; i<=N; i++)
	{
		for(int j=1; j<=M; j++)
		{
			if(i!=N && A[i][j]==A[i+1][j])
			{
				uf.Union(f(i, j), f(i+1, j));
			}
			if(j!=M && A[i][j]==A[i][j+1])
			{
				uf.Union(f(i, j), f(i, j+1));
			}
		}
	}

	scanf("%d", &Q);
	for(int i=1; i<=Q; i++)
	{
		scanf("%d%d%d", &B[i].y, &B[i].x, &B[i].c);
	}

	for(int i=1; i<=Q; i++)
	{
		int nowy=B[i].y, nowx=B[i].x;
		if(A[nowy][nowx]==B[i].c) continue;
		queue<pii> QQ;
		QQ.push({nowy, nowx});
		int col=A[nowy][nowx];
		A[nowy][nowx]=B[i].c;
		while(!QQ.empty())
		{
			pii now=QQ.front(); QQ.pop();
			for(int i=0; i<4; i++)
			{
				int ny=now.first+dy[i], nx=now.second+dx[i];
				if(A[ny][nx]==col)
				{
					A[ny][nx]=B[i].c;
					QQ.push({ny, nx});
				}
			}
		}
	}

	for(int i=1; i<=N; i++)
	{
		for(int j=1; j<=M; j++)
		{
			printf("%d ", A[i][j]);
		}
		printf("\n");
	}
}

Compilation message

paint.cpp: In function 'int main()':
paint.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   46 |  scanf("%d%d", &N, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~
paint.cpp:54:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   54 |    scanf("%d", &A[i][j]);
      |    ~~~~~^~~~~~~~~~~~~~~~
paint.cpp:74:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   74 |  scanf("%d", &Q);
      |  ~~~~~^~~~~~~~~~
paint.cpp:77:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   77 |   scanf("%d%d%d", &B[i].y, &B[i].x, &B[i].c);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 15 ms 10024 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 25 ms 4864 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 18 ms 3692 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -