답안 #401277

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
401277 2021-05-09T18:14:26 Z A_D 무지개나라 (APIO17_rainbow) C++14
컴파일 오류
0 ms 0 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 MM=2e5+1000;
bool a[N][MM];
int pre[3][MM];
int mn[3];
int mx[3];
int v=0;
void init(int R, int C, int sr, int sc, int M, char *S) {
    v=0;
    string s;
    memset(a,0,sizeof(a));
    memset(pre,0,sizeof(pre));
    memset(mn,0,sizeof(mn));
    memset(mx,0,sizeof(mx));
    s+=S;
    int x=sr;
    int y=sc;
    a[x][y]=1;
    mn[1]=1e9;
    mn[2]=1e9;
    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]==1e9)v|=1;
    if(mn[2]==1e9)v|=2;
    for(int i=1;i<=C;i++)cout<<pre[1][i]<<" ";cout<<endl;
    for(int i=1;i<=C;i++)cout<<pre[2][i]<<" ";cout<<endl;
    cout<<mn[1]<<" "<<mn[2]<<" "<<mx[1]<<" "<<mx[2]<<endl;
    cout<<v<<endl;
}

int colour(int ar, int ac, int br, int bc) {
    if(v){
        int ret=0,ret2=0;
        for(int i=ar;i<=br;i++){
      //  cout<<ac<<" "<<mn[i]<<" "<<bc<<" "<<mx[i]<<endl;
    //        cout<<i<<" "<<v<<endl;
            if(v&i){
                ret2=1;
            }
            else{
                if(ac<mn[i])ret++;
                if(bc>mx[i])ret++;
            }
        }
        if(ret2)return 1;
        return ret;
    }
    else if(br-ar==0){
        return pre[ar][bc]-pre[ar][ac-1]+ ( (pre[ar][ac] == pre[ar][ac-1]) &&(a[ar][ac]==0) );
    }
    else{
        int ans=0;
        ans+=pre[1][bc]-pre[1][ac-1]+( (pre[1][ac] == pre[1][ac-1]) &&(a[1][ac]==0)  );
  //      cout<<ans<<" ";
        ans+=pre[2][bc]-pre[2][ac-1]+( (pre[2][ac] == pre[2][ac-1]) &&(a[2][ac]==0)  );
    //    cout<<ans<<" ";
        int h=-(max(mx[1],mx[2])<bc);
        h-=( (pre[2][ac] == 0) &&(a[2][ac]==0) && (pre[1][ac] == 0 )&&(a[1][ac]==0)  );
      //  cout<<h<<endl;
        //cout<<(max(mn[1],mn[2])>ac)<<" "<<(max(mx[1],mx[2])<bc)<<endl;
//        cout<<max(mx[1],mx[2])<<" "<<bc<<endl;
        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;
}


//*/


/*

2 14 13 1000
1 2
EEESEEENEESEE


2 8 4 1000
1 2
EEEE

*/

Compilation message

rainbow.cpp: In function 'void init(int, int, int, int, int, char*)':
rainbow.cpp:79:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   79 |     for(int i=1;i<=C;i++)cout<<pre[1][i]<<" ";cout<<endl;
      |     ^~~
rainbow.cpp:79:47: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   79 |     for(int i=1;i<=C;i++)cout<<pre[1][i]<<" ";cout<<endl;
      |                                               ^~~~
rainbow.cpp:80:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   80 |     for(int i=1;i<=C;i++)cout<<pre[2][i]<<" ";cout<<endl;
      |     ^~~
rainbow.cpp:80:47: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   80 |     for(int i=1;i<=C;i++)cout<<pre[2][i]<<" ";cout<<endl;
      |                                               ^~~~
rainbow.cpp: In function 'int main()':
rainbow.cpp:129:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  129 |     scanf("%d %d %d %d", &R, &C, &M, &Q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
rainbow.cpp:130:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  130 |     scanf("%d %d", &sr, &sc);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
rainbow.cpp:132:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  132 |         scanf(" %s ", S);
      |         ~~~~~^~~~~~~~~~~
rainbow.cpp:140:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  140 |         scanf("%d %d %d %d", &ar, &ac, &br, &bc);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/cclLj0IQ.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccP6gLB6.o:rainbow.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status