제출 #294178

#제출 시각아이디문제언어결과실행 시간메모리
294178humbertoyustaRectangles (IOI19_rect)C++14
23 / 100
750 ms617416 KiB
#include "rect.h" #include<bits/stdc++.h> using namespace std; //#define int long long #define maxn 2505 #define f first #define s second #define db(x) cerr << #x << ": " << (x) << '\n'; #define ll long long #define ii pair<int,int> map<pair<ii,ii>,bool> mp; ll ans; int valid[maxn][maxn], valend[maxn][maxn], mnx, mny, mxx, mxy, cnt; bool valbgn[maxn][maxn], mk[maxn][maxn]; int n, m, A[maxn][maxn]; void dfs(int i,int j){ mnx = min( mnx , i ); mxx = max( mxx , i ); mny = min( mny , j ); mxy = max( mxy , j ); cnt++; mk[i][j] = 1; if( i + 1 <= n - 1 && A[i+1][j] == 0 && !mk[i+1][j] ) dfs(i+1,j); if( i - 1 >= 0 && A[i-1][j] == 0 && !mk[i-1][j] ) dfs(i-1,j); if( j + 1 <= m - 1 && A[i][j+1] == 0 && !mk[i][j+1] ) dfs(i,j+1); if( j - 1 >= 0 && A[i][j-1] == 0 && !mk[i][j-1] ) dfs(i,j-1); } ll f(int x){ for(int i=0; i<n; i++) for(int j=0; j<m; j++) valid[i][j] = valend[i][j] = valbgn[i][j] = 0; for(int i=1; i<n-1; i++){ int mx = A[i][x]; valend[i][x-1] = 1 + i; valbgn[i][x-1] = 1; for(int j=x; j<m-1; j++){ if( A[i][j] > mx ) mx = A[i][j]; valid[i][j] = ( mx < A[i][x-1] && mx < A[i][j+1] ); valend[i][j] = ( ( ( valend[i][j-1] - valend[i-1][j-1] ) != 0 ) && A[i][j] < A[i-1][j] ); valbgn[i][j] = ( valbgn[i][j-1] && A[i][j] < A[i+1][j] ); if( valid[i][j] ) valid[i][j] += valid[i-1][j]; valend[i][j] += valend[i-1][j]; } } ll res = 0; for(int j=x; j<m-1; j++){ for(int i=1; i<n-1; i++){ if( valbgn[i][j] ){ int k = i - valid[i][j]; res += valend[i][j] - valend[k][j]; //if( valend[i][j] - valend[k][j] ){ // db(x)db(j) // db(i)db(k) // db(valend[i][j] - valend[k][j]) //} } } } return res; } long long count_rectangles(std::vector<std::vector<int> > a) { n = a.size(); m = a[0].size(); int maximum = 0; for(int i=0; i<n; i++) for(int j=0; j<m; j++){ A[i][j] = a[i][j]; maximum = max( maximum , A[i][j] ); } if( maximum <= 1 ){ for(int i=1; i<n-1; i++) for(int j=1; j<m-1; j++) if( !mk[i][j] && A[i][j] == 0 ){ mnx = i; mxx = i; mny = j; mxy = j; cnt = 0; dfs(i,j); if( ( mxx - mnx + 1 ) * ( mxy - mny + 1 ) == cnt ){ if( mnx >= 1 && mxx <= n - 2 && mny >= 1 && mxy <= m - 2 ){ ans ++; } } } } else{ for(int i=1; i<m-1; i++) ans += f(i); } return ans; }
#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...