Submission #545808

# Submission time Handle Problem Language Result Execution time Memory
545808 2022-04-05T13:22:41 Z Monarchuwu Land of the Rainbow Gold (APIO17_rainbow) C++17
Compilation error
0 ms 0 KB
#include<iostream>
#include<algorithm>

#ifdef ONLINE_JUDGE
#include "rainbow.h"
#endif

using namespace std;
typedef long long ll;

typedef pair<int, int> pii;
#define ff first
#define ss second

const int N = 2e5 + 8;
const int dr[4] = { 0, 0, 1, -1 };
const int dc[4] = { 1, -1, 0, 0 };
int r, c, m, q, sr, sc;
int num[256];
string s;

namespace subtask1 {
    bool vis_init[52][52], vis[52][52];
    void init() {
        vis_init[sr][sc] = true;
        for (char c : s) {
            sr += dr[num[c]];
            sc += dc[num[c]];
            vis_init[sr][sc] = true;
        }
    }
    void dfs(int i, int j) {
        vis[i][j] = true;
        for (int k = 0, i2, j2; k < 4; ++k) {
            i2 = i + dr[k], j2 = j + dc[k];
            if (!vis[i2][j2]) dfs(i2, j2);
        }
    }
    int solve(int ar, int ac, int br, int bc) {
        int m = br - ar + 1, n = bc - ac + 1;
        for (int i = 1; i <= m; ++i) vis[i][0] = vis[i][n + 1] = true;
        for (int j = 1; j <= n; ++j) vis[0][j] = vis[m + 1][j] = true;
        for (int i = 1; i <= m; ++i)
            for (int j = 1; j <= n; ++j)
                vis[i][j] = vis_init[i + ar - 1][j + ac - 1];

        int cnt(0);
        for (int i = 1; i <= m; ++i)
            for (int j = 1; j <= n; ++j)
                if (!vis[i][j]) dfs(i, j), ++cnt;
        return cnt;
    }
}

void init(int R, int C, int SR, int SC, int M, char *S) {
    num['E'] = 0, num['W'] = 1, num['S'] = 2, num['N'] = 3;
    r = R, c = C, sr = SR, sc = SC, m = M;
    for (int i = 0; i < m; ++i) s.push_back(S[i]);
    if (r <= 50 && c <= 50)
        subtask1::init();
}

int colours(int ar, int ac, int br, int bc) {
    if (r <= 50 && c <= 50)
        return subtask1::solve(ar, ac, br, bc);
}

char str[N];
int main() {
    cin.tie(NULL)->sync_with_stdio(false);
    cin >> r >> c >> m >> q >> sr >> sc >> str;
    init(r, c, sr, sc, m, str);

    int ar, ac, br, bc; while (q--) {
        cin >> ar >> ac >> br >> bc;
        cout << colours(ar, ac, br, bc) << '\n';
    }
}
/**  /\_/\
 *  (= ._.)
 *  / >0  \>1
**/

Compilation message

rainbow.cpp: In function 'void subtask1::init()':
rainbow.cpp:27:26: warning: array subscript has type 'char' [-Wchar-subscripts]
   27 |             sr += dr[num[c]];
      |                          ^
rainbow.cpp:28:26: warning: array subscript has type 'char' [-Wchar-subscripts]
   28 |             sc += dc[num[c]];
      |                          ^
rainbow.cpp: In function 'int colours(int, int, int, int)':
rainbow.cpp:66:1: warning: control reaches end of non-void function [-Wreturn-type]
   66 | }
      | ^
/usr/bin/ld: /tmp/cct2Fn8P.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccAZphVO.o:rainbow.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cct2Fn8P.o: in function `main':
grader.cpp:(.text.startup+0x167): undefined reference to `colour(int, int, int, int)'
collect2: error: ld returned 1 exit status