Submission #252937

# Submission time Handle Problem Language Result Execution time Memory
252937 2020-07-26T13:57:38 Z Erkhemkhuu Land of the Rainbow Gold (APIO17_rainbow) C++17
11 / 100
3000 ms 1284 KB
#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
const int sN = 105;
char grid[sN][sN], temp[sN][sN];
queue <int> q;
void init(int R, int C, int sr, int sc, int M, char *S) {
    int n, m, curx, cury, sz, i, j;
    n = R; m = C; curx = sr; cury = sc;
    sz = M;
    for(i = 0; i < sN; i++)
        for(j = 0; j < sN; j++)
            grid[i][j] = '0';
  	grid[curx][cury] = 'X';
    for(i = 0; i < sz; i++) {
        if(S[i] == 'N') grid[--curx][cury] = 'X';
        if(S[i] == 'E') grid[curx][++cury] = 'X';
        if(S[i] == 'S') grid[++curx][cury] = 'X';
        if(S[i] == 'W') grid[curx][--cury] = 'X';
    }
    return;
}
int colour(int ar, int ac, int br, int bc) {
    int x0, y0, x1, y1;
    x0 = ar; y0 = ac;
    x1 = br; y1 = bc;
    int N = x1 - x0 + 1;
    int M = y1 - y0 + 1;
    int i, j;
    for(i = x0; i <= x1; i++)
        for(j = y0; j <= y1; j++)
            temp[i - x0 + 1][j - y0 + 1] = grid[i][j];
    int cnt = 0;
    for(i = 1; i <= N; i++) {
        for(j = 1; j <= M; j++) {
            if(temp[i][j] == '0') {
                cnt++;
                q.push(i * 1000 + j);
                while(!q.empty()) {
                    int v = q.front();
                    int curx = v / 1000;
                    int cury = v % 1000;
                    q.pop();
                    if(temp[curx][cury] != '0') continue;
                    temp[curx][cury] = 'M';
                    if(curx - 1 >= 1 && temp[curx - 1][cury] == '0') q.push((curx - 1) * 1000 + cury);
                    if(cury + 1 <= M && temp[curx][cury + 1] == '0') q.push(curx * 1000 + cury + 1);
                    if(curx + 1 <= N && temp[curx + 1][cury] == '0') q.push((curx + 1) * 1000 + cury);
                    if(cury - 1 >= 1 && temp[curx][cury - 1] == '0') q.push(curx * 1000 + cury - 1);
                }
            }
        }
    }
    return cnt;
}

Compilation message

rainbow.cpp: In function 'void init(int, int, int, int, int, char*)':
rainbow.cpp:11:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for(i = 0; i < sN; i++)
     ^~~
rainbow.cpp:14:4: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
    grid[curx][cury] = 'X';
    ^~~~
rainbow.cpp:8:9: warning: variable 'n' set but not used [-Wunused-but-set-variable]
     int n, m, curx, cury, sz, i, j;
         ^
rainbow.cpp:8:12: warning: variable 'm' set but not used [-Wunused-but-set-variable]
     int n, m, curx, cury, sz, i, j;
            ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 7 ms 308 KB Output is correct
3 Correct 21 ms 384 KB Output is correct
4 Correct 22 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 16 ms 384 KB Output is correct
12 Correct 16 ms 512 KB Output is correct
13 Correct 7 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Runtime error 2 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Runtime error 2 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 7 ms 308 KB Output is correct
3 Correct 21 ms 384 KB Output is correct
4 Correct 22 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 16 ms 384 KB Output is correct
12 Correct 16 ms 512 KB Output is correct
13 Correct 7 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Execution timed out 3042 ms 1284 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 7 ms 308 KB Output is correct
3 Correct 21 ms 384 KB Output is correct
4 Correct 22 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 16 ms 384 KB Output is correct
12 Correct 16 ms 512 KB Output is correct
13 Correct 7 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Execution timed out 3042 ms 1284 KB Time limit exceeded
19 Halted 0 ms 0 KB -