Submission #941446

#TimeUsernameProblemLanguageResultExecution timeMemory
941446Programmer123Rectangles (IOI19_rect)C++17
37 / 100
5093 ms61264 KiB
#include "rect.h" long long count_rectangles(std::vector<std::vector<int> > a) { int N = a.size(); int M = a[0].size(); long long ans = 0; if (N == 3) { bool works[M]; works[0] = false; works[M - 1] = false; for (int i = 1; i < M - 1; ++i) { works[i] = a[1][i] < a[0][i] && a[1][i] < a[2][i]; } for (int l = 1; l < M - 1; ++l) { if (!works[l]) continue; int max = a[1][l]; for (int r = l; r < M - 1; ++r) { if (!works[r]) break; max = std::max(max, a[1][r]); if (max >= a[1][l - 1]) break; if (max >= a[1][r + 1]) continue; ans++; } } return ans; } int max[N]; for (int u = 1; u < N - 1; ++u) { int maxc[M]; for (int i = 0; i < M; ++i) { maxc[i] = a[u][i]; } for (int d = u; d < N - 1; ++d) { for (int i = 0; i < M; ++i) { maxc[i] = std::max(maxc[i], a[d][i]); } bool works[M]; for (int i = 0; i < M; ++i) { works[i] = maxc[i] < a[u - 1][i] && maxc[i] < a[d + 1][i]; } for (int l = 1; l < M - 1; ++l) { if (!works[l]) continue; for (int i = u; i <= d; ++i) { max[i] = a[i][l]; } for (int r = l; r < M - 1; ++r) { if (!works[r]) break; for (int i = u; i <= d; ++i) { max[i] = std::max(max[i], a[i][r]); } for (int i = u; i <= d; ++i) { if (max[i] >= a[i][l - 1]) goto dead; } for (int i = u; i <= d; ++i) { if (max[i] >= a[i][r + 1]) goto next; } ans++; next:; } dead:; } } } 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...