Submission #991544

# Submission time Handle Problem Language Result Execution time Memory
991544 2024-06-02T11:56:14 Z MarwenElarbi Rectangles (IOI19_rect) C++17
0 / 100
94 ms 37152 KB
#include<bits/stdc++.h>
#include <cstdio>
#include <unistd.h>
#include <cassert>
#include <string>
using namespace std;
#define fi first
#define se second
#define ll long long
#define pb push_back
const int nax=2505;
vector<vector<int>> grid;
int arx[4]={1,-1,0,0};
int ary[4]={0,0,-1,1};
ll mxx,mxy,mnx,mny;
bool vis[2505][2505];
int N,M;
bool test(int x,int y){
    if(x<=0||y<=0||x>=N||y>=M||grid[x][y]==1||vis[x][y]) return true;
    else return false;
}
void dfs(ll x,ll y){
    //cout <<x<<" "<<y<<endl;
    vis[x][y]=true;
    mxx=max(mxx,x);
    mxy=max(mxy,y);
    mnx=min(mnx,x);
    mny=min(mny,y);
    for (int i = 0; i < 4; ++i)
    {
        int curx=arx[i];
        int cury=ary[i];
        if(!test(curx+x,cury+y)){
            dfs(curx+x,cury+y);
        }
    }
}
long long count_rectangles(std::vector<std::vector<int> > a) {
    grid=a;
    int n=a.size();
    int m=a[0].size();
    N=n;
    M=m;
    if(n<=2||m<=2) return 0;
    ll ans=0;
    for (int i = 1; i < n-1; ++i)
    {
        for (int j = 1; j < m-1; ++j)
        {
            if(vis[i][j]) continue;
            else if(grid[i][j]==1) continue;
            //cout <<i<<" "<<j<<" "<<endl;
            vis[i][j]=true;
            mxx=mxy=0;
            mnx=mny=max(n,m);
            dfs(i,j);
            bool nabba=true;
            for (int x = mnx; x <= mxx; ++x)
            {
                for (int y = mny; y <= mxy; ++y)
                {
                    if(grid[x][y]==1) nabba=false;
                    if(!nabba) break;
                }
                if(!nabba) break;
            }
            if(!nabba) continue;
            if(mnx<=0||mny<=0||mxx>=n-1||mxy>=m-1) continue;
            ans+=1ll*(1ll*(mxx-mnx+1)*(mxx-mnx+2)/2)*(1ll*(mxy-mny+1)*(mxy-mny+2)/2); 
            //cout <<mnx<<" "<<mxx<<" "<<mny<<" "<<mxy<<endl;
        }
    }
    return ans;
}

# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 732 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 94 ms 37152 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -