# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
29713 | inqr | Art Class (IOI13_artclass) | C++14 | 225 ms | 26952 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "artclass.h"
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rt insert
#define st first
#define nd second
#define ll long long
using namespace std;
int h,w,r[500][500],g[500][500],b[500][500];
int d[8][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
int d2[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
int diffedge,diffsame;
int dfsv[505][505];
vector <pair<int,int> > edges_dfs;
vector <pair<int,int> > edges;
int change(int h1,int w1,int h2,int w2){return abs(r[h1][w1]-r[h2][w2])+abs(g[h1][w1]-g[h2][w2])+abs(b[h1][w1]-b[h2][w2]);}
void dfs(int hn,int wn){
if(dfsv[hn][wn]==1)return;
dfsv[hn][wn]=1;
//printf("\ndfs= %d %d\n",hn,wn);
int isedge=0;
for(int i=0;i<8;i++){
if(change(hn,wn,hn+d[i][0],wn+d[i][1])>=diffedge)
isedge++;
}
if(isedge>=5){
edges.pb(mp(hn,wn));
edges_dfs.pb(mp(hn,wn));
}
for(int i=0;i<4;i++){
int hnx=hn+d2[i][0],wnx=wn+d2[i][1];
//printf("%d %d -> %d %d\n",hn,wn,hnx,wnx);
//printf("%d %d %d\n",i,d2[i][0],d2[i][1]);
//printf("hn wn %d %d %d\n",r[hn][wn],g[hn][wn],b[hn][wn]);
//printf("hnx wnx %d %d %d\n",r[hnx][wnx],g[hnx][wnx],b[hnx][wnx]);
//printf("change hn hnx=%d\n",change(hn,wn,hnx,wnx));
//printf("dfsv hn wn =%d hnx wnx=%d\n",dfsv[hn][wn],dfsv[hnx][wnx]);
if(!dfsv[hnx][wnx]){
//printf("1\n");
if(change(hn,wn,hnx,wnx)<=diffsame){
//printf("2\n");
if(0<=hnx&&hnx<h&&0<=wnx&&wnx<w){
//printf(" %d %d -> %d %d\n",hn,wn,hnx,wnx);
dfs(hn+d2[i][0],wn+d2[i][1]);
}
}
}
}
}
int solve(){
int s1,s2,s3,s4;s1=s2=s3=s4=0;
int groupcnt=0;
memset(dfsv,0,sizeof(dfsv));
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(dfsv[i][j]==0){
edges.clear();
groupcnt++;
dfs(i,j);
//printf("edges = %d\n",(int)edges_dfs.size());
}
}
}
//printf("groupcnt=%d\n",groupcnt);
if(edges.size()<=500)return 1;
else if(edges.size()>=3000)return 3;
else return 4;
}
int style(int H, int W, int R[500][500], int G[500][500], int B[500][500]) {
//freopen("artclass.out","w",stdout);
h=H;w=W;
long long gg,rr,bb;
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
r[i][j]=R[i][j];
g[i][j]=G[i][j];
b[i][j]=B[i][j];
gg+=g[i][j];
bb+=b[i][j];
rr+=r[i][j];
if(gg>=bb+rr)return 2;
}
}
diffsame=160;
diffedge=320;
return solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |