Submission #683897

# Submission time Handle Problem Language Result Execution time Memory
683897 2023-01-19T15:04:14 Z KiriLL1ca Hyper-minimum (IZhO11_hyper) C++17
100 / 100
406 ms 65392 KB
#include <bits/stdc++.h>
#define vec vector
#define forn(i, s, f) for (int i = s; i <= f; ++i)

using namespace std;

template <typename T> inline bool umin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template <typename T> inline bool umax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }

typedef pair <int, int> pii;

const int N = 40;

int a[N][N][N][N], res[N][N][N][N];
int st[7][N][N][N][N];
int lg[N];

inline int ask (int i, int j, int k, int l, int ri, int rj, int rk, int rl, int m) {
        int s = lg[m];
        int ii = ri - (1 << s) + 1;
        int jj = rj - (1 << s) + 1;
        int kk = rk - (1 << s) + 1;
        int ll = rl - (1 << s) + 1;

        return min({
                   st[s][i][j][k][l],
                   st[s][ii][j][k][l],
                   st[s][i][jj][k][l],
                   st[s][i][j][kk][l],
                   st[s][i][j][k][ll],

                   st[s][ii][jj][k][l],
                   st[s][ii][j][kk][l],
                   st[s][ii][j][k][ll],

                   st[s][i][jj][kk][l],
                   st[s][i][jj][k][ll],

                   st[s][i][j][kk][ll],

                   st[s][ii][jj][kk][l],
                   st[s][ii][jj][k][ll],
                   st[s][ii][j][kk][ll],
                   st[s][i][jj][kk][ll],

                   st[s][ii][jj][kk][ll]
                   });
}

inline void solve () {
        for (int i = 2; i < N; ++i) lg[i] = lg[i >> 1] + 1;

        int n, M; cin >> n >> M;
        forn (i, 1, n) forn (j, 1, n) forn (k, 1, n) forn (l, 1, n) cin >> a[i][j][k][l];
        forn (i, 1, n) forn (j, 1, n) forn (k, 1, n) forn (l, 1, n) st[0][i][j][k][l] = a[i][j][k][l];

        for (int s = 1; s <= 6; ++s) {
                int p = (1 << (s - 1));
                int G = n - (1 << s) + 1;
                forn (i, 1, G) forn (j, 1, G) forn (k, 1, G) forn (l, 1, G) {
                        st[s][i][j][k][l] = min({
                                                st[s - 1][i + 0][j + 0][k + 0][l + 0],
                                                st[s - 1][i + p][j + 0][k + 0][l + 0],
                                                st[s - 1][i + 0][j + p][k + 0][l + 0],
                                                st[s - 1][i + 0][j + 0][k + p][l + 0],
                                                st[s - 1][i + 0][j + 0][k + 0][l + p],

                                                st[s - 1][i + p][j + p][k + 0][l + 0],
                                                st[s - 1][i + p][j + 0][k + p][l + 0],
                                                st[s - 1][i + p][j + 0][k + 0][l + p],

                                                st[s - 1][i + 0][j + p][k + p][l + 0],
                                                st[s - 1][i + 0][j + p][k + 0][l + p],

                                                st[s - 1][i + 0][j + 0][k + p][l + p],

                                                st[s - 1][i + p][j + p][k + p][l + 0],
                                                st[s - 1][i + p][j + p][k + 0][l + p],
                                                st[s - 1][i + p][j + 0][k + p][l + p],
                                                st[s - 1][i + 0][j + p][k + p][l + p],

                                                st[s - 1][i + p][j + p][k + p][l + p],
                                                });
                }
        }

        int G = n - M + 1;
        forn (i, 1, G) forn (j, 1, G) forn (k, 1, G) forn (l, 1, G) {
                cout << ask(i,         j,         k,         l,
                            i + M - 1, j + M - 1, k + M - 1, l + M - 1, M) << " ";
        }

}

signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        #ifdef LOCAL
                freopen("input.txt", "r", stdin);
                freopen("output.txt", "w", stdout);
        #else
                
        #endif
        int t = 1; // cin >> t;
        while (t--) solve();
        return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 2 ms 2132 KB Output is correct
4 Correct 2 ms 2260 KB Output is correct
5 Correct 3 ms 2140 KB Output is correct
6 Correct 10 ms 6020 KB Output is correct
7 Correct 12 ms 5836 KB Output is correct
8 Correct 34 ms 11980 KB Output is correct
9 Correct 44 ms 13772 KB Output is correct
10 Correct 24 ms 12104 KB Output is correct
11 Correct 63 ms 22016 KB Output is correct
12 Correct 140 ms 35552 KB Output is correct
13 Correct 136 ms 34476 KB Output is correct
14 Correct 188 ms 40268 KB Output is correct
15 Correct 287 ms 56232 KB Output is correct
16 Correct 176 ms 44692 KB Output is correct
17 Correct 184 ms 45972 KB Output is correct
18 Correct 406 ms 65392 KB Output is correct
19 Correct 237 ms 54380 KB Output is correct
20 Correct 213 ms 52300 KB Output is correct