Submission #390843

# Submission time Handle Problem Language Result Execution time Memory
390843 2021-04-17T07:48:15 Z A_D Paint (COI20_paint) C++14
0 / 100
341 ms 524292 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+100;
int a[N];
vector<int> idx[N];
int p[N];
set<int> st[N];
vector<int> vec;
set<int> q;
int x[]={0,0,1,-1 };
int y[]={1,-1,0,0 };
int find(int u)
{
    if(u==p[u])return u;
    return p[u]=find(p[u]);
}
void compine(int u,int v,int c)
{
    if(st[u].size()>st[v].size())swap(u,v);
    p[u]=v;
    for(auto x:st[u])st[v].insert(x);
    st[u].clear();
    a[v]=c;
}
int n,m;
void solve()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        idx[i].resize(m+1);
    }
    int cnt=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cnt++;
            scanf("%lld",&a[cnt]);
            p[cnt]=cnt;
            idx[i][j]=cnt;
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            int i1=idx[i][j];
            int u=find(i1);
            vec.clear();
            for(int k=0;k<4;k++){
                int ni=i+x[k];
                int nj=j+y[k];
                if(min(ni,nj)==0)continue;
                if(ni>n||nj>m)continue;
                int i2=idx[ni][nj];
                int v=find(i2);
                if(a[i1]==a[i2]){
                    if(u!=v){
                        vec.push_back(v);
                    }
                }
                else{
                    st[u].insert(v);
                }
            }
            for(auto x:vec){
                compine(u,x,a[u]);
            }
        }
    }
    int q;
    cin>>q;
    while(q--){
  //      fix();
        int c,i,j;
        scanf("%lld",&i);
        scanf("%lld",&j);
        scanf("%lld",&c);
        int me=idx[i][j];
        me=find(me);
       // if(!q)cout<<me<<" "<<a[me]<<endl;
        if(a[me]==c)continue;
        a[me]=c;
        vec.clear();
        for(auto x:st[me]){
            if(a[x]==c)vec.push_back(x);
        }
        for(auto x:vec){
            me=find(me);
            compine(me,x,c);
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            int me=idx[i][j];
            me=find(me);
            cout<<a[me]<<" ";
        }
        cout<<endl;
    }
}
main()
{
    int t=1;
//    cin>>t;
    while(t--)solve();
}

Compilation message

paint.cpp:99:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   99 | main()
      |      ^
paint.cpp: In function 'void solve()':
paint.cpp:37:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 |             scanf("%lld",&a[cnt]);
      |             ~~~~~^~~~~~~~~~~~~~~~
paint.cpp:73:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   73 |         scanf("%lld",&i);
      |         ~~~~~^~~~~~~~~~~
paint.cpp:74:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   74 |         scanf("%lld",&j);
      |         ~~~~~^~~~~~~~~~~
paint.cpp:75:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   75 |         scanf("%lld",&c);
      |         ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 46 ms 70852 KB Output is correct
2 Runtime error 264 ms 524292 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 328 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 341 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 308 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -