Submission #295423

#TimeUsernameProblemLanguageResultExecution timeMemory
295423humbertoyustaRectangles (IOI19_rect)C++14
50 / 100
2134 ms605648 KiB
#include "rect.h" #include<bits/stdc++.h> #pragma GCC optimize ("Ofast") 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> int vx[202][202][202], vy[202][202][202]; 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{ if( n <= 200 && m <= 200 ){ for(int i=1; i<n-1; i++){ for(int j=1; j<m-1; j++){ int mx = A[i][j]; for(int k=j; k<m-1; k++){ if( A[i][k] > mx ) mx = A[i][k]; vx[i][j][k] = ( mx < A[i][j-1] && mx < A[i][k+1] ); if( vx[i][j][k] ){ vx[i][j][k] = vx[i][j][k] + vx[i-1][j][k]; } } } } for(int i=1; i<m-1; i++){ for(int j=1; j<n-1; j++){ int mx = A[j][i]; for(int k=j; k<n-1; k++){ if( A[k][i] > mx ) mx = A[k][i]; vy[i][j][k] = ( mx < A[j-1][i] && mx < A[k+1][i] ); if( vy[i][j][k] ) vy[i][j][k] += vy[i-1][j][k]; } } } for(int i=1; i<n-1; i++){ for(int j=i; j<n-1; j++){ for(int k=1; k<m-1; k++){ for(int l=k; l<m-1; l++){ if( j - vx[j][k][l] < i && l - vy[l][i][j] < k ){ 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...