Submission #603367

#TimeUsernameProblemLanguageResultExecution timeMemory
603367SeDunionRectangles (IOI19_rect)C++17
27 / 100
671 ms111048 KiB
#include "rect.h" #include<iostream> #include<vector> using namespace std; using ll = long long; const int N = 202; int gr[N][N][N]; int gc[N][N][N]; ll count_rectangles(vector<vector<int>>a) { int n = a.size(), m = a[0].size(); ll ans = 0; for (int r = 1 ; r < n - 1 ; ++ r) { for (int c1 = 1 ; c1 < m - 1 ; ++ c1) { int mx = 0; for (int c2 = c1 ; c2 < m - 1 ; ++ c2) { mx = max(mx, a[r][c2]); if (mx < a[r][c1 - 1] && mx < a[r][c2 + 1]) { gr[r][c1][c2] = 1; } } } } for (int c = 1 ; c < m - 1 ; ++ c) { for (int r1 = 1 ; r1 < n - 1 ; ++ r1) { int mx = 0; for (int r2 = r1 ; r2 < n - 1 ; ++ r2) { mx = max(mx, a[r2][c]); if (mx < a[r1 - 1][c] && mx < a[r2 + 1][c]) { gc[c][r1][r2] = 1; } } } } for (int r = 1 ; r < n - 1 ; ++ r) { for (int c1 = 1 ; c1 < m - 1 ; ++ c1) { for (int c2 = c1 ; c2 < m - 1 ; ++ c2) { gr[r][c1][c2] += gr[r-1][c1][c2]; } } } for (int c = 1 ; c < m - 1 ; ++ c) { for (int r1 = 1 ; r1 < n - 1 ; ++ r1) { for (int r2 = r1 ; r2 < n - 1 ; ++ r2) { gc[c][r1][r2] += gc[c-1][r1][r2]; } } } for (int r1 = 1 ; r1 < n - 1 ; ++ r1) { for (int r2 = r1 ; r2 < n - 1 ; ++ r2) { for (int c1 = 1 ; c1 < m - 1 ; ++ c1) { for (int c2 = c1 ; c2 < m - 1; ++ c2) { int sr = gr[r2][c1][c2] - gr[r1-1][c1][c2]; int sc = gc[c2][r1][r2] - gc[c1-1][r1][r2]; if (sr == r2 - r1 + 1 && sc == c2 - c1 + 1) { ans++; } } } } } 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...