답안 #948543

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
948543 2024-03-18T07:48:44 Z vjudge1 무지개나라 (APIO17_rainbow) C++17
23 / 100
45 ms 80780 KB
#include <bits/stdc++.h>
#include "rainbow.h"
//#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N=2e5+5;
int g[100][N],vis[100][N],cnt[100][N];
int r,c;
void init(int R, int C, int sr, int sc, int M,  char *S){
    r=R;
    c=C;
    g[sr][sc]=1;
    for(int i=0;i<M;i++){
        if(S[i]=='N')sr--;
        else if(S[i]=='S')sr++;
        else if(S[i]=='W')sc--;
        else sc++;
        g[sr][sc]=1;
    }
    
    for(int i=1;i<=r;i++){
        g[i][0]=1;
        for(int j=1;j<=c;j++){
            cnt[i][j]=cnt[i][j-1];
            if(!g[i][j] && g[i][j-1])cnt[i][j]++;
        
        }
        
    }
       
}
int colour(int ar, int ac, int br, int bc){
    if(r==2){
        if(ar==br){
            int ans=cnt[ar][bc]-cnt[ar][ac-1];
            if(!g[ar][ac-1] && !g[ar][ac])ans++;
            return ans;
        }
        int x=cnt[ar][bc]-cnt[ar][ac-1];
        if(!g[ar][ac-1] && !g[ar][ac])x++;
        int y=cnt[br][bc]-cnt[br][ac-1];
        if(!g[br][ac-1] && !g[br][ac])y++;
        int res=x+y;
        if(!g[ar][ac] && !g[br][ac])res--;
        if(!g[ar][bc] && !g[br][bc])res--;
        
        if(res==0 && x==1 && y==1)return 1;
        return res;
        
    }
    queue <pair <int,int> > q;
    vector <int> X={0,0,-1,1};
    vector <int> Y={1,-1,0,0};
    int ans=0;
    for(int i=ar;i<=br;i++){
        for(int j=ac;j<=bc;j++){
            if(!vis[i][j] && !g[i][j]){
                ans++;
                vis[i][j]=1;
                q.push({i,j});
                while(!q.empty()){
                    int x=q.front().ff;
                    int y=q.front().ss;
                    q.pop();
                    for(int k=0;k<4;k++){
                        if(x+X[k]>=ar && x+X[k]<=br && y+Y[k]>=ac && y+Y[k]<=bc && !g[x+X[k]][y+Y[k]] && !vis[x+X[k]][y+Y[k]]){
                            vis[x+X[k]][y+Y[k]]=1;
                            q.push({x+X[k],y+Y[k]});
                        }
                    }
                }
            }
            
        }
    }
    for(int i=1;i<=r;i++){
        for(int j=1;j<=c;j++){
            vis[i][j]=0;
        }
    }
    return ans;
}
/*signed main(){
    ios_base::sync_with_stdio();
    cin.tie(0);cout.tie(0);
    int r,c,m,q,x,y;
    cin>>r>>c>>m>>q>>x>>y;
    string s="";
    if(m!=0)cin>>s;
    init(r,c,x,y,m,s);
    for(int i=0;i<q;i++){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        cout<<colour(a,b,c,d)<<"\n";
    }
}*/

# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 29276 KB Output is correct
2 Correct 19 ms 72536 KB Output is correct
3 Correct 18 ms 41820 KB Output is correct
4 Correct 18 ms 42072 KB Output is correct
5 Correct 19 ms 80780 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 18 ms 48188 KB Output is correct
12 Correct 18 ms 60404 KB Output is correct
13 Correct 16 ms 64348 KB Output is correct
14 Correct 10 ms 41820 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 42 ms 8708 KB Output is correct
4 Correct 43 ms 8784 KB Output is correct
5 Correct 43 ms 8680 KB Output is correct
6 Correct 42 ms 8684 KB Output is correct
7 Correct 43 ms 8788 KB Output is correct
8 Correct 42 ms 8748 KB Output is correct
9 Correct 43 ms 8784 KB Output is correct
10 Correct 43 ms 8784 KB Output is correct
11 Correct 43 ms 8788 KB Output is correct
12 Correct 39 ms 8784 KB Output is correct
13 Correct 40 ms 8784 KB Output is correct
14 Correct 40 ms 8844 KB Output is correct
15 Correct 39 ms 8784 KB Output is correct
16 Correct 45 ms 8716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Runtime error 5 ms 600 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 29276 KB Output is correct
2 Correct 19 ms 72536 KB Output is correct
3 Correct 18 ms 41820 KB Output is correct
4 Correct 18 ms 42072 KB Output is correct
5 Correct 19 ms 80780 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 18 ms 48188 KB Output is correct
12 Correct 18 ms 60404 KB Output is correct
13 Correct 16 ms 64348 KB Output is correct
14 Correct 10 ms 41820 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Runtime error 5 ms 604 KB Execution killed with signal 11
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 29276 KB Output is correct
2 Correct 19 ms 72536 KB Output is correct
3 Correct 18 ms 41820 KB Output is correct
4 Correct 18 ms 42072 KB Output is correct
5 Correct 19 ms 80780 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 18 ms 48188 KB Output is correct
12 Correct 18 ms 60404 KB Output is correct
13 Correct 16 ms 64348 KB Output is correct
14 Correct 10 ms 41820 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Runtime error 5 ms 604 KB Execution killed with signal 11
19 Halted 0 ms 0 KB -