Submission #341893

# Submission time Handle Problem Language Result Execution time Memory
341893 2020-12-31T11:52:00 Z Hazem Paint (COI20_paint) C++14
0 / 100
354 ms 524292 KB
/*
ID: tmhazem1
LANG: C++14
TASK: pprime
*/

#include <bits/stdc++.h>
using namespace std;

#define S second
#define F first
#define LL long long

const int N = 6e5 + 10;


LL LINF = 100000000000000000;
LL INF = 1000000000;
int MOD = 1e9+7;

vector<vector<int>>vec;
vector<vector<int>>component;
int colors[N];
int n,m;

int x[] = {1,-1,0,0};
int y[] = {0,0,1,-1};

bool in(int i,int j){

    return i>=0&&j>=0&&i<n&&j<m;
}

void dfs(int i,int j,int cnt){

    component[i][j] = cnt;
    for(int k=0;k<4;k++){
        int i1 = i+x[k],j1 = j+y[k];
        if(in(i1,j1)&&vec[i][j]==vec[i1][j1])
            dfs(i1,j1,cnt);
    }
}

int main()
{
    // freopen("out.txt","w",stdout);
    scanf("%d%d",&n,&m);

    for(int i=1;i<=n;i++){

        vector<int>vec0;
        for(int j=0;j<m;j++){
            int x;cin>>x;
            vec0.push_back(x);
        }
        vec.push_back(vec0);
        vector<int>vec1(m,-1);
        component.push_back(vec1);
    }
    
    int cnt = 1;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            if(component[i][j]!=-1)continue;
            else colors[cnt] = vec[i][j],dfs(i,j,cnt++);
    
    int q;
    scanf("%d",&q);
    while(q--){
        int i,j,c;
        scanf("%d%d%d",&i,&j,&c);
        colors[component[i][j]] = c;
    }    

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++)
            printf("%d ",colors[component[i][j]]);
        puts("");
    }
}       

Compilation message

paint.cpp: In function 'int main()':
paint.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
paint.cpp:68:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   68 |     scanf("%d",&q);
      |     ~~~~~^~~~~~~~~
paint.cpp:71:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   71 |         scanf("%d%d%d",&i,&j,&c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 300 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 319 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 333 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 354 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -