Submission #948506

# Submission time Handle Problem Language Result Execution time Memory
948506 2024-03-18T07:15:08 Z vjudge1 Land of the Rainbow Gold (APIO17_rainbow) C++17
11 / 100
42 ms 80984 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++;
        if(x==1 && y==1)return 1;
        int res=x+y;
        
        if(!g[ar][ac] && !g[br][ac])res--;
        if(!g[ar][bc] && !g[br][bc])res--;
        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;
    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";
    }
}*/

# Verdict Execution time Memory Grader output
1 Correct 5 ms 29276 KB Output is correct
2 Correct 15 ms 72536 KB Output is correct
3 Correct 19 ms 42072 KB Output is correct
4 Correct 20 ms 41820 KB Output is correct
5 Correct 15 ms 80984 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 17 ms 48188 KB Output is correct
12 Correct 16 ms 60408 KB Output is correct
13 Correct 16 ms 64492 KB Output is correct
14 Correct 9 ms 42076 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 42 ms 8648 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Runtime error 5 ms 860 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 29276 KB Output is correct
2 Correct 15 ms 72536 KB Output is correct
3 Correct 19 ms 42072 KB Output is correct
4 Correct 20 ms 41820 KB Output is correct
5 Correct 15 ms 80984 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 17 ms 48188 KB Output is correct
12 Correct 16 ms 60408 KB Output is correct
13 Correct 16 ms 64492 KB Output is correct
14 Correct 9 ms 42076 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Runtime error 6 ms 604 KB Execution killed with signal 11
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 29276 KB Output is correct
2 Correct 15 ms 72536 KB Output is correct
3 Correct 19 ms 42072 KB Output is correct
4 Correct 20 ms 41820 KB Output is correct
5 Correct 15 ms 80984 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 17 ms 48188 KB Output is correct
12 Correct 16 ms 60408 KB Output is correct
13 Correct 16 ms 64492 KB Output is correct
14 Correct 9 ms 42076 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Runtime error 6 ms 604 KB Execution killed with signal 11
19 Halted 0 ms 0 KB -