답안 #922983

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
922983 2024-02-06T11:55:41 Z Ianis Maxcomp (info1cup18_maxcomp) C++17
0 / 100
4 ms 12892 KB
#ifdef LOCAL
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <random>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#else
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
#define cerr if (false) cerr 
#define endl '\n'
#endif

#define fi first
#define se second

#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()

#define lsb(x) (x & (-x))

#define bit(mask, i) (((mask) >> (i)) & 1)
#define popcount(x) __builtin_popcount(x)

#define YES cout << "YES" << endl
#define NO cout << "NO" << endl

using namespace std;

template <typename T>
bool ckmax(T &a, T b) { return a < b ? a = b, true : false; }
template <typename T>
bool ckmin(T &a, T b) { return a > b ? a = b, true : false; }

using ll = long long;
using pii = pair<int, int>;

const int NMAX = 1e3+5;
const int INF  = 1e9+5;

const int di[] = { 1, -1, 0, 0 };
const int dj[] = { 0, 0, 1, -1 };

struct Point {
   int val, i, j;
};

struct State {
   int max, min, cnt;

   State(): max(0), min(INF), cnt(0) { }
   State(int _max, int _min, int _cnt): max(_max), min(_min), cnt(_cnt) { }

   int weight() const {
      return max - min - cnt;
   }

   State add(int val) {
      State s = *this;
      ckmax(s.max, val);
      ckmin(s.min, val);
      s.cnt++;
      return s;
   }
};

bool operator<(const State &s1, const State &s2) {
   return s1.weight() < s2.weight();
}

int n, m;
int a[NMAX][NMAX];
State dp[NMAX][NMAX];

void read() {
   cin >> n >> m;
   for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++)
         cin >> a[i][j];
   }
}

int solve() {
   int ans = -1;

   for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
         dp[i][j] = State(a[i][j], a[i][j], 1);
         ckmax(dp[i][j], max(dp[i - 1][j].add(a[i][j]), dp[i][j - 1].add(a[i][j])));
         ckmax(ans, dp[i][j].weight());
      }
   }

   for (int i = 1; i <= n; i++) {
      for (int j = m; j >= 1; j--) {
         dp[i][j] = State(a[i][j], a[i][j], 1);
         ckmax(dp[i][j], max(dp[i + 1][j].add(a[i][j]), dp[i][j + 1].add(a[i][j])));
         ckmax(ans, dp[i][j].weight());
      }
   }

   return ans;
}

signed main() {
#ifdef LOCAL
   freopen("input.txt", "r", stdin);
#endif
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   
   read();
   cout << solve() << endl;

   return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 12120 KB Output is correct
2 Correct 4 ms 12124 KB Output is correct
3 Correct 3 ms 12124 KB Output is correct
4 Incorrect 3 ms 12124 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 12892 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 12120 KB Output is correct
2 Correct 4 ms 12124 KB Output is correct
3 Correct 3 ms 12124 KB Output is correct
4 Incorrect 3 ms 12124 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 12120 KB Output is correct
2 Correct 4 ms 12124 KB Output is correct
3 Correct 3 ms 12124 KB Output is correct
4 Incorrect 3 ms 12124 KB Output isn't correct
5 Halted 0 ms 0 KB -