Submission #1032394

# Submission time Handle Problem Language Result Execution time Memory
1032394 2024-07-23T16:51:08 Z shmax Rectangles (IOI19_rect) C++17
37 / 100
3067 ms 1048576 KB
#include "rect.h"
#include <bits/stdc++.h>

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,bmi,bmi2")

using namespace std;
using i32 = int;
//#define int long long
#define len(x) (int)(x.size())
#define inf 1000'000'000'000'000'000LL
#define all(x) x.begin(), x.end()
#define low_bit(x) (x & (-x))

template<typename T>
using vec = vector<T>;

const int maxM = 701;

long long count_rectangles(std::vector<std::vector<i32>> a) {
    int n = len(a);
    int m = len(a[0]);
    long long ans = 0;
    vec<vec<bitset<maxM>>> b(n, vec<bitset<maxM>>(m));
    for (int i = 1; i < n - 1; i++) {
        for (int j = 1; j < m - 1; j++) {
            b[i][j].reset();
            int mx = a[i][j];
            for (int l = i; l < n - 1; l++) {
                mx = max(mx, a[l][j]);
                if (mx >= min(a[i - 1][j], a[l + 1][j])) continue;
                b[i][j][l] = true;
            }

        }
    }

    vec<vec<bitset<maxM>>> good(m, vec<bitset<maxM>>(m));

    vec<vec<vec<int>>> maxVal(n, vec<vec<int>>(m, vec<int>(m, 0)));
    for (int i = 1; i < n - 1; i++) {
        for (int l = 1; l < m - 1; l++) {
            for (int r = l; r < m - 1; r++) {
                maxVal[i][l][r] = max(maxVal[i][l][r - 1], a[i][r]);
            }
        }
    }
    for (int l = 1; l < m - 1; l++) {
        for (int r = l; r < m - 1; r++) {
            for (int i = 0; i < n; i++) {
                good[l][r][i] = maxVal[i][l][r] < min(a[i][l - 1], a[i][r + 1]);
            }
        }
    }
    vec<vec<vec<int>>> lowest(m, vec<vec<int>>(m, vec<int>(n, 0)));
    for (int l = 1; l < m - 1; l++) {
        for (int r = l; r < m - 1; r++) {
            for (int i = n - 2; i >= 1; i--) {
                if (!good[l][r][i]) continue;
                lowest[l][r][i] = lowest[l][r][i + 1] + 1;
            }
        }
    }
    for (int i = 1; i < n - 1; i++) {
        for (int j = 1; j < m - 1; j++) {
            if (a[i][j] >= a[i - 1][j]) continue;
            if (a[i][j] >= a[i][j - 1]) continue;
            for (int k = j; k < m - 1; k++) {
                b[i][j] &= b[i][k];

                ans += (b[i][j] & ((good[j][k] << (maxM - i - lowest[j][k][i])) >> (maxM - i - lowest[j][k][i]))).count();
            }
        }
    }

    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 876 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 0 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 856 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 860 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 876 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 0 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 856 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 860 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 20 ms 6236 KB Output is correct
23 Correct 19 ms 5976 KB Output is correct
24 Correct 20 ms 5980 KB Output is correct
25 Correct 7 ms 5980 KB Output is correct
26 Correct 10 ms 5976 KB Output is correct
27 Correct 11 ms 5872 KB Output is correct
28 Correct 9 ms 6072 KB Output is correct
29 Correct 3 ms 2008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 876 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 0 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 856 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 20 ms 6236 KB Output is correct
18 Correct 19 ms 5976 KB Output is correct
19 Correct 20 ms 5980 KB Output is correct
20 Correct 7 ms 5980 KB Output is correct
21 Correct 10 ms 5976 KB Output is correct
22 Correct 11 ms 5872 KB Output is correct
23 Correct 9 ms 6072 KB Output is correct
24 Correct 3 ms 2008 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 860 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 306 ms 73796 KB Output is correct
31 Correct 293 ms 73796 KB Output is correct
32 Correct 290 ms 73812 KB Output is correct
33 Correct 110 ms 73552 KB Output is correct
34 Correct 141 ms 73556 KB Output is correct
35 Correct 140 ms 73776 KB Output is correct
36 Correct 138 ms 73816 KB Output is correct
37 Correct 134 ms 71756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 876 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 0 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 856 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 20 ms 6236 KB Output is correct
18 Correct 19 ms 5976 KB Output is correct
19 Correct 20 ms 5980 KB Output is correct
20 Correct 7 ms 5980 KB Output is correct
21 Correct 10 ms 5976 KB Output is correct
22 Correct 11 ms 5872 KB Output is correct
23 Correct 9 ms 6072 KB Output is correct
24 Correct 3 ms 2008 KB Output is correct
25 Correct 306 ms 73796 KB Output is correct
26 Correct 293 ms 73796 KB Output is correct
27 Correct 290 ms 73812 KB Output is correct
28 Correct 110 ms 73552 KB Output is correct
29 Correct 141 ms 73556 KB Output is correct
30 Correct 140 ms 73776 KB Output is correct
31 Correct 138 ms 73816 KB Output is correct
32 Correct 134 ms 71756 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 860 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Runtime error 604 ms 1048576 KB Execution killed with signal 9
39 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 694 ms 955720 KB Output is correct
2 Correct 499 ms 689384 KB Output is correct
3 Correct 513 ms 955540 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 603 ms 955680 KB Output is correct
6 Correct 593 ms 955768 KB Output is correct
7 Correct 605 ms 955828 KB Output is correct
8 Correct 612 ms 955768 KB Output is correct
9 Correct 612 ms 955768 KB Output is correct
10 Correct 496 ms 906108 KB Output is correct
11 Correct 563 ms 930940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Runtime error 3067 ms 1048576 KB Execution killed with signal 9
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 876 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 0 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 856 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 20 ms 6236 KB Output is correct
18 Correct 19 ms 5976 KB Output is correct
19 Correct 20 ms 5980 KB Output is correct
20 Correct 7 ms 5980 KB Output is correct
21 Correct 10 ms 5976 KB Output is correct
22 Correct 11 ms 5872 KB Output is correct
23 Correct 9 ms 6072 KB Output is correct
24 Correct 3 ms 2008 KB Output is correct
25 Correct 306 ms 73796 KB Output is correct
26 Correct 293 ms 73796 KB Output is correct
27 Correct 290 ms 73812 KB Output is correct
28 Correct 110 ms 73552 KB Output is correct
29 Correct 141 ms 73556 KB Output is correct
30 Correct 140 ms 73776 KB Output is correct
31 Correct 138 ms 73816 KB Output is correct
32 Correct 134 ms 71756 KB Output is correct
33 Runtime error 604 ms 1048576 KB Execution killed with signal 9
34 Halted 0 ms 0 KB -