Submission #364865

# Submission time Handle Problem Language Result Execution time Memory
364865 2021-02-10T10:16:02 Z tengiz05 Maxcomp (info1cup18_maxcomp) C++17
100 / 100
49 ms 8192 KB
#include <bits/stdc++.h>
using namespace std;
template <class T> inline void read(T &x) {
	x = 0; register char ch = getchar();
	for (; ch<'0' || ch>'9';) ch = getchar();
	for (; ch>='0' && ch<='9';) x = x*10 + ch-'0', ch = getchar();
}

//~ #define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
template<class T> inline void chmin(T& a, const T& b) {if(a>b)a=b;}
template<class T> inline void chmax(T& a, const T& b) {if(a<b)a=b;}
const int mod = 1e9+7, N = 1005;
int msb(int val){return sizeof(int)*8-__builtin_clzll(val)-1;}
int n, m, k;
int a[N][N];
int dp[N][N];
inline void solve(int test_case){
	int i, j;
	read(n);read(m);
	memset(a, 245, sizeof a);
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			read(a[i][j]);
		}
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			dp[i][j] = a[i][j];
			chmax(dp[i][j], dp[i-1][j]-1);
			chmax(dp[i][j], dp[i][j-1]-1);
		}
	}
	
	for(i=n;i>=1;i--){
		for(j=m;j>=1;j--){
			chmax(dp[i][j],a[i][j]);
			chmax(dp[i][j], dp[i+1][j]-1);
			chmax(dp[i][j], dp[i][j+1]-1);
		}
	}
	int ans = -1;
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			chmax(ans, dp[i][j] - a[i][j]);
		}
	}
	cout << ans-1 << '\n';
	return;
}
/*

2 3
5 7 5
2 4 3

*/
signed main(){
	//~ FASTIO;
//~ #define MULTITEST 1
#if MULTITEST
	int _T;
	cin >> _T;
	for(int T_CASE = 1; T_CASE <= _T; T_CASE++)
		solve(T_CASE);
#else
	solve(1);
#endif
	return 0;
}




Compilation message

maxcomp.cpp: In function 'void read(T&)':
maxcomp.cpp:4:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    4 |  x = 0; register char ch = getchar();
      |                       ^~
maxcomp.cpp: In instantiation of 'void read(T&) [with T = int]':
maxcomp.cpp:27:8:   required from here
maxcomp.cpp:4:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4332 KB Output is correct
2 Correct 3 ms 4332 KB Output is correct
3 Correct 3 ms 4332 KB Output is correct
4 Correct 3 ms 4332 KB Output is correct
5 Correct 3 ms 4332 KB Output is correct
6 Correct 3 ms 4332 KB Output is correct
7 Correct 3 ms 4332 KB Output is correct
8 Correct 3 ms 4332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4332 KB Output is correct
2 Correct 3 ms 4332 KB Output is correct
3 Correct 3 ms 4332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4332 KB Output is correct
2 Correct 3 ms 4332 KB Output is correct
3 Correct 3 ms 4332 KB Output is correct
4 Correct 3 ms 4332 KB Output is correct
5 Correct 3 ms 4332 KB Output is correct
6 Correct 3 ms 4332 KB Output is correct
7 Correct 3 ms 4332 KB Output is correct
8 Correct 3 ms 4332 KB Output is correct
9 Correct 3 ms 4460 KB Output is correct
10 Correct 3 ms 4460 KB Output is correct
11 Correct 3 ms 4460 KB Output is correct
12 Correct 3 ms 4460 KB Output is correct
13 Correct 3 ms 4460 KB Output is correct
14 Correct 3 ms 4460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4332 KB Output is correct
2 Correct 3 ms 4332 KB Output is correct
3 Correct 3 ms 4332 KB Output is correct
4 Correct 3 ms 4332 KB Output is correct
5 Correct 3 ms 4332 KB Output is correct
6 Correct 3 ms 4332 KB Output is correct
7 Correct 3 ms 4332 KB Output is correct
8 Correct 3 ms 4332 KB Output is correct
9 Correct 3 ms 4332 KB Output is correct
10 Correct 3 ms 4332 KB Output is correct
11 Correct 3 ms 4332 KB Output is correct
12 Correct 3 ms 4460 KB Output is correct
13 Correct 3 ms 4460 KB Output is correct
14 Correct 3 ms 4460 KB Output is correct
15 Correct 3 ms 4460 KB Output is correct
16 Correct 3 ms 4460 KB Output is correct
17 Correct 3 ms 4460 KB Output is correct
18 Correct 47 ms 8192 KB Output is correct
19 Correct 47 ms 8172 KB Output is correct
20 Correct 45 ms 8172 KB Output is correct
21 Correct 47 ms 8172 KB Output is correct
22 Correct 49 ms 8172 KB Output is correct
23 Correct 48 ms 8172 KB Output is correct
24 Correct 48 ms 8044 KB Output is correct