제출 #226181

#제출 시각아이디문제언어결과실행 시간메모리
226181AaronNaiduRectangles (IOI19_rect)C++14
0 / 100
5 ms512 KiB
#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; int prefSums[3000][3000]; 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[endx+1][y] or board[x][y] >= board[x][starty-1] or board[x][y] >= board[x][endy+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; prefSums[0][0] = board[0][0]; for (int i = 1; i < n; i++) { prefSums[i][0] = prefSums[i-1][0] + board[i][0]; } for (int i = 1; i < m; i++) { prefSums[0][i] = prefSums[0][i-1] + board[0][i]; } for (int i = 1; i < n; i++) { for (int j = 1; j < m; j++) { prefSums[i][j] = prefSums[i][j-1] + prefSums[i-1][j] - prefSums[i-1][j-1] + board[i][j]; } } ll totalCount = 0; for (int i = 1; i < n-1; i++) { for (int j = 1; j < m-1; j++) { if (board[i][j] == 0) { int endx = i; int endy = j; while (endx < n-2 and board[endx+1][endy] == 0) { endx++; } while (endy < m-2 and prefSums[endx][endy+1] - prefSums[i-1][endy+1] - prefSums[endx][j-1] + prefSums[i-1][j-1] == 0) { endy++; } int totSum = prefSums[endx+1][endy+1]; if (i > 1) { totSum -= prefSums[i-2][endy+1]; } if (j > 1) { totSum -= prefSums[endx+1][j-2]; } if (i > 1 and j > 1) { totSum += prefSums[i-2][j-2]; } if (totSum == 2 * (endx - i + 2 + endy - j + 2)) { totalCount++; } for (int x = i; x <= endx; x++) { for (int y = j; y <= endy; y++) { board[i][j] = 1; } } } } } return totalCount; }
#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...