Submission #1067943

# Submission time Handle Problem Language Result Execution time Memory
1067943 2024-08-21T05:53:23 Z becaido Rectangles (IOI19_rect) C++17
27 / 100
289 ms 105148 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;

#ifndef WAIMAI
#include "rect.h"
#else
#include "grader.cpp"
#endif

#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif

#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second

const int SIZE = 2505;
const int SSIZ = 205;

int n, m;
ll ans;
int a[SIZE][SIZE];
int U[SSIZ][SSIZ][SSIZ], D[SSIZ][SSIZ][SSIZ];
int L[SSIZ][SSIZ][SSIZ], R[SSIZ][SSIZ][SSIZ];

ll n_small() {
    if (n < 3) return 0;
    FOR (l, 2, n) {
        int mx = 0;
        FOR (r, l, n - 1) {
            if (a[2][r] >= min(a[1][r], a[3][r])) break;
            mx = max(mx, a[2][r]);
            ans += (mx < min(a[2][l - 1], a[2][r + 1]));
        }
    }
    return ans;
}

ll count_rectangles(vector<vector<int>> _a) {
    n = _a.size(), m = _a[0].size(), ans = 0;
    FOR (i, 1, n) FOR (j, 1, m) a[i][j] = _a[i - 1][j - 1];

    if (n <= 3) return n_small();

    FOR (i, 1, n) {
        vector<int> st;
        FOR (j, 1, m) {
            while (st.size() && a[i][j] > a[i][st.back()]) st.pop_back();
            L[i][i][j] = (st.size() ? st.back() + 1 : 1);
            st.pb(j);
            // debug(i, j, L[i][i][j]);
        }
        st.clear();
        for (int j = m; j >= 1; j--) {
            while (st.size() && a[i][j] > a[i][st.back()]) st.pop_back();
            R[i][i][j] = (st.size() ? st.back() - 1 : m);
            st.pb(j);
            // debug(i, j, R[i][i][j]);
        }
    }
    FOR (j, 1, m) {
        vector<int> st;
        FOR (i, 1, n) {
            while (st.size() && a[i][j] > a[st.back()][j]) st.pop_back();
            U[i][j][j] = (st.size() ? st.back() + 1 : 1);
            st.pb(i);
            // debug(i, j, U[i][j][j]);
        }
        st.clear();
        for (int i = n; i >= 1; i--) {
            while (st.size() && a[i][j] > a[st.back()][j]) st.pop_back();
            D[i][j][j] = (st.size() ? st.back() - 1 : n);
            st.pb(i);
            // debug(i, j, D[i][j][j]);
        }
    }

    FOR (u, 1, n) FOR (d, u + 1, n) FOR (j, 1, m) {
        L[u][d][j] = max(L[u][d - 1][j], L[d][d][j]);
        R[u][d][j] = min(R[u][d - 1][j], R[d][d][j]);
    }
    FOR (i, 1, n) FOR (l, 1, m) FOR (r, l + 1, m) {
        U[i][l][r] = max(U[i][l][r - 1], U[i][r][r]);
        D[i][l][r] = min(D[i][l][r - 1], D[i][r][r]);
    }

    FOR (u, 1, n) FOR (d, u + 2, n) FOR (l, 1, m) FOR (r, l + 2, m) {
        bool f = 1;
        // debug(u, d, l, r, D[u][l][r], U[d][l][r], R[u][d][l], L[u][d][r]);
        f &= (D[u][l + 1][r - 1] + 1 >= d);
        f &= (U[d][l + 1][r - 1] - 1 <= u);
        f &= (R[u + 1][d - 1][l] + 1 >= r);
        f &= (L[u + 1][d - 1][r] - 1 <= l);
        ans += f;
    }
    return ans;
}

