Submission #292564

#TimeUsernameProblemLanguageResultExecution timeMemory
292564miss_robotRectangles (IOI19_rect)C++14
37 / 100
5096 ms41336 KiB
#include <bits/stdc++.h> #include "rect.h" #pragma GCC optimize("O3") using namespace std; const int N = 700, M = 700, L = 1024; int n, m; long long sol; int f[2500][2500], dx[]={0,1,0,-1}, dy[]={1,0,-1,0}, up[N][2*L], dwn[N][M], lft[M][N], rgt[M][N]; int qry(int a, int b, int t[]){ a += L, b += L; int r = 7e6; while(a <= b){ if(a&1) r = min(r, t[a++]); if(!(b&1)) r = min(r, t[b--]); a >>= 1, b >>= 1; } return r; } void st1(){ for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ for(int k = j+1; k < m; k++){ if(f[i][k] < f[i][j]) rgt[j][i]++; else break; } for(int k = j-1; k >= 0; k--){ if(f[i][k] < f[i][j]) lft[j][i]++; else break; } for(int k = i+1; k < n; k++){ if(f[k][j] < f[i][j]) dwn[i][j]++; else break; } for(int k = i-1; k >= 0; k--){ if(f[k][j] < f[i][j]) up[i][j+L]++; else break; } } } for(int i = 0; i < n; i++) for(int j = L-1; j; j--) up[i][j] = min(up[i][j<<1], up[i][(j<<1)|1]); for(int x = 0; x < n-2; x++){ for(int y = 1; y < m-1; y++){ int mxlen = N; for(int Y = y; Y < m-1; Y++){ mxlen = min(mxlen, dwn[x][Y]); int last = x+mxlen; for(int X = x+1; X <= last && X < n-1; X++){ if(rgt[y-1][X] < Y-y+1 || lft[Y+1][X] < Y-y+1){ last = X-1; break; } if(qry(y, Y, up[X+1]) >= X-x) sol++; else if(X == last) last--; } } } } } void st5(){ for(int i = 1, mx; i < m-1; i++){ mx = 0; for(int j = i; j < m-1; j++){ mx = max(mx, f[1][j]); if(f[1][j] >= f[1][i-1] || f[1][j] >= f[0][j] || f[1][j] >= f[2][j]) break; if(mx < f[1][j+1]) sol++; } } } int vis[N][M]; void flood(int x, int y, int &maxx, int &maxy, int &minx, int &miny, int &c){ if(x < 0 || y < 0 || x == n || y == m || vis[x][y] || f[x][y]) return; c++; vis[x][y] = 1; maxx = max(maxx, x), minx = min(minx, x); maxy = max(maxy, y), miny = min(miny, y); for(int k = 0, i, j; k < 4; k++){ i = x+dx[k], j = y+dy[k]; flood(i, j, maxx, maxy, minx, miny, c); } } void st6(){ for(int i = 1; i < n-1; i++){ for(int j = 1; j < m-1; j++){ if(vis[i][j] || f[i][j]) continue; int maxx = i, minx = i, maxy = j, miny = j, c = 0; flood(i, j, maxx, maxy, minx, miny, c); if(minx && miny && maxx < n-1 && maxy < m-1 && c == (maxx-minx+1)*(maxy-miny+1)) sol++; } } } long long count_rectangles(vector< vector<int> > a){ n = a.size(), m = a[0].size(); if(n < 3 || m < 3) return 0; for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) f[i][j] = a[i][j]; int s6 = 1; for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) if(f[i][j] > 1) s6 = 0; if(n == 3) st5(); else if(s6) st6(); else st1(); return sol; }
#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...