답안 #393748

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
393748 2021-04-24T12:30:05 Z sad Paint (COI20_paint) C++14
0 / 100
3000 ms 21556 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
using namespace std;
int n,m;
const int N=200006;
vector<short int>a[N],vis[N];
vector<short int>v[N];
short int pa[N],co[N];
int go (int x,int y)
{
    int re=x-1;
    re*=m;
    re+=y;return re;
}
int get (int x)
{
    if(pa[x]==x)return x;
    return pa[x]=get(pa[x]);
}
void merge(int x,int y)
{
    x=get(x);
    y=get(y);
    if(x==y)return;
    if(v[x].size()<v[y].size())swap(x,y);
    for(auto it:v[y])
    {
        int o=get(it);
        if(o==x)continue;
        v[x].pb(o);
    }
    v[y].clear();
    pa[y]=x;
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>m;
    int r=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<m+1;j++)
        {
            cin>>co[go(i,j)];
            pa[go(i,j)]=go(i,j);
            int u=go(i,j),uu=go(i-1,j),uuu=go(i,j-1);
            if(i>1)
            {
                if(co[u]==co[uu])
                {
                    merge(u,go(i-1,j));
                }
                else {v[u].pb(go(i-1,j));
                v[go(i-1,j)].pb(u);}

            }
            if(j>1)
            {
                if(co[u]==co[uuu])
                {
                    merge(u,go(i,j-1));
                }
                else {v[u].pb(go(i,j-1));
                v[go(i,j-1)].pb(u);}
            }
        }
    }


    int q;cin>>q;
    while(q--)
    {
        int x,y,c;
        cin>>x>>y>>c;
        int u=go(x,y);
        if(c==co[u])continue;
        co[u]=1-co[u];
        u=get(u);
        for(auto it:v[u])
        {
            merge(it,u);
        }
    }
    for(int i=1;i<n+1;i++)
    {
        for(int j=1;j<m+1;j++)cout<<co[get(go(i,j))]<<" ";
        cout<<endl;
    }

}

Compilation message

paint.cpp: In function 'int main()':
paint.cpp:42:9: warning: unused variable 'r' [-Wunused-variable]
   42 |     int r=0;
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 14376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3067 ms 16296 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3085 ms 21556 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3099 ms 19868 KB Time limit exceeded
2 Halted 0 ms 0 KB -