/*
in1
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
out1
6
*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 2 ms 12380 KB Output is correct
3 Correct 2 ms 14428 KB Output is correct
4 Correct 2 ms 12380 KB Output is correct
5 Correct 2 ms 14428 KB Output is correct
6 Correct 2 ms 14428 KB Output is correct
7 Correct 1 ms 11612 KB Output is correct
8 Correct 1 ms 12892 KB Output is correct
9 Correct 3 ms 14428 KB Output is correct
10 Correct 2 ms 12376 KB Output is correct
11 Correct 2 ms 14424 KB Output is correct
12 Correct 2 ms 12380 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 12636 KB Output is correct
15 Correct 1 ms 12636 KB Output is correct
16 Correct 0 ms 2660 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 2 ms 12380 KB Output is correct
20 Correct 1 ms 11612 KB Output is correct
21 Correct 2 ms 10592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 2 ms 12380 KB Output is correct
3 Correct 2 ms 14428 KB Output is correct
4 Correct 2 ms 12380 KB Output is correct
5 Correct 2 ms 14428 KB Output is correct
6 Correct 2 ms 14428 KB Output is correct
7 Correct 1 ms 11612 KB Output is correct
8 Correct 1 ms 12892 KB Output is correct
9 Correct 3 ms 14428 KB Output is correct
10 Correct 2 ms 12376 KB Output is correct
11 Correct 2 ms 14424 KB Output is correct
12 Correct 2 ms 12380 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 12636 KB Output is correct
15 Correct 1 ms 12636 KB Output is correct
16 Correct 0 ms 2660 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 2 ms 12380 KB Output is correct
20 Correct 1 ms 11612 KB Output is correct
21 Correct 2 ms 10592 KB Output is correct
22 Correct 17 ms 26716 KB Output is correct
23 Correct 16 ms 25408 KB Output is correct
24 Correct 17 ms 26804 KB Output is correct
25 Correct 18 ms 25180 KB Output is correct
26 Correct 14 ms 24920 KB Output is correct
27 Correct 14 ms 25180 KB Output is correct
28 Correct 15 ms 25408 KB Output is correct
29 Correct 7 ms 21596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 2 ms 12380 KB Output is correct
3 Correct 2 ms 14428 KB Output is correct
4 Correct 2 ms 12380 KB Output is correct
5 Correct 2 ms 14428 KB Output is correct
6 Correct 2 ms 14428 KB Output is correct
7 Correct 1 ms 11612 KB Output is correct
8 Correct 1 ms 12892 KB Output is correct
9 Correct 3 ms 14428 KB Output is correct
10 Correct 2 ms 12376 KB Output is correct
11 Correct 2 ms 14424 KB Output is correct
12 Correct 2 ms 12380 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 12636 KB Output is correct
15 Correct 1 ms 12636 KB Output is correct
16 Correct 0 ms 2660 KB Output is correct
17 Correct 17 ms 26716 KB Output is correct
18 Correct 16 ms 25408 KB Output is correct
19 Correct 17 ms 26804 KB Output is correct
20 Correct 18 ms 25180 KB Output is correct
21 Correct 14 ms 24920 KB Output is correct
22 Correct 14 ms 25180 KB Output is correct
23 Correct 15 ms 25408 KB Output is correct
24 Correct 7 ms 21596 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 2 ms 12380 KB Output is correct
28 Correct 1 ms 11612 KB Output is correct
29 Correct 2 ms 10592 KB Output is correct
30 Correct 276 ms 104788 KB Output is correct
31 Correct 273 ms 104788 KB Output is correct
32 Correct 267 ms 104784 KB Output is correct
33 Correct 289 ms 105148 KB Output is correct
34 Correct 274 ms 104784 KB Output is correct
35 Correct 271 ms 104788 KB Output is correct
36 Correct 276 ms 104980 KB Output is correct
37 Correct 280 ms 103764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 2 ms 12380 KB Output is correct
3 Correct 2 ms 14428 KB Output is correct
4 Correct 2 ms 12380 KB Output is correct
5 Correct 2 ms 14428 KB Output is correct
6 Correct 2 ms 14428 KB Output is correct
7 Correct 1 ms 11612 KB Output is correct
8 Correct 1 ms 12892 KB Output is correct
9 Correct 3 ms 14428 KB Output is correct
10 Correct 2 ms 12376 KB Output is correct
11 Correct 2 ms 14424 KB Output is correct
12 Correct 2 ms 12380 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 12636 KB Output is correct
15 Correct 1 ms 12636 KB Output is correct
16 Correct 0 ms 2660 KB Output is correct
17 Correct 17 ms 26716 KB Output is correct
18 Correct 16 ms 25408 KB Output is correct
19 Correct 17 ms 26804 KB Output is correct
20 Correct 18 ms 25180 KB Output is correct
21 Correct 14 ms 24920 KB Output is correct
22 Correct 14 ms 25180 KB Output is correct
23 Correct 15 ms 25408 KB Output is correct
24 Correct 7 ms 21596 KB Output is correct
25 Correct 276 ms 104788 KB Output is correct
26 Correct 273 ms 104788 KB Output is correct
27 Correct 267 ms 104784 KB Output is correct
28 Correct 289 ms 105148 KB Output is correct
29 Correct 274 ms 104784 KB Output is correct
30 Correct 271 ms 104788 KB Output is correct
31 Correct 276 ms 104980 KB Output is correct
32 Correct 280 ms 103764 KB Output is correct
33 Correct 0 ms 2396 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 2 ms 12380 KB Output is correct
36 Correct 1 ms 11612 KB Output is correct
37 Correct 2 ms 10592 KB Output is correct
38 Runtime error 44 ms 48720 KB Execution killed with signal 11
39 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 2 ms 12380 KB Output is correct
4 Correct 1 ms 11612 KB Output is correct
5 Correct 2 ms 10592 KB Output is correct
6 Correct 2 ms 14684 KB Output is correct
7 Runtime error 109 ms 103828 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 2 ms 12380 KB Output is correct
3 Correct 2 ms 14428 KB Output is correct
4 Correct 2 ms 12380 KB Output is correct
5 Correct 2 ms 14428 KB Output is correct
6 Correct 2 ms 14428 KB Output is correct
7 Correct 1 ms 11612 KB Output is correct
8 Correct 1 ms 12892 KB Output is correct
9 Correct 3 ms 14428 KB Output is correct
10 Correct 2 ms 12376 KB Output is correct
11 Correct 2 ms 14424 KB Output is correct
12 Correct 2 ms 12380 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 12636 KB Output is correct
15 Correct 1 ms 12636 KB Output is correct
16 Correct 0 ms 2660 KB Output is correct
17 Correct 17 ms 26716 KB Output is correct
18 Correct 16 ms 25408 KB Output is correct
19 Correct 17 ms 26804 KB Output is correct
20 Correct 18 ms 25180 KB Output is correct
21 Correct 14 ms 24920 KB Output is correct
22 Correct 14 ms 25180 KB Output is correct
23 Correct 15 ms 25408 KB Output is correct
24 Correct 7 ms 21596 KB Output is correct
25 Correct 276 ms 104788 KB Output is correct
26 Correct 273 ms 104788 KB Output is correct
27 Correct 267 ms 104784 KB Output is correct
28 Correct 289 ms 105148 KB Output is correct
29 Correct 274 ms 104784 KB Output is correct
30 Correct 271 ms 104788 KB Output is correct
31 Correct 276 ms 104980 KB Output is correct
32 Correct 280 ms 103764 KB Output is correct
33 Runtime error 44 ms 48720 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -