답안 #897023

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
897023 2024-01-02T12:29:16 Z vjudge1 Maxcomp (info1cup18_maxcomp) C++17
100 / 100
106 ms 48716 KB
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
 
// #pragma GCC optimize("Ofast,unroll-loops,fast-math")
// #pragma GCC target("popcnt")


typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
 
#define sz size()
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define pb push_back

const int mod = ll(1e9)+7; //(b + (a%b)) % b (to mod -1%(10^9+7) correctly in c++ its -1 but its suppose to be 10^9+6
const ll MOD = 998244353;  // (a%mod)*(binpow(b,mod-2,mod) = (a/b)%mod
const int N = ll(4e5)+100;
const long long inf = 1e17;
const long double eps = 1e-15L;
 
ll lcm(ll a, ll b) { return (a / __gcd(a,b))*b; }

ll binpow(ll a, ll b, ll m) { ll res=1; a %= m; while(b>0){ if(b&1)res=(res * a) % m; a=(a * a) % m; b/=2; } return res%m;}


void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }

long long n, m, a[1005][1005], mx[1005][1005][4];

void Baizho() {	
	cin>>n>>m;
	for(int i = 1; i <= n; i ++) {
		for(int j = 1; j <= m; j ++) cin>>a[i][j];
	}
	for(int i = 0; i <= n + 1; i ++) for(int j = 0; j <= m + 1; j ++) for(int k = 0; k < 4; k ++) mx[i][j][k] = -inf;
	for(int i = n; i >= 1; i --) {
		for(int j = m; j >= 1; j --) mx[i][j][0] = max({mx[i + 1][j][0], mx[i][j + 1][0], -a[i][j]-i-j});
		for(int j = 1; j <= m; j ++) mx[i][j][1] = max({mx[i + 1][j][1], mx[i][j - 1][1], -a[i][j]-i+j});
	}
	for(int i = 1; i <= n; i ++) {
		for(int j = m; j >= 1; j --) mx[i][j][2] = max({mx[i - 1][j][2], mx[i][j + 1][2], -a[i][j]+i-j});
		for(int j = 1; j <= m; j ++) mx[i][j][3] = max({mx[i - 1][j][3], mx[i][j - 1][3], -a[i][j]+i+j});
	}
	long long ans = -inf;
	for(int i = 1; i <= n; i ++) {
		for(int j = 1; j <= m; j ++) {
			ans = max({ans, a[i][j] + i + j + mx[i][j][0], a[i][j] + i - j + mx[i][j][1], a[i][j] - i + j + mx[i][j][2], a[i][j] - i - j + mx[i][j][3]});
		}
	}
	cout<<ans - 1;
}
 
signed main() {		
 
    ios_base::sync_with_stdio(false);   
    cin.tie(0);cout.tie(0); 
//   	precalc();
   	
    int ttt = 1;
//    cin>>ttt;

    for(int i=1; i<=ttt; i++) { Baizho(); }
}

Compilation message

maxcomp.cpp: In function 'void Freopen(std::string)':
maxcomp.cpp:35:34: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
      |                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
maxcomp.cpp:35:76: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
      |                                                                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2516 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2516 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4576 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2516 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4576 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 88 ms 48468 KB Output is correct
19 Correct 89 ms 48464 KB Output is correct
20 Correct 84 ms 47952 KB Output is correct
21 Correct 88 ms 48232 KB Output is correct
22 Correct 106 ms 48444 KB Output is correct
23 Correct 87 ms 48472 KB Output is correct
24 Correct 91 ms 48716 KB Output is correct