답안 #945134

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
945134 2024-03-13T12:41:44 Z TAhmed33 무지개나라 (APIO17_rainbow) C++
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
bool ok[51][51];
int dx[4] = {0, -1, 0, 1}, dy[4] = {1, 0, -1, 0};
int mny, mxy, mnx, mxx;
map <char, int> lk = {
    {'E', 0},
    {'N', 1},
    {'W', 2},
    {'S', 3}
};
int n, m;
void init (int N, int M, int x, int y, int z, char *s) {
    n = N; m = M;
    x--; y--;
    for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) ok[i][j] = 1;
    ok[x][y] = 0;
    mny = mxy = y; mnx = mxx = x;
    for (int i = 0; i < z; i++) {
        x += dx[lk[s[i]]]; y += dy[lk[s[i]]];
        mny = min(mny, y);
        mxy = max(mxy, y);
        mnx = min(mnx, x);
        mxx = max(mxx, x);
        ok[x][y] = 0;
    }
    /*for (int i = 0; i < n; i++) {
    	for (int j = 0; j < m; j++) {
    		cout << ok[i][j];
    	}
    	cout << '\n';
    }*/
}
int colour (int ar, int ac, int br, int bc) {
    ar--; br--; ac--; bc--;
    if (ar > br) swap(ar, br);
    if (ac > bc) swap(ac, bc);
    //cout << ar << " " << ac << ": " << br << " " << bc << '\n';
    int v = 0, e = 0, f = 0;
    for (int i = ar; i <= br; i++) {
        for (int j = ac; j <= bc; j++) {
            if (!ok[i][j]) continue;
            v++;
        }
    }
    for (int i = ar; i <= br; i++) {
        for (int j = ac; j <= bc; j++) {
            if (!ok[i][j]) continue;
            if (i < br) if (ok[i + 1][j]) e++;
            if (j < bc) if (ok[i][j + 1]) e++;
            if (i < br && j < bc) if (ok[i + 1][j] && ok[i][j + 1] && ok[i + 1][j + 1]) f++;
        }
    }
    if (ar > mnx && br < mxx && ac > mny && bc < mxy) f++;
    return v - e + f;
}
static int R, C, M, Q;
static int sr, sc;
static char S[100000 + 5];
int main() {
    scanf("%d %d %d %d", &R, &C, &M, &Q);
    scanf("%d %d", &sr, &sc);
    if (M > 0) {
        scanf(" %s ", S);
    }

    init(R, C, sr, sc, M, S);

    int query;
    for (query = 0; query < Q; query++) {
        int ar, ac, br, bc;
        scanf("%d %d %d %d", &ar, &ac, &br, &bc);
        printf("%d\n", colour(ar, ac, br, bc));
    }

    return 0;
}

Compilation message

rainbow.cpp: In function 'int main()':
rainbow.cpp:61:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |     scanf("%d %d %d %d", &R, &C, &M, &Q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
rainbow.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |     scanf("%d %d", &sr, &sc);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
rainbow.cpp:64:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         scanf(" %s ", S);
      |         ~~~~~^~~~~~~~~~~
rainbow.cpp:72:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         scanf("%d %d %d %d", &ar, &ac, &br, &bc);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/cc5Hauoa.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccFkRlOc.o:rainbow.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status