Submission #261402

#TimeUsernameProblemLanguageResultExecution timeMemory
261402SuperJavaRectangles (IOI19_rect)C++17
27 / 100
5049 ms85496 KiB
#include "rect.h" #include <vector> #include <cmath> #include <iostream> #define sz(a) (a.size()) using namespace std; int spr[705][10][705]; int spc[705][10][705]; int lg[705]; int query_r(int row, int l, int r){ int logo = lg[r-l+1]; return max(spr[row][logo][l],spr[row][logo][r-(1<<logo)+1]); } int query_c(int col, int l, int r){ int logo = lg[r-l+1]; return max(spc[col][logo][l],spc[col][logo][r-(1<<logo)+1]); } long long count_rectangles(vector<vector<int>> a) { for (int i = 1; i < 705; ++i){ lg[i] = log2(i); } int n = sz(a); int m = sz(a[0]); int answer = 0; for (int i = 0; i < n; ++i){ for (int j = 0; j < m; ++j){ spr[i][0][j] = a[i][j]; } for (int k = 1; k < 10; ++k){ for (int j = 0; j < m-(1<<k)+1; ++j){ spr[i][k][j] = max(spr[i][k-1][j], spr[i][k-1][j+(1<<(k-1))]); } } } for (int i = 0; i < m; ++i){ for (int j = 0; j < n; ++j){ spc[i][0][j] = a[j][i]; } for (int k = 1; k < 10; ++k){ for (int j = 0; j < n-(1<<k)+1; ++j){ spc[i][k][j] = max(spc[i][k-1][j], spc[i][k-1][j+(1<<(k-1))]); } } } for (int r1 = 1; r1 < n-1; ++r1){ for (int c1 = 1; c1 < m-1; ++c1){ for (int r2 = r1; r2 < n-1; ++r2){ if(a[r2][c1] >= a[r2][c1-1] || a[r2][c1] >= a[r1-1][c1]){ break; } bool milhem = false; for (int c2 = c1; c2 < m-1 && !milhem; ++c2){ bool good = true; for (int i = r1; i <= r2 && good; ++i){ int mx = query_r(i, c1, c2); if(mx >= a[i][c1-1]){ good = false; milhem = true; } if(mx >= a[i][c2+1]){ good = false; } } for (int i = c1; i <= c2 && good; ++i){ int mx = query_c(i, r1, r2); if(mx >= a[r1-1][i] || mx >= a[r2+1][i]){ good = false; milhem = true; } } if(good){ answer++; } } } } } return answer; }
#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...