답안 #401077

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
401077 2021-05-09T10:21:39 Z A_D 무지개나라 (APIO17_rainbow) C++14
0 / 100
1 ms 332 KB
//#include "rainbow.h"

#include <bits/stdc++.h>
/*

static int R, C, M, Q;
static int sr, sc;
static char S[100000 + 5];

*/

#define LL long long

using namespace std;













const int N=3;
const int M=2e5+1000;
bool a[N][M];
int pre[3][N];
int mn[3];
int mx[3];
bool v=0;
void init(int R, int C, int sr, int sc, int M, char *S) {
    string s;
    s+=S;
    int x=sr;
    int y=sc;
    a[x][y]=1;
    mn[1]=1e18;
    mn[2]=1e18;
    mx[1]=0;
    mx[2]=0;
    for(auto z:s){
        mn[x]=min(mn[x],y);
        mx[x]=max(mx[x],y);
        if(z=='N'){
            x--;
        }
        if(z=='S'){
            x++;
        }
        if(z=='W'){
            y--;
        }
        if(z=='E'){
            y++;
        }
        mn[x]=min(mn[x],y);
        mx[x]=max(mx[x],y);
        a[x][y]=1;
    }
    for(int i=1;i<=R;i++){
        for(int j=1;j<=C;j++){
            pre[i][j]=pre[i][j-1];
            if(a[i][j-1]==1&&a[i][j]==0)pre[i][j]++;
        }
    }
    if(mn[1]==1e18)v|=1;
    if(mn[2]==1e18)v|=2;
}

int colour(int ar, int ac, int br, int bc) {
    if(v){
        int ret=0,ret2=0;
        for(int i=ar;i<=br;i++){
            if(v&i){
                ret2=1;
            }
            else{
                if(ac<mn[ar])ret++;
                if(bc>mx[ar])ret++;
            }
        }
        if(ret2)return 1;
        return ret;
    }
    else if(br-ar==0){
        return pre[ar][bc]-pre[ar][ac-1]+(mn[ar] > ar );
    }
    else{
        int ans=0;
        ans+=pre[1][bc]-pre[1][ac-1];
        ans+=pre[2][bc]-pre[2][ac-1];
        int h=(max(mn[1],mn[2])>ac)-(max(mx[1],mx[2])>bc);
        ans+=h;
        return ans;
    }
}
/*


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 'void init(int, int, int, int, int, char*)':
rainbow.cpp:41:11: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   41 |     mn[1]=1e18;
      |           ^~~~
rainbow.cpp:42:11: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   42 |     mn[2]=1e18;
      |           ^~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -