Submission #754073

#TimeUsernameProblemLanguageResultExecution timeMemory
754073marvinthangArt Class (IOI13_artclass)C++17
98 / 100
81 ms3600 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]); }; REP(i, H) REP(j, W) { if (j + 1 < W) sum1 += diff(i, j, i, j + 1); if (i + 1 < H) sum2 += diff(i, j, i + 1, j); } sum1 /= H * (W - 1); sum2 /= (H - 1) * W; // if (sum1 < 9) return 4; // if (sum1 + sum2 >= 110) return 3; // cout << sum1 + sum2 << ' '; vector <vector <bool>> visited(H, vector<bool>(W)); int cnt = 0; REP(x, H) REP(y, W) if (!visited[x][y]) { ++cnt; queue <pair <int, int>> q; q.emplace(x, y); visited[x][y] = true; while (!q.empty()) { auto [x, y] = q.front(); q.pop(); REP(d, 4) { int u = x + dx[d], v = y + dy[d]; if (u < 0 || u >= H || v < 0 || v >= W || visited[u][v] || diff(x, y, u, v) > 60) continue; visited[u][v] = true; q.emplace(u, v); } } } long long f = cnt * 1000000LL / H / W; if (sum1 <= 10 && sum2 <= 10 && f <= 100) return 4; if (sum1 + sum2 >= 100 && f >= 70000) return 3; cnt = 0; visited = vector <vector<bool>>(H, vector<bool>(W)); REP(x, H) REP(y, W) if (!visited[x][y]) { ++cnt; queue <pair <int, int>> q; q.emplace(x, y); visited[x][y] = true; while (!q.empty()) { auto [x, y] = q.front(); q.pop(); REP(d, 4) { int u = x + dx[d], v = y + dy[d]; if (u < 0 || u >= H || v < 0 || v >= W || visited[u][v] || diff(x, y, u, v) > 10) continue; visited[u][v] = true; q.emplace(u, v); } } } f = cnt * 1000000LL / H / W; if (f >= 350000) return 2; return 1; } #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...