Submission #754213

#TimeUsernameProblemLanguageResultExecution timeMemory
754213marvinthangArt Class (IOI13_artclass)C++17
98 / 100
55 ms3236 KiB
/*************************************
*    author: marvinthang             *
*    created: 06.06.2023 21:33:35    *
*************************************/

#include "artclass.h"
#include <bits/stdc++.h>

using namespace std;

#define                  fi  first
#define                  se  second
#define                left  ___left
#define               right  ___right
#define                TIME  (1.0 * clock() / CLOCKS_PER_SEC)
#define             MASK(i)  (1LL << (i))
#define           BIT(x, i)  ((x) >> (i) & 1)
#define  __builtin_popcount  __builtin_popcountll
#define              ALL(v)  (v).begin(), (v).end()
#define           REP(i, n)  for (int i = 0, _n = (n); i < _n; ++i)
#define          REPD(i, n)  for (int i = (n); i--; )
#define        FOR(i, a, b)  for (int i = (a), _b = (b); i < _b; ++i) 
#define       FORD(i, b, a)  for (int i = (b), _a = (a); --i >= _a; ) 
#define       FORE(i, a, b)  for (int i = (a), _b = (b); i <= _b; ++i) 
#define      FORDE(i, b, a)  for (int i = (b), _a = (a); i >= _a; --i) 
#define        scan_op(...)  istream & operator >> (istream &in, __VA_ARGS__ &u)
#define       print_op(...)  ostream & operator << (ostream &out, const __VA_ARGS__ &u)
#ifdef LOCAL
    #include "debug.h"
#else
    #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
    #define DB(...) 23
    #define db(...) 23
    #define debug(...) 23
#endif

template <class U, class V> scan_op(pair <U, V>)  { return in >> u.first >> u.second; }
template <class T> scan_op(vector <T>)  { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; }
template <class U, class V> print_op(pair <U, V>)  { return out << '(' << u.first << ", " << u.second << ')'; }
template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")";  else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); }
template <class ...U> print_op(tuple<U...>) { return print_tuple_utils<0, tuple<U...>>(out, u); }
template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream&>::type operator << (ostream &out, const Con &con) { out << '{'; for (__typeof(con.begin()) it = con.begin(); it != con.end(); ++it) out << (it == con.begin() ? "" : ", ") << *it; return out << '}'; }

inline char gc() { // like getchar()
    static char buf[1 << 16];
    static size_t bc, be;
    if (bc >= be) {
        buf[0] = 0, bc = 0;
        be = fread(buf, 1, sizeof(buf), stdin);
    }
    return buf[bc++]; // returns 0 on EOF
}

int readInt() {
    int a, c;
    while ((a = gc()) < 40);
    if (a == '-') return -readInt();
    while ((c = gc()) >= 48) a = a * 10 + c - 480;
    return a - 48;
}

// end of template

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int style(int H, int W, int R[500][500], int G[500][500], int B[500][500]) {
    int sum1 = 0, sum2 = 0;
    auto diff = [&] (int x, int y, int u, int v) {
        return abs(R[x][y] - R[u][v]) + abs(G[x][y] - G[u][v]) + abs(B[x][y] - B[u][v]);
    };
    int sum_r = 0, sum_g = 0, sum_b = 0;
    int adj_r = 0, adj_g = 0, adj_b = 0;
    REP(i, H) REP(j, W) {
        sum_r += R[i][j];
        sum_g += G[i][j];
        sum_b += B[i][j];
        if (j + 1 < W) {
            sum1 += diff(i, j, i, j + 1);
            adj_r += abs(R[i][j] - R[i][j + 1]);
            adj_g += abs(G[i][j] - G[i][j + 1]);
            adj_b += abs(B[i][j] - B[i][j + 1]);
        }
        if (i + 1 < H) {
            sum2 += diff(i, j, i + 1, j);
            adj_r += abs(R[i][j] - R[i + 1][j]);
            adj_g += abs(G[i][j] - G[i + 1][j]);
            adj_b += abs(B[i][j] - B[i + 1][j]);
        }
    }
    sum_r /= H * W;
    sum_g /= H * W;
    sum_b /= H * W;
    adj_r /= H * W;
    adj_g /= H * W;
    adj_b /= H * W;
    sum1 /= H * (W - 1);
    sum2 /= (H - 1) * W;
    if (sum1 <= 8 && sum2 <= 9 && min({adj_r, adj_g, adj_b}) <= 6) return 4;
    if (sum1 + sum2 >= 100 && max({adj_r, adj_g, adj_b}) >= 36) return 3;
    if (max({sum_r, sum_g, sum_b}) >= 131) return 1;
    return 2;
}

#ifdef LOCAL
#include <stdio.h>
#include "artclass.h"

static int H, W;
static int R[500][500];
static int G[500][500];
static int B[500][500];

int main() {
    freopen("artclass.out", "w", stdout);
    FOR(t, 1, 5) {
        FOR(i, 1, 10) {
            freopen(("style-" + to_string(t) + "-" + to_string(i) + ".txt").c_str(), "r", stdin);
            H = readInt(); W = readInt();
            REP(i, H) REP(j, W) {
                R[i][j] = readInt();
                G[i][j] = readInt();
                B[i][j] = readInt();
            }
            int x = style(H, W, R, G, B);
            if (x != t) cerr << t << ' ' << i << ": " << x << '\n';
        }
        cout << '\n' << string(20, '=') << '\n';
    }
    return 0;
}
#endif
#Verdict Execution timeMemoryGrader output
Fetching results...