# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
940363 | shenfe1 | Art Class (IOI13_artclass) | C++17 | 90 ms | 32820 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 <bits/stdc++.h>
#pragma optimize("Ofast")
#pragma target("avx2")
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define mem(a,i) memset(a,i,sizeof(a))
#define sz(s) (int)s.size()
#define y1 yy
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound
#define gcd(a,b) __gcd(a,b)
#define in insert
// #define int ll
const int MAX=500+15;
const ll inf=1e9;
const int mod=1e9+7;
const int mod1=1e9+9;
const ld eps=1e-9;
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,-1,1,-1};
int binpow(int a,int n){
if(!n)return 1;
if(n%2==1)return a*binpow(a,n-1);
int k=binpow(a,n/2);
return k*k;
}
#include "artclass.h"
int r[MAX][MAX],g[MAX][MAX],b[MAX][MAX];
int isBorder[MAX][MAX];
int h,w;
vector<pii> vec;
int use[MAX][MAX];
bool good(int i,int j){
return (0<=i&&i<h&&0<=j&&j<w);
}
void dfs(int i,int j){
// cout<<i<<" "<<j<<"\n";
vec.pb({i,j});
use[i][j]=1;
for(int k=0;k<8;k++){
int ni=i+dx[k];
int nj=j+dy[k];
if(good(ni,nj)&&!isBorder[ni][nj]&&!use[ni][nj])dfs(ni,nj);
}
}
int style(int H, int W, int R[500][500], int G[500][500], int B[500][500]) {
h=H;
w=W;
int C1=20;
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];
}
{
bool ok=1;
int cnt=0;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(abs(max({R[i][j],G[i][j],B[i][j]})-min({R[i][j],G[i][j],B[i][j]}))<=C1&&max({R[i][j],G[i][j],B[i][j]})<=128){
isBorder[i][j]=1;
cnt++;
}
}
}
// cout<<cnt<<"\n";
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(!isBorder[i][j]&&!use[i][j]){
vec.clear();
dfs(i,j);
// return -1;
ld mr=0,mb=0,mg=0;
for(auto x:vec){
mr+=R[x.F][x.S];
mb+=B[x.F][x.S];
mg+=G[x.F][x.S];
}
if(vec.empty())continue;
cout<<sz(vec)<<"\n";
mr/=sz(vec);
mb/=sz(vec);
mg/=sz(vec);
int cnt=0;
for(auto x:vec){
if(abs(R[x.F][x.S]-mr)<=2*C1||abs(G[x.F][x.S]-mg)<=2*C1||abs(B[x.F][x.S]-mb)<=2*C1)cnt++;
}
if(cnt<sz(vec)*9.0/10){
ok=0;
// cout<<sz(vec)<<"\n";
}
}
}
}
if(ok)return 1;
}
bool is4=1;
int C=50;
for(int i=0;i<H;i++){
int cnt=0;
ld mr=0,mb=0,mg=0;
for(int j=0;j<W;j++){
mr+=R[i][j];
mb+=B[i][j];
mg+=G[i][j];
}
mr/=W;
mb/=W;
mg/=W;
for(int j=0;j<W;j++){
if(abs(R[i][j]-mr)<=C&&abs(G[i][j]-mg)<=C&&abs(B[i][j]-mb)<=C)cnt++;
}
if(cnt<W*9.0/10){
is4=0;
}
}
if(is4==1)return 4;
return 2;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |