(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #390175

#TimeUsernameProblemLanguageResultExecution timeMemory
390175MilosMilutinovicQuality Of Living (IOI10_quality)C++14
100 / 100
3467 ms175372 KiB
/** * author: milos * created: 15.04.2021 12:47:15 **/ #include <bits/stdc++.h> #include "quality.h" using namespace std; int rectangle(int R, int C, int H, int W, int Q[3001][3001]) { vector<int> xs; for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { xs.push_back(Q[i][j]); } } auto InRect = [&](int x1, int x2, int y1, int y2, int x, int y) { return x1 <= x && x <= x2 && y1 <= y && y <= y2; }; auto Can = [&](int val) { int sum[R][C]; for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { sum[i][j] = (Q[i][j] <= val ? 1 : 0); if (i > 0) sum[i][j] += sum[i - 1][j]; if (j > 0) sum[i][j] += sum[i][j - 1]; if (i > 0 && j > 0) sum[i][j] -= sum[i - 1][j - 1]; } } int x = -1, y = -1; for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { if (Q[i][j] == val) { x = i; y = j; } } } assert(x != -1 && y != -1); int P = H * W; for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { int ii = i + H - 1, jj = j + W - 1; if (ii >= R || jj >= C) { continue; } int cnt = sum[ii][jj]; if (i > 0) cnt -= sum[i - 1][jj]; if (j > 0) cnt -= sum[ii][j - 1]; if (i > 0 && j > 0) cnt += sum[i - 1][j - 1]; if (cnt >= P / 2 + 1) { return true; } } } return false; }; sort(xs.begin(), xs.end()); xs.erase(unique(xs.begin(), xs.end()), xs.end()); int bot = 0, top = (int) xs.size() - 1, ans = 1e9; while (bot <= top) { int mid = bot + top >> 1; if (Can(xs[mid])) { ans = xs[mid]; top = mid - 1; } else { bot = mid + 1; } } return ans; }

Compilation message (stderr)

quality.cpp: In function 'int rectangle(int, int, int, int, int (*)[3001])':
quality.cpp:61:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   61 |     int mid = bot + top >> 1;
      |               ~~~~^~~~~
quality.cpp:17:8: warning: variable 'InRect' set but not used [-Wunused-but-set-variable]
   17 |   auto InRect = [&](int x1, int x2, int y1, int y2, int x, int y) {
      |        ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...