# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
226169 | 2020-04-22T17:28:31 Z | AaronNaidu | Split the Attractions (IOI19_split) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n, m; vector<pair<int, int> > topLeft; vector<pair<int, int> > bottomRight; vector<vector<int> > board; bool works(int startx, int endx, int starty, int endy) { if (startx > endx or starty > endy) { return false; } for (int x = startx; x <= endx; x++) { for (int y = starty; y < endy; y++) { if (board[x][y] >= board[startx-1][y] or board[x][y] >= board[startx+1][y] or board[x][y] >= board[x][starty-1] or board[x][y] >= board[x][starty+1]) { return false; } } } //cout << startx << "," << starty << " to " << endx << "," << endy << "\n"; return true; } ll count_rectangles(vector<vector<int> > a) { n = a.size(); m = a[0].size(); board = a; for (int i = 1; i < n - 1; i++) { for (int j = 1; j < m - 1; j++) { if (a[i][j] < a[i-1][j] and a[i][j] < a[i][j-1]) { topLeft.push_back({i,j}); //cout << "Top left could be " << i << "," << j << "\n"; } if (a[i][j] < a[i+1][j] and a[i][j] < a[i][j+1]) { bottomRight.push_back({i,j}); //cout << "Bottom right could be " << i << "," << j << "\n"; } } } ll totalCount = 0; for (auto i : topLeft) { for (auto j : bottomRight) { totalCount += works(i.first,j.first, i.second, j.second); } } return totalCount; }