Submission #340136

#TimeUsernameProblemLanguageResultExecution timeMemory
340136shrek12357Rectangles (IOI19_rect)C++14
37 / 100
5051 ms40556 KiB
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <map> #include <set> #include <climits> #include <cmath> #include <fstream> #include <queue> #include <stack> #include <bitset> #include "rect.h" using namespace std; #define ll long long //cin.tie(0);ios_base::sync_with_stdio(0); const int MAXN = 2505; int grid[MAXN][MAXN]; int n, m; ll ans1() { if (n == 1 || n == 2) { return 0; } int cnt = 0; for (int i = 1; i < m - 1; i++) { int cur = grid[1][i - 1]; int mx = grid[1][i]; for (int j = i; j < m - 1; j++) { mx = max(mx, grid[1][j]); if (grid[1][j] >= cur || grid[1][j] >= grid[0][j] || grid[1][j] >= grid[2][j]) { break; } if (grid[1][j] >= grid[1][j + 1] || mx >= cur || mx >= grid[1][j + 1]) { continue; } cnt++; } } return cnt; } ll ans2() { ll cnt = 0; for (int i = 1; i < n - 1; i++) { for (int j = 1; j < m - 1; j++) { for (int k = i; k < n - 1; k++) { for (int l = j; l < m - 1; l++) { bool bad = false; for (int a = i; a <= k; a++) { for (int b = j; b <= l; b++) { if (grid[a][b] >= grid[i - 1][b] || grid[a][b] >= grid[k + 1][b] || grid[a][b] >= grid[a][j - 1] || grid[a][b] >= grid[a][l + 1]) { bad = true; break; } } if (bad) { break; } } if (!bad) { cnt++; } } } } } return cnt; } ll count_rectangles(vector<vector<int>> a) { n = a.size(); m = a[0].size(); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { grid[i][j] = a[i][j]; } } if (n <= 3) { return ans1(); } return ans2(); }
#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...