Submission #416867

#TimeUsernameProblemLanguageResultExecution timeMemory
416867Theo830Rectangles (IOI19_rect)C++17
25 / 100
5046 ms1048580 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e9+7; ll MOD = 998244353; typedef pair<ll,ll> ii; #define iii pair<ll,ii> #define f(i,a,b) for(ll i = a;i < b;i++) #define pb push_back #define vll vector<ll> #define F first #define S second #define all(x) (x).begin(), (x).end() ///I hope I will get uprating and don't make mistakes ///I will never stop programming ///sqrt(-1) Love C++ ///Please don't hack me ///@TheofanisOrfanou Theo830 ///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst) ///Stay Calm ///Look for special cases ///Beware of overflow and array bounds ///Think the problem backwards ///Training mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<ll> distr; ll rnd(ll a, ll b){return distr(rng)%(b-a+1)+a;} #include "rect.h" /* long long count_rectangles(std::vector<std::vector<int> > a); int main() { int n, m; cin>>n>>m; vector<vector<int>> a(n, vector<int>(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin>>a[i][j]; } } long long result = count_rectangles(a); printf("%lld\n", result); return 0; } */ long long count_rectangles(vector<vector<int> > a){ ll ans = 0; ll n = a.size(); ll m = a[0].size(); ll Maxi[n][m][m]; ll maxi[m][n][n]; f(i,1,n-1){ f(j,1,m-1){ Maxi[i][j][j] = a[i][j]; f(k,j+1,m-1){ Maxi[i][j][k] = max(Maxi[i][j][k-1],1LL * a[i][k]); } } } f(i,1,m-1){ f(j,1,n-1){ maxi[i][j][j] = a[j][i]; f(k,j+1,n-1){ maxi[i][j][k] = max(maxi[i][j][k-1],1LL * a[k][i]); } } } f(i,1,n-1){ f(j,1,m-1){ f(ii,i,n-1){ f(jj,j,m-1){ bool ok = 1; f(k,i,ii+1){ ok &= (Maxi[k][j][jj] < min(a[k][j-1],a[k][jj+1])); } f(k,j,jj+1){ ok &= (maxi[k][i][ii] < min(a[i-1][k],a[ii+1][k])); } ans += ok; } } } } return ans; } /* 6 5 4 8 7 5 6 7 4 10 3 5 9 7 20 14 2 9 14 7 3 6 5 7 5 2 7 4 5 13 5 6 */
#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...