Submission #491654

# Submission time Handle Problem Language Result Execution time Memory
491654 2021-12-03T17:24:43 Z patrikpavic2 Sandwich (JOI16_sandwich) C++17
Compilation error
0 ms 0 KB
#include <cstdio>
#include <bitset>
#include <queue>
#include <vector>

#define X first
#define Y second
#define PB push_back

using namespace std;

const int N = 405;

int n, m;
char A[N][N];
int jos[N][N][2], bio[N][N][2];
queue < pair < pair < int, int >, int > > Q;
bitset < N * N > koji[N * N][2];

inline int kod(int i, int j){
    return i * m + j;
}


void smanji(int i, int j, int k, int oi, int oj, int ok){
    jos[i][j][k]--; koji[kod(i, j)][k] |= koji[kod(oi, oj)][ok];
    if(!jos[i][j][k])
        Q.push({{i, j}, k});
}


int main(){
    scanf("%d%d", &n, &m);
    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            koji[kod(i, j)][0][kod(i, j)] = 1;
            koji[kod(i, j)][1][kod(i, j)] = 1;
            scanf(" %c", &A[i][j]);
            if(A[i][j] == 'Z'){
                jos[i][j][0] = (!!i) + (!!j); jos[i][j][1] = (!!(n - i - 1)) + (!!(m - j - 1));
            }
            else{
                jos[i][j][0] = (!!i) + (!!(m - j - 1)); jos[i][j][1] = (!!(n - i - 1)) + (!!j);
            }
        }
    }
    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            if(!jos[i][j][0]) Q.push({{i, j}, 0});
            if(!jos[i][j][1]) Q.push({{i, j}, 1});
        }
    }
    for(;!Q.empty();Q.pop()){
        int cx = Q.front().X.X, cy = Q.front().X.Y;
        int sm = Q.front().Y;
      //  printf("%d %d %d\n", cx, cy, sm);
        bio[cx][cy][sm] = 1;
        if(A[cx][cy] == 'N' && sm == 0){
            if(cy) smanji(cx, cy - 1, A[cx][cy - 1] == 'Z', cx, cy, sm);
            if(cx + 1 < n) smanji(cx + 1, cy, 0, cx, cy, sm);
        }
        if(A[cx][cy] == 'N' && sm == 1){
            if(cx) smanji(cx - 1, cy, 1, cx, cy, sm);
            if(cy + 1 < m) smanji(cx, cy + 1, A[cx][cy + 1] == 'N', cx, cy, sm);
        }
        if(A[cx][cy] == 'Z' && sm == 0){
            if(cx + 1 < n) smanji(cx + 1, cy, 0, cx, cy, sm);
            if(cy + 1 < m) smanji(cx, cy + 1, A[cx][cy + 1] == 'N', cx, cy, sm);
        }
        if(A[cx][cy] == 'Z' && sm == 1){
            if(cx) smanji(cx - 1, cy, 1, cx, cy, sm);
            if(cy) smanji(cx, cy - 1, A[cx][cy - 1] == 'Z', cx, cy, sm);
        }
    }
    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            int ans = N * N;
            if(bio[i][j][0]) ans = min(ans, (int)koji[kod(i, j)][0].count());
            if(bio[i][j][1]) ans = min(ans, (int)koji[kod(i, j)][1].count());
            printf("%d ", ans == N * N ? -1 : 2 * ans);
        }
        printf("\n");
    }
    return 0;
}

Compilation message

sandwich.cpp: In function 'int main()':
sandwich.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
sandwich.cpp:38:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |             scanf(" %c", &A[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~~
/tmp/ccpJlSKO.o: in function `smanji(int, int, int, int, int, int)':
sandwich.cpp:(.text+0x24e): relocation truncated to fit: R_X86_64_PC32 against symbol `jos' defined in .bss section in /tmp/ccpJlSKO.o
sandwich.cpp:(.text+0x28f): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccpJlSKO.o
sandwich.cpp:(.text+0x30e): relocation truncated to fit: R_X86_64_PC32 against symbol `Q' defined in .bss section in /tmp/ccpJlSKO.o
/tmp/ccpJlSKO.o: in function `main':
sandwich.cpp:(.text.startup+0x9): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccpJlSKO.o
sandwich.cpp:(.text.startup+0x10): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccpJlSKO.o
sandwich.cpp:(.text.startup+0x3f): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccpJlSKO.o
sandwich.cpp:(.text.startup+0x4f): relocation truncated to fit: R_X86_64_PC32 against symbol `jos' defined in .bss section in /tmp/ccpJlSKO.o
sandwich.cpp:(.text.startup+0x56): relocation truncated to fit: R_X86_64_PC32 against symbol `A' defined in .bss section in /tmp/ccpJlSKO.o
sandwich.cpp:(.text.startup+0x5c): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccpJlSKO.o
sandwich.cpp:(.text.startup+0xa2): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccpJlSKO.o
sandwich.cpp:(.text.startup+0xa8): additional relocation overflows omitted from the output
/usr/bin/ld: failed to convert GOTPCREL relocation; relink with --no-relax
collect2: error: ld returned 1 exit status