이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "rect.h"
#pragma GCC optimize("O3")
using namespace std;
const int N = 2500, M = 2500;
int n, m;
long long sol;
int f[N][M], dx[]={0,1,0,-1}, dy[]={1,0,-1,0};
void st5(){
for(int i = 1, mx; i < m-1; i++){
mx = 0;
for(int j = i; j < m-1; j++){
mx = max(mx, f[1][j]);
if(f[1][j] >= f[1][i-1] || f[1][j] >= f[0][j] || f[1][j] >= f[2][j]) break;
if(mx < f[1][j+1]) sol++;
}
}
}
int vis[N][M];
void flood(int x, int y, int &maxx, int &maxy, int &minx, int &miny, int &c){
if(x < 0 || y < 0 || x == n || y == m || vis[x][y] || f[x][y]) return;
c++;
vis[x][y] = 1;
maxx = max(maxx, x), minx = min(minx, x);
maxy = max(maxy, y), miny = min(miny, y);
for(int k = 0, i, j; k < 4; k++){
i = x+dx[k], j = y+dy[k];
flood(i, j, maxx, maxy, minx, miny, c);
}
}
void st6(){
for(int i = 1; i < n-1; i++){
for(int j = 1; j < m-1; j++){
if(vis[i][j] || f[i][j]) continue;
int maxx = i, minx = i, maxy = j, miny = j, c = 0;
flood(i, j, maxx, maxy, minx, miny, c);
if(minx && miny && maxx < n-1 && maxy < m-1 && c == (maxx-minx+1)*(maxy-miny+1)) sol++;
}
}
}
long long count_rectangles(vector< vector<int> > a){
n = a.size(), m = a[0].size();
if(n < 3 || m < 3) return 0;
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
f[i][j] = a[i][j];
if(n == 3) st5();
else st6();
return sol;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |