답안 #390845

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
390845 2021-04-17T08:09:33 Z A_D Paint (COI20_paint) C++14
0 / 100
321 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+10);
    }
    int cnt=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cnt++;
            scanf("%d",&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("%d",&i);
        scanf("%d",&j);
        scanf("%d",&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("%d",&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("%d",&i);
      |         ~~~~~^~~~~~~~~
paint.cpp:74:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   74 |         scanf("%d",&j);
      |         ~~~~~^~~~~~~~~
paint.cpp:75:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   75 |         scanf("%d",&c);
      |         ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 70804 KB Output is correct
2 Runtime error 277 ms 524292 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 317 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 321 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 318 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -