Submission #393794

# Submission time Handle Problem Language Result Execution time Memory
393794 2021-04-24T13:16:19 Z sad Paint (COI20_paint) C++14
0 / 100
82 ms 17360 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=400006;
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);
    }
    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++)
        {
            int x=go(i,j);
            cin>>co[x];
            pa[x]=x;
            int u=x,uu=go(i-1,j),uuu=go(i,j-1);
            if(i>1)
            {
                if(co[u]==co[uu])
                {
                    merge(u,uu);
                }
                else {v[u].pb(uu);
                v[uu].pb(u);}

            }
            if(j>1)
            {
                if(co[u]==co[uuu])
                {
                    merge(u,uuu);
                }
                else {v[u].pb(uuu);
                v[uuu].pb(u);}
            }
        }
    }
    int q;cin>>q;
    while(q--)
    {
        int x,y,c;
        cin>>x>>y>>c;
        int u=go(x,y);
        int w=get(u);
        if(c==co[w])continue;
        co[w]=1-co[w];
        for(auto it:v[u])
        {
            int t=get(it);
            if(t==w)continue;
            merge(t,w);
            w=get(w);
        }
        co[w]=c;
    }
    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:40:9: warning: unused variable 'r' [-Wunused-variable]
   40 |     int r=0;
      |         ^
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 9676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 11640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 77 ms 17360 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 82 ms 15544 KB Output isn't correct
2 Halted 0 ms 0 KB -