Submission #416886

# Submission time Handle Problem Language Result Execution time Memory
416886 2021-06-03T06:49:33 Z Theo830 Rectangles (IOI19_rect) C++17
37 / 100
3213 ms 1048580 KB
#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();
    bool ok1[n][m][m];
    bool ok2[m][n][n];
    memset(ok1,0,sizeof ok1);
    memset(ok2,0,sizeof ok2);
    f(i,1,n-1){
        f(j,1,m-1){
            ll Maxi = a[i][j];
            ok1[i][j][j] = min(a[i][j-1],a[i][j+1]) > Maxi;
            f(k,j+1,m-1){
                Maxi = max(Maxi,1LL * a[i][k]);
                ok1[i][j][k] = min(a[i][j-1],a[i][k+1]) > Maxi;
            }
        }
    }
    f(i,1,m-1){
        f(j,1,n-1){
            ll maxi = a[j][i];
            ok2[i][j][j] = min(a[j-1][i],a[j+1][i]) > maxi;
            f(k,j+1,n-1){
                maxi = max(maxi,1LL * a[k][i]);
                ok2[i][j][k] = min(a[j-1][i],a[k+1][i]) > maxi;
            }
        }
    }
    ll pre1[m][m][n+1];
    memset(pre1,0,sizeof pre1);
    f(j,1,m-1){
        f(jj,j,m-1){
            f(k,0,n){
                pre1[j][jj][k+1] = pre1[j][jj][k] + ok1[k][j][jj];
            }
        }
    }
    ll pre2[n][n][m+1];
    memset(pre2,0,sizeof pre2);
    f(i,1,n-1){
        f(ii,i,n-1){
            f(k,0,m){
                pre2[i][ii][k+1] = pre2[i][ii][k] + ok2[k][i][ii];
            }
        }
    }
    f(i,1,n-1){
        f(j,1,m-1){
            f(ii,i,n-1){
                f(jj,j,m-1){
                    bool ok = (pre1[j][jj][ii+1] - pre1[j][jj][i]) == (ii - i  + 1);
                    ok &= (pre2[i][ii][jj+1] - pre2[i][ii][j]) == (jj - j + 1);
                    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 time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 2 ms 716 KB Output is correct
4 Correct 1 ms 672 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 356 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 1 ms 716 KB Output is correct
12 Correct 1 ms 716 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 292 KB Output is correct
17 Correct 1 ms 292 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 2 ms 716 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 2 ms 716 KB Output is correct
4 Correct 1 ms 672 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 356 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 1 ms 716 KB Output is correct
12 Correct 1 ms 716 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 292 KB Output is correct
17 Correct 1 ms 292 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 2 ms 716 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 39 ms 9420 KB Output is correct
23 Correct 39 ms 9508 KB Output is correct
24 Correct 38 ms 9420 KB Output is correct
25 Correct 39 ms 9472 KB Output is correct
26 Correct 35 ms 9264 KB Output is correct
27 Correct 37 ms 9292 KB Output is correct
28 Correct 44 ms 9476 KB Output is correct
29 Correct 10 ms 3788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 2 ms 716 KB Output is correct
4 Correct 1 ms 672 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 356 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 1 ms 716 KB Output is correct
12 Correct 1 ms 716 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 292 KB Output is correct
17 Correct 39 ms 9420 KB Output is correct
18 Correct 39 ms 9508 KB Output is correct
19 Correct 38 ms 9420 KB Output is correct
20 Correct 39 ms 9472 KB Output is correct
21 Correct 35 ms 9264 KB Output is correct
22 Correct 37 ms 9292 KB Output is correct
23 Correct 44 ms 9476 KB Output is correct
24 Correct 10 ms 3788 KB Output is correct
25 Correct 1 ms 292 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 2 ms 716 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 3162 ms 142348 KB Output is correct
31 Correct 3186 ms 142348 KB Output is correct
32 Correct 3156 ms 142532 KB Output is correct
33 Correct 3135 ms 142284 KB Output is correct
34 Correct 3136 ms 142272 KB Output is correct
35 Correct 3143 ms 142428 KB Output is correct
36 Correct 3213 ms 142404 KB Output is correct
37 Correct 1987 ms 139264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 2 ms 716 KB Output is correct
4 Correct 1 ms 672 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 356 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 1 ms 716 KB Output is correct
12 Correct 1 ms 716 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 292 KB Output is correct
17 Correct 39 ms 9420 KB Output is correct
18 Correct 39 ms 9508 KB Output is correct
19 Correct 38 ms 9420 KB Output is correct
20 Correct 39 ms 9472 KB Output is correct
21 Correct 35 ms 9264 KB Output is correct
22 Correct 37 ms 9292 KB Output is correct
23 Correct 44 ms 9476 KB Output is correct
24 Correct 10 ms 3788 KB Output is correct
25 Correct 3162 ms 142348 KB Output is correct
26 Correct 3186 ms 142348 KB Output is correct
27 Correct 3156 ms 142532 KB Output is correct
28 Correct 3135 ms 142284 KB Output is correct
29 Correct 3136 ms 142272 KB Output is correct
30 Correct 3143 ms 142428 KB Output is correct
31 Correct 3213 ms 142404 KB Output is correct
32 Correct 1987 ms 139264 KB Output is correct
33 Correct 1 ms 292 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 2 ms 716 KB Output is correct
36 Correct 1 ms 460 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Runtime error 1280 ms 1048580 KB Execution killed with signal 9
39 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 158 ms 214704 KB Output is correct
2 Correct 115 ms 154856 KB Output is correct
3 Correct 163 ms 214496 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 159 ms 214600 KB Output is correct
6 Correct 161 ms 214640 KB Output is correct
7 Correct 159 ms 214596 KB Output is correct
8 Correct 158 ms 214588 KB Output is correct
9 Correct 159 ms 214608 KB Output is correct
10 Correct 74 ms 104260 KB Output is correct
11 Correct 104 ms 159404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 2 ms 716 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Runtime error 475 ms 1048580 KB Execution killed with signal 9
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 2 ms 716 KB Output is correct
4 Correct 1 ms 672 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 356 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 1 ms 716 KB Output is correct
12 Correct 1 ms 716 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 292 KB Output is correct
17 Correct 39 ms 9420 KB Output is correct
18 Correct 39 ms 9508 KB Output is correct
19 Correct 38 ms 9420 KB Output is correct
20 Correct 39 ms 9472 KB Output is correct
21 Correct 35 ms 9264 KB Output is correct
22 Correct 37 ms 9292 KB Output is correct
23 Correct 44 ms 9476 KB Output is correct
24 Correct 10 ms 3788 KB Output is correct
25 Correct 3162 ms 142348 KB Output is correct
26 Correct 3186 ms 142348 KB Output is correct
27 Correct 3156 ms 142532 KB Output is correct
28 Correct 3135 ms 142284 KB Output is correct
29 Correct 3136 ms 142272 KB Output is correct
30 Correct 3143 ms 142428 KB Output is correct
31 Correct 3213 ms 142404 KB Output is correct
32 Correct 1987 ms 139264 KB Output is correct
33 Runtime error 1280 ms 1048580 KB Execution killed with signal 9
34 Halted 0 ms 0 KB -