# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
8137 | IohcEjnim | Art Class (IOI13_artclass) | C++98 | 178 ms | 33536 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 <stdio.h>
const int same = 31;
int H, W;
int R[510][510], G[510][510], B[510][510];
bool check[510][510];
int abs(int a) {return a > 0 ? a : -a;}
bool sim(int x, int y, int xx, int yy)
{
if (abs(R[x][y]-R[xx][yy]) > same) return false;
if (abs(G[x][y]-G[xx][yy]) > same) return false;
if (abs(B[x][y]-B[xx][yy]) > same) return false;
return true;
}
void flood(int x, int y)
{
if (x < 0 || x >= H || y < 0 || y >= W) return;
if (check[x][y]) return;
check[x][y] = true;
if (sim(x, y, x, y+1)) flood(x, y+1);
if (sim(x, y, x, y-1)) flood(x, y-1);
if (sim(x, y, x+1, y)) flood(x+1, y);
if (sim(x, y, x-1, y)) flood(x-1, y);
}
int style(int h, int w, int r[500][500], int g[500][500], int b[500][500])
{
H = h; W = w;
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];
}
long long sr = 0, sg = 0, sb = 0;
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
{
sr += R[i][j];
sg += G[i][j];
sb += B[i][j];
}
sr /= H*W;
sg /= H*W;
sb /= H*W;
//printf("<%3lld %3lld %3lld> ", sr, sg, sb);
int cnt = 0;
for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) check[i][j] = false;
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
if (not check[i][j])
{
flood(i, j);
cnt++;
}
//printf("<%6d> ", cnt);
long long cr = 0, cg = 0, cb = 0;
for (int i = 0; i < H-1; i++)
for (int j = 0; j < W-1; j++)
{
cr += abs(R[i][j]-R[i][j+1]);
cg += abs(G[i][j]-G[i][j+1]);
cb += abs(B[i][j]-B[i][j+1]);
cr += abs(R[i][j]-R[i+1][j]);
cg += abs(G[i][j]-G[i+1][j]);
cb += abs(B[i][j]-B[i+1][j]);
}
cr *= 10;
cg *= 10;
cb *= 10;
cr /= H*W;
cg /= H*W;
cb /= H*W;
//printf("<%4lld %4lld %4lld> ", cr, cg, cb);
if (cnt < 15) return 4;
if (cr+cg+cb > 1200) return 3;
if (sb < 80) return 2;
return 1;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |