Submission #594171

# Submission time Handle Problem Language Result Execution time Memory
594171 2022-07-12T07:35:17 Z piOOE Sandcastle 2 (JOI22_ho_t5) C++17
10 / 100
5000 ms 1088 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    bool swapped = false;
    if (n > m) {
        swapped = true;
        swap(n, m);
    }
    vector<vector<int>> a(n, vector<int>(m));
    for (int i = 0; i < (swapped ? m : n); ++i) {
        for (int j = 0; j < (swapped ? n : m); ++j) {
            if (!swapped) {
                cin >> a[i][j];
            } else {
                cin >> a[j][i];
            }
        }
    }
    int x1, y1, x2, y2;

    auto MIN = [&](int x, int y) -> bool {
        if (x > x1 && a[x - 1][y] < a[x][y]) return false;
        if (y > y1 && a[x][y - 1] < a[x][y]) return false;
        if (x < x2 && a[x + 1][y] < a[x][y]) return false;
        if (y < y2 && a[x][y + 1] < a[x][y]) return false;
        return true;
    };

    auto MAX = [&](int x, int y) -> bool {
        if (x > x1 && a[x - 1][y] > a[x][y]) return false;
        if (y > y1 && a[x][y - 1] > a[x][y]) return false;
        if (x < x2 && a[x + 1][y] > a[x][y]) return false;
        if (y < y2 && a[x][y + 1] > a[x][y]) return false;
        return true;
    };
    int ans = 0;
    for (x1 = 0; x1 < n; ++x1) {
        for (y1 = 0; y1 < m; ++y1) {
            for (x2 = x1; x2 < n; ++x2) {
                for (y2 = y1; y2 < m; ++y2) {
                    int cnt = 0;
                    vector<array<int, 3>> v;
                    for (int i = x1; i <= x2 && cnt <= 2; ++i) {
                        for (int j = y1; j <= y2 && cnt <= 2; ++j) {
                            v.push_back({a[i][j], i, j});
                        }
                    }
                    sort(v.begin(), v.end());
                    bool ok = true;
                    for (int i = 1; i < int(v.size()) && ok; ++i) {
                        ok &= abs(v[i][1] - v[i - 1][1]) + abs(v[i][2] - v[i - 1][2]) <= 1;
                    }
                    if (ok) {
                        ans += 1;
                    }
                }
            }
        }
    }
    cout << ans;
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:29:10: warning: variable 'MIN' set but not used [-Wunused-but-set-variable]
   29 |     auto MIN = [&](int x, int y) -> bool {
      |          ^~~
Main.cpp:37:10: warning: variable 'MAX' set but not used [-Wunused-but-set-variable]
   37 |     auto MAX = [&](int x, int y) -> bool {
      |          ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 5092 ms 1088 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 212 KB Output is correct
2 Correct 3 ms 212 KB Output is correct
3 Correct 2 ms 320 KB Output is correct
4 Correct 2 ms 444 KB Output is correct
5 Correct 3 ms 212 KB Output is correct
6 Correct 3 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 212 KB Output is correct
2 Correct 3 ms 212 KB Output is correct
3 Correct 2 ms 320 KB Output is correct
4 Correct 2 ms 444 KB Output is correct
5 Correct 3 ms 212 KB Output is correct
6 Correct 3 ms 212 KB Output is correct
7 Execution timed out 5073 ms 368 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 212 KB Output is correct
2 Correct 3 ms 212 KB Output is correct
3 Correct 2 ms 320 KB Output is correct
4 Correct 2 ms 444 KB Output is correct
5 Correct 3 ms 212 KB Output is correct
6 Correct 3 ms 212 KB Output is correct
7 Execution timed out 5073 ms 368 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 212 KB Output is correct
2 Correct 3 ms 212 KB Output is correct
3 Correct 2 ms 320 KB Output is correct
4 Correct 2 ms 444 KB Output is correct
5 Correct 3 ms 212 KB Output is correct
6 Correct 3 ms 212 KB Output is correct
7 Execution timed out 5073 ms 368 KB Time limit exceeded
8 Halted 0 ms 0 KB -