Submission #496877

# Submission time Handle Problem Language Result Execution time Memory
496877 2021-12-22T05:58:02 Z kingline Maxcomp (info1cup18_maxcomp) C++17
15 / 100
2 ms 332 KB
/*#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/
#include <bits/stdc++.h>
#pragma GCC optimize ("unroll-loops,Ofast,O3")
#pragma GCC target("avx,avx2,fma")
//#define file(data) freopen(data".in", "r", stdin); freopen(data".out", "w", stdout);
#define pb push_back
//#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(data) data.begin() , data.end()
#define endl '\n'
//freopen("nenokku_easy.in", "r", stdin);
//freopen("nenokku_easy.out", "w", stdout);
//#define int long long
#define pii pair < int, int >
#define pll pair < long long, long long >

using namespace std;

const int N = 1e3 + 5;
const int lg = 21;

int n, m, a[N][N], ans = 0;

void rec(int i, int j, int mn, int mx, int len) {
    if(i > n || j > m) return;
    ans = max(ans, mx - mn - len);
    rec(i + 1, j, min(mn, a[i + 1][j]), max(mx, a[i + 1][j]), len + 1);
    rec(i, j + 1, min(mn, a[i][j + 1]), max(mx, a[i][j + 1]), len + 1);
}

void recmin(int i, int j, int mn, int mx, int len) {
    if(i > n || j > m) return;
    ans = max(ans, mx - mn - len);
    if(a[i + 1][j] > mn) recmin(i + 1, j, mn, max(mx, a[i + 1][j]), len + 1);
    if(a[i][j + 1] > mn) recmin(i, j + 1, mn, max(mx, a[i][j + 1]), len + 1);
}

void recmax(int i, int j, int mn, int mx, int len) {
    if(i > n || j > m) return;
    ans = max(ans, mx - mn - len);
    if(a[i + 1][j] < mx) recmax(i + 1, j, min(mn, a[i + 1][j]), mx, len + 1);
    if(a[i][j + 1] < mx) recmax(i, j + 1, min(mn, a[i][j + 1]), mx, len + 1);
}

main() {
    //file("pieaters");
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cin >> a[i][j];
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            rec(i, j, a[i][j], a[i][j], 1);
            recmin(i, j, a[i][j], a[i][j], 1);
            recmax(i, j, a[i][j], a[i][j], 1);
        }
    }
    cout << ans;
}





Compilation message

maxcomp.cpp:48:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   48 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Incorrect 1 ms 324 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Incorrect 1 ms 324 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Incorrect 1 ms 324 KB Output isn't correct
4 Halted 0 ms 0 KB -