Submission #207357

#TimeUsernameProblemLanguageResultExecution timeMemory
207357balbitRectangles (IOI19_rect)C++14
13 / 100
541 ms261240 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define SZ(x) (int)((x).size())
#define ALL(x) x.begin(),x.end()

#define pii pair<int, int>
#define f first
#define s second

#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<" = ", _do(__VA_ARGS__)
template<typename T> void _do(T &&x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S&&...y) {cerr<<x<<", "; _do(y...);}
#define IOS()
#else
#define IOS() ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define bug(...)
#endif // BALBIT

const int MX = 100000000;


#define REP(i,n) for (int i = 0; i<n; ++i)
#define RREP(i,n) for (int i = n-1; i>=0; --i)
#define FOR(i,a,b) for (int i = a; i<b; i++)

vector<vector<int> > g;
int n,m;

bool bad = 0;
int cnt = 0;
int r1=MX, r2=0, c1=MX, c2=0;
int dx [] = {1,0,-1,0};
int dy [] = {0,1,0,-1};
inline bool ig(int r, int c) {
    return r>=0 && c>=0 && r<n && c<m;
}
void dfs(int r, int c) {
    g[r][c] =1;
    if (r == 0 || c == 0 || r== n-1 || c == m-1) bad = 1;
    r1 = min(r1, r);
    c1 = min(c1, c);
    r2 = max(r2,r);
    c2 = max(c2,c);
    ++cnt;
    REP(i,4) {
        if (ig(r+dx[i], c+dy[i]) && !g [r+dx[i]] [ c+dy[i]]) {
            dfs(r+dx[i], c+dy[i]);
        }
    }
}

ll count_rectangles(vector<vector<int> > a) {
     n = SZ(a);
     m = SZ(a[0]);
    g = a;
    ll re = 0;
    REP(i,n) REP(j,m){
        if (!g[i][j]) {
            bad = cnt = 0;
            r1=MX, r2=0, c1=MX, c2=0;
            dfs(i,j);
            if (!bad && (r2-r1+1) * (c2-c1+1) == cnt) {
                ++re;
            }
        }
    }
    return re;
}

#ifdef BALBIT
signed main(){
    IOS();
    ll ro = count_rectangles({{1,1,1,1},{1,0,0,1},{1,1,1,1}});
    bug(ro);
}
#endif

Compilation message (stderr)

rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:64:23: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
             bad = cnt = 0;
                   ~~~~^~~
#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...