Submission #57258

# Submission time Handle Problem Language Result Execution time Memory
57258 2018-07-14T12:13:28 Z MatheusLealV Land of the Rainbow Gold (APIO17_rainbow) C++17
0 / 100
3000 ms 36896 KB
#include "rainbow.h"
#include <bits/stdc++.h>
#define N 3050
#define f first
#define s second
using namespace std;
typedef pair<int, int> pii;

int n, m, ok[N][N], block[N][N];

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

int Ni, Mi, Nii, Mii;

int dxy(char c)
{
	if(c == 'N') return 1;

	if(c == 'S') return 0;

	if(c == 'W') return 3;

	return 2;
}

void dfs(int x, int y)
{
	ok[x][y] = 1;

	//cout<<"DFS "<<x<<" "<<y<<"\n";

	for(int i = 0; i < 4; i++)
	{
		int a = x + dx[i], b = y + dy[i];

		if(a < Ni or b < Mi or a > Nii or b > Mii or ok[a][b] == 1 or block[a][b]) continue;

		ok[a][b] = 1;

		dfs(a, b);
	}
}

void init(int R, int C, int sr, int sc, int M, char *S)
{
	int x = sr, y = sc;

	string s;

	for(int i = 0; i < M; i++) s.push_back(S[i]);

	for(int i = 0; i < s.size(); i++)
	{
		block[x][y] = 1;

		int id = dxy(s[i]);

		x = x + dx[id], y = y + dy[id];

		block[x][y] = 1;

		//cout<<"BLOCK "<<x<<" "<<y<<"\n";
	}
}

int colour(int ar, int ac, int br, int bc)
{
    int cnt = 0;

    memset(ok, 0, sizeof ok);

    Nii = br, Ni = ar, Mi = ac, Mii = bc;

    for(int x = ar; x <= br; x++)
    {
    	for(int y = ac; y <= bc; y++)
    	{
    		if(ok[x][y] or block[x][y]) continue;

    		cnt ++;

    		ok[x][y] = 1;

    		dfs(x, y);
    	}
    }

    return cnt;
}

Compilation message

rainbow.cpp: In function 'void init(int, int, int, int, int, char*)':
rainbow.cpp:52:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < s.size(); i++)
                 ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 3043 ms 36856 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 118 ms 36856 KB Output is correct
2 Incorrect 91 ms 36896 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 36896 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3043 ms 36856 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3043 ms 36856 KB Time limit exceeded
2 Halted 0 ms 0 KB -