Submission #160618

#TimeUsernameProblemLanguageResultExecution timeMemory
160618eggag32Rectangles (IOI19_rect)C++17
27 / 100
5046 ms1048576 KiB
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include <bits/stdc++.h> #include "rect.h" //#include "grader.cpp" using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef pair<int, int> pi; #define debug(x) cerr << #x << ": " << x << endl; #define debug2(x, y) debug(x) debug(y); #define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++) #define rep(i, a) for(int i = 0; i < (int)(a); i++) #define all(v) v.begin(), v.end() #define mp make_pair #define pb push_back #define lb lower_bound #define ub upper_bound #define fi first #define se second #define sq(x) ((x) * (x)) template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); } bool ver[705][705][705]; bool hor[705][705][705]; ll count_rectangles(vector<vi> a){ int n = a.size(); int m = a[0].size(); memset(ver, 0, sizeof(ver)); memset(hor, 0, sizeof(hor)); repn(i, 1, n - 1){ int hor1[705][705]; memset(hor1, 0, sizeof(hor1)); repn(j, 1, m - 1) repn(k, j, m - 1){ if(j == k){ hor1[j][k] = a[i][j]; if(hor1[j][k] < a[i][j - 1] && hor1[j][k] < a[i][k + 1]) hor[i][j][k] = 1; } else{ hor1[j][k] = max(hor1[j][k - 1], a[i][k]); if(hor1[j][k] < a[i][j - 1] && hor1[j][k] < a[i][k + 1]) hor[i][j][k] = 1; } } } repn(j, 1, m - 1){ int ver1[705][705]; memset(ver1, 0, sizeof(ver1)); repn(i, 1, n - 1) repn(k, i, n - 1){ if(i == k){ ver1[i][k] = a[i][j]; if(ver1[i][k] < a[i - 1][j] && ver1[i][k] < a[k + 1][j]) ver[j][i][k] = 1; } else{ ver1[i][k] = max(ver1[i][k - 1], a[k][j]); if(ver1[i][k] < a[i - 1][j] && ver1[i][k] < a[k + 1][j]) ver[j][i][k] = 1; } } } ll ans = 0; repn(i, 1, n - 1) repn(j, 1, m - 1) repn(k, i, n - 1) repn(l, j, m - 1){ int f = 1; repn(x, i, k + 1){ if(!hor[x][j][l] || !hor[x][j][l]){ f = 0; break; } } if(!f) continue; repn(x, j, l + 1){ if(!ver[x][i][k] || !ver[x][i][k]){ f = 0; break; } } if(!f) continue; ans++; } return ans; } /* Things to look out for: - Integer overflows - Array bounds - Special cases Be careful! */
#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...