제출 #146627

#제출 시각아이디문제언어결과실행 시간메모리
146627BlagojceRectangles (IOI19_rect)C++14
13 / 100
719 ms505168 KiB
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
ll const inf = 1e9;
ll const mod = 1e9 + 7;
ld const eps = 1e-9;
#include "rect.h"

bool vis[2500][2500];
int n, m;

int lb, rb, ub, db;
int cnt = 0;
void flood_fill(int r, int c){
        cnt ++;
        lb = min(lb, c);
        rb = max(rb, c);
        ub = min(ub, r);
        db = max(db, r);
        vis[r][c] = true;
        if(r + 1 < n && !vis[r+ 1][c]){
                flood_fill(r + 1, c);
        }
        if(r - 1 >= 0 && !vis[r - 1][c]){
                flood_fill(r - 1, c);
        }
        if(c + 1 < m && !vis[r][c + 1]){
                flood_fill(r, c + 1);
        }
        if(c - 1 >= 0 && !vis[r][c - 1]){
                flood_fill(r, c - 1);
        }
}

long long count_rectangles(std::vector<std::vector<int> > a) {
        memset(vis, false, sizeof(vis));
        /*cin >> n >> m;
        a.resize(n);
        fr(i, 0, n){
                a[i].resize(m);
                fr(j, 0, m)cin >>a[i][j];
        }*/
        n = a.size();
        m = a[0].size();
        fr(i, 0, n){
                fr(j, 0, m){
                        if(a[i][j] == 1) vis[i][j] = true;
                }
        }

        int CNT = 0;
        fr(i, 1, n - 1){
                fr(j, 1, m - 1){
                        if(vis[i][j]) continue;
                        lb = m;
                        rb = -1;
                        ub = n;
                        db = -1;
                        cnt = 0;
                        flood_fill(i, j);
                        if(lb == 0 || rb == m - 1 || ub == 0 || db == n - 1){
                                continue;
                        }
                        if(cnt == (rb - lb + 1) * (db - ub + 1)){
                                CNT ++;
                        }


                }
        }
       // cout << CNT << endl;
        return CNT;


        /*int MAXr[n][m][m];
        fr(i, 0, n){
                fr(j, 0, m){
                        int MAX = 0;
                        fr(o, j, m){
                                MAX = max(MAX, a[i][o]);
                                MAXr[i][j][o] = MAX;
                        }
                }
        }
        int MAXc[m][n][n];
        fr(i, 0, m){
                fr(j, 0 ,n){
                        int MAX = 0;
                        fr(o, j, n){
                                MAX = max(MAX, a[o][i]);
                                MAXc[i][j][o] = MAX;
                        }
                }
        }

        bool ok = true;
        int CNT = 0;
        fr(i, 1, n){
                fr(j, 1, m){
                        fr(ri, i, n - 1){
                                fr(cj, j, m - 1){
                                        ok = true;
                                        fr(o, i, ri + 1){
                                                if(MAXr[o][j][cj] >= min(a[o][cj + 1], a[o][j - 1])){
                                                        ok = false;;
                                                        break;
                                                }
                                        }
                                        if(!ok) continue;
                                        fr(o, j, cj + 1){
                                                if(MAXc[o][i][ri] >= min(a[i - 1][o], a[ri + 1][o])){
                                                        ok = false;
                                                        break;
                                                }
                                        }
                                        if(ok)CNT ++;

                                }
                        }
                }
        }
        //cout << CNT << endl;
        return CNT;*/

}
/*
int main()
{
        count_rectangles({{1}});
        return 0;
}*/
/*
6 5
4 8 7 5 6
7 4 10 3 5
9 7 20 14 2
9 14 7 3 6
5 7 5 2 7
4 5 13 5 6
*/
#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...