이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int c=2502;
bool v[c][c], t[c][c];
int n, m, ans, ks, ko, ns, no, db;
void dfs(int a, int b) {
v[a][b]=true, db++;
ks=min(ks, a), ko=min(ko, b), ns=max(ns, a), no=max(no, b);
if (a>0 && !v[a-1][b] && !t[a-1][b]) dfs(a-1, b);
if (b>0 && !v[1][b-1] && !t[a][b-1]) dfs(a, b-1);
if (a+1<n && !v[a+1][b] && !t[a+1][b]) dfs(a+1, b);
if (b+1<m && !v[a][b+1] && !t[a][b+1]) dfs(a, b+1);
}
long long count_rectangles(vector<vector<int>> sz) {
n=sz.size(), m=sz[0].size();
for (int i=0; i<n; i++) for (int j=0; j<m; j++) t[i][j]=sz[i][j];
for (int i=0; i<n; i++) for (int j=0; j<m; j++) {
if (!v[i][j] && !sz[i][j]) {
ns=0, no=0, ks=c, ko=c, db=0;
dfs(i, j);
if (ks>0 && ko>0 && ns<n-1 && no<m-1 && (ns-ks+1)*(no-ko+1)==db) ans++;
}
}
return ans;
}
/*
int b1, b2;
vector<vector<int>> b3;
int main()
{
cin >> b1 >> b2;
b3.resize(b1);
for (int i=0; i<b1; i++) for (int j=0; j<b2; j++) {
int x; cin >> x;
b3[i].push_back(x);
}
cout << count_rectangles(b3);
return 0;
}
*/
# | 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... |