Submission #411889

# Submission time Handle Problem Language Result Execution time Memory
411889 2021-05-26T07:56:44 Z 장태환(#7564) Paint (COI20_paint) C++
8 / 100
3000 ms 5380 KB
#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;
int arr[200100];
int nex[200100][4];
int sta[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][2] = cu - M;
			if (i < N - 1)
				nex[cu][3] = cu + M;
			if (j)
				nex[cu][0] = cu - 1;
			if (j < M - 1)
				nex[cu][1] = 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--];
			if (arr[cu] ^ curc)
				continue;
			arr[cu] = c;
			sta[++siz] = nex[cu][0];
			sta[++siz] = nex[cu][1];
			sta[++siz] = nex[cu][2];
			sta[++siz] = nex[cu][3];
		}
	}
	for (i = 0; i < N; i++)
	{
		for (j = 0; j < M; j++)
		{
			int cu = i * M + j + 1;
			cout << arr[cu] << ' ';
		}
		cout << '\n';
	}
}

Compilation message

paint.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization("unroll-loops")
      |
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 4 ms 460 KB Output is correct
4 Correct 4 ms 460 KB Output is correct
5 Correct 159 ms 564 KB Output is correct
6 Correct 260 ms 596 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 1308 KB Output is correct
2 Correct 124 ms 2472 KB Output is correct
3 Execution timed out 3072 ms 4700 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Incorrect 1646 ms 5380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 89 ms 3824 KB Output is correct
2 Execution timed out 3063 ms 5168 KB Time limit exceeded
3 Halted 0 ms 0 KB -