# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
816002 | Magikarp4000 | Art Class (IOI13_artclass) | C++17 | 5093 ms | 11148 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>
using namespace std;
#define OPTM ios_base::sync_with_stdio(0); cin.tie(0);
#define INF int(1e9+7)
#define ln '\n'
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define FOR(i,s,n) for (int i = s; i < n; i++)
#define FORR(i,n,s) for (int i = n; i > s; i--)
#define FORX(u, arr) for (auto u : arr)
#define PB push_back
#define F first
#define S second
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define UM unordered_map
#define US unordered_set
#define PQ priority_queue
#define ALL(v) v.begin(), v.end()
const ll LLINF = 1e18+1;
const int dx[] = {0,0,1,-1};
const int dy[] = {1,-1,0,0};
const int VAR = 30;
const int EPS = 10;
const int EPS1 = 10;
struct Coord {
PII tp,ri,bt,le;
};
const int MAXN = 5e2+5;
int h, w, r[MAXN][MAXN], g[MAXN][MAXN], b[MAXN][MAXN], z[MAXN][MAXN];
vector<Coord> v;
vector<int> cnts;
bool same(int x1, int y1, int x2, int y2) {
int diff = abs(r[y1][x1]-r[y2][x2])+abs(g[y1][x1]-g[y2][x2])+abs(b[y1][x1]-b[y2][x2]);
return diff <= VAR;
}
void bfs(int sx, int sy, int idx) {
queue<PII> q;
q.push({sx,sy});
while (!q.empty()) {
int x = q.front().F, y = q.front().S;
q.pop();
z[y][x] = idx;
FOR(i,0,4) {
int nx = x+dx[i], ny = y+dy[i];
if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
if (z[ny][nx]) continue;
if (same(x,y,nx,ny)) {
z[ny][nx] = idx;
q.push({nx,ny});
}
}
}
Coord cur = {{-1,-1},{-1,-1},{-1,-1},{-1,-1}};
FOR(i,0,h) {
FOR(j,0,w) {
if (z[i][j]) {
cur.tp = {j,i};
break;
}
}
}
FORR(j,w-1,-1) {
FOR(i,0,h) {
if (z[i][j]) {
cur.ri = {j,i};
break;
}
}
}
FORR(i,h-1,-1) {
FORR(j,w-1,-1) {
if (z[i][j]) {
cur.bt = {j,i};
break;
}
}
}
FOR(j,0,w) {
FORR(i,h,-1) {
if (z[i][j]) {
cur.le = {j,i};
break;
}
}
}
v.PB(cur);
int cnt = 0;
FOR(i,0,h) FOR(j,0,w) cnt += z[i][j] > 0;
cnts.PB(cnt);
}
int style(int H, int W, int R[500][500], int G[500][500], int B[500][500]) {
h = H, w = W;
FOR(i,0,h) FOR(j,0,w) r[i][j] = R[i][j], g[i][j] = G[i][j], b[i][j] = B[i][j];
int idx = 1;
FOR(i,0,h) {
FOR(j,0,w) {
if (z[i][j]) continue;
// if (r[i][j]+g[i][j]+b[i][j] <= VAR) continue;
bfs(j,i,idx++);
}
}
int vn = v.size(), num = 0;
FORX(u,v) {
int val = (u.tp.S-u.le.S)*(u.ri.F-u.bt.F);
int val1 = (u.ri.S-u.bt.S)*(u.tp.F-u.le.F);
if (abs(val-val1) <= EPS) num++;
}
if (num >= 5) return 1;
FOR(k,0,vn) {
Coord u = v[k];
if (abs(u.ri.F-u.tp.F) <= EPS1
&& abs(u.ri.S-u.bt.S) <= EPS1
&& abs(u.bt.F-u.le.F) <= EPS1
&& abs(u.tp.S-u.le.S) <= EPS1
) {
int bad = 0;
FOR(i,u.tp.S,u.bt.S+1) {
FOR(j,u.le.F,u.ri.F+1) bad += z[i][j] != k+1;
}
if ((u.tp.S-u.bt.S)*(u.ri.F-u.le.F) <= h*w/10) continue;
if (bad <= 5) return 4;
}
}
int gre = 0;
FOR(i,0,h) FOR(j,0,w) gre += g[i][j];
if (gre >= h*w*255/3) return 2;
// FORX(u,cnts) if (u >= h*w/4) return 4;
return 3;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |