Submission #597989

#TimeUsernameProblemLanguageResultExecution timeMemory
597989JohannRectangles (IOI19_rect)C++14
38 / 100
5050 ms85196 KiB
// sub1+2 sub5+6 #include "bits/stdc++.h" using namespace std; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpii; typedef vector<vi> vvi; typedef long long ll; #define sz(x) (int) (x).size() #define all(x) (x).begin(), (x).end() int n, m; int conv(int i, int j) { return i * m + j; } pii conv(int i) { return {i / m, i % m}; } bool inRange(int i, int j) { return 0 <= i && i < n && 0 <= j && j < m; } vpii dirs = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; vvi A; bool done[2505 * 2505] = {false}; ll ans; bool check(int x, int y, int w, int h) { for (int row = y; row <= y + h; ++row) { int maxi = 0; for (int col = x; col <= x + w; ++col) maxi = max(maxi, A[row][col]); if (maxi >= min(A[row][x-1], A[row][x+w+1])) return false; } for (int col = x; col <= x + w; ++col) { int maxi = 0; for (int row = y; row <= y + h; ++row) maxi = max(maxi, A[row][col]); if (maxi >= min(A[y-1][col], A[y+h+1][col])) return false; } return true; } ll count_rectangles(vvi a) { n = sz(a), m = (sz(a[0])); A.assign(n, vi(m)); for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) A[i][j] = a[i][j]; for (int y = 1; y < n - 1; ++y) { for (int x = 1; x < m - 1; ++x) { if (!(a[y - 1][x] > a[y][x] && a[y][x - 1] > a[y][x])) continue; for (int h = 0; y + h < n - 1; ++h) { if (!(a[y + h][x - 1] > a[y + h][x])) break; for (int w = 0; x + w < m - 1; ++w) { if (!(a[y - 1][x + w] > a[y][x + w])) break; if (check(x, y, w, h)) { ++ans; // printf("y%d x%d w%d h%d\n", y, x, w, h); } } } } } return ans; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...