답안 #411879

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
411879 2021-05-26T07:47:15 Z 장태환(#7564) Paint (COI20_paint) C++17
8 / 100
3000 ms 5912 KB
#include <vector>
#include <algorithm>
#include <iostream>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
int arr[200100];
int nex[200100][4];
int sta[200100];
int vis[200100];
int siz;
int main()
{
	int N, M,K;
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> N >> M;
	int i,j;
	for (i = 0; i < N; i++)
	{
		for (j = 0; j < M; j++)
		{
			int cu = i * M + j + 1;
			cin >> arr[cu];
			if (i)
				nex[cu][0] = cu - M;
			if (i<N-1)
				nex[cu][1] = cu + M;
			if(j)
				nex[cu][2] = cu-1;
			if (j<M-1)
				nex[cu][3] = cu +1;
		}
	}
	cin >> K;
	for (i = 0; i < K; i++)
	{
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		if (arr[a * M + b + 1] == c)
			continue;
		sta[0] = a * M + b + 1;
		int curc = arr[a * M + b + 1];
		siz = 0;
		while (siz>=0)
		{
			
			int cu = sta[siz--];
			vis[cu] = 0;
			if (arr[cu] ^ curc)
				continue;
			arr[cu] = c;
			
			if (vis[nex[cu][0]])
			{
				
			}
			else
			{
				sta[++siz] = nex[cu][0];
				vis[nex[cu][0]] = 1;
			}
			if (vis[nex[cu][1]])
			{

			}
			else
			{
				sta[++siz] = nex[cu][1];
				vis[nex[cu][1]] = 1;
			}
			if (vis[nex[cu][2]])
			{

			}
			else
			{
				sta[++siz] = nex[cu][2];
				vis[nex[cu][2]] = 1;
			}
			if (vis[nex[cu][3]])
			{

			}
			else
			{
				sta[++siz] = nex[cu][3];
				vis[nex[cu][3]] = 1;
			}
		}
	}
	for (i = 0; i < N; i++)
	{
		for (j = 0; j < M; j++)
		{
			int cu = i * M + j + 1;
			cout << arr[cu]<<' ';
		}
		cout << '\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 5 ms 588 KB Output is correct
4 Correct 6 ms 460 KB Output is correct
5 Correct 384 ms 564 KB Output is correct
6 Correct 543 ms 588 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 1504 KB Output is correct
2 Correct 156 ms 2932 KB Output is correct
3 Execution timed out 3069 ms 5408 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 2266 ms 5912 KB Output is correct
2 Correct 407 ms 5660 KB Output is correct
3 Correct 494 ms 5724 KB Output is correct
4 Execution timed out 3061 ms 5384 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 4108 KB Output is correct
2 Execution timed out 3068 ms 5116 KB Time limit exceeded
3 Halted 0 ms 0 KB -