답안 #446828

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
446828 2021-07-23T12:08:56 Z MOUF_MAHMALAT Paint (COI20_paint) C++11
8 / 100
641 ms 964 KB
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
using namespace std;
typedef int ll;
ll n,m,a[10009],q,c;
vector<vector<ll> >v;
queue<ll>dq;
ll op(ll x,ll y)
{
    if(x<0||y<0||x>=n||y>=m)
        return -1;
    return x*m+y;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    for(ll i=0; i<n*m; i++)
        cin>>a[i];
    v.resize(n*m);
    for(ll i=0; i<n; i++)
        for(ll j=0; j<m; j++)
        {
            ll o=op(i,j),k;
            k=op(i-1,j);
            if(k>-1)
                v[o].push_back(k);
            k=op(i+1,j);
            if(k>-1)
                v[o].push_back(k);
            k=op(i,j-1);
            if(k>-1)
                v[o].push_back(k);
            k=op(i,j+1);
            if(k>-1)
                v[o].push_back(k);
        }
    cin>>q;
    while(q--)
    {
        ll x,y,z,o;
        cin>>x>>y>>z;
        o=op(x-1,y-1);
        if(a[o]==z)
            continue;
        c=a[o],a[o]=z;
        dq.push(o);
        while(!dq.empty())
        {
            o=dq.front();
            dq.pop();
            for(auto u:v[o])
                if(a[u]==c)
                {
                    a[u]=z;
                    dq.push(u);
                }
        }
    }
    for(ll i=0; i<n*m; i++)
    {
        if(i&&i%m==0)
            cout<<"\n";
        cout<<a[i]<<" ";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 5 ms 844 KB Output is correct
4 Correct 6 ms 716 KB Output is correct
5 Correct 395 ms 872 KB Output is correct
6 Correct 641 ms 964 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -