제출 #497888

#제출 시각아이디문제언어결과실행 시간메모리
497888kinglineMaxcomp (info1cup18_maxcomp)C++17
100 / 100
132 ms39832 KiB
/*#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; typedef long long ll; const int N = 1e3 + 5; const int M = 305; const int mod = 1e9 + 7; int n, m, a[N][N], uppref[N][N], downpref[N][N], upsuff[N][N], downsuff[N][N]; void calc() { for(int i = 0; i <= n + 1; i++) { for(int j = 0; j <= m + 1; j++) { uppref[i][j] = upsuff[i][j] = downpref[i][j] = downsuff[i][j] = -1e10; } } for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { uppref[i][j] = max(max(uppref[i - 1][j], uppref[i][j - 1]), (-a[i][j] + i + j)); } } for(int i = 1; i <= n; i++) { for(int j = m; j > 0; j--) { upsuff[i][j] = max(max(upsuff[i - 1][j], upsuff[i][j + 1]), (-a[i][j] + i - j)); } } for(int i = n; i > 0; i--) { for(int j = 1; j <= m; j++) { downpref[i][j] = max(max(downpref[i + 1][j], downpref[i][j - 1]), (-a[i][j] - i + j)); } } for(int i = n; i > 0; i--) { for(int j = m; j > 0; j--) { downsuff[i][j] = max(max(downsuff[i + 1][j], downsuff[i][j + 1]), (-a[i][j] - i - j)); } } } int get(int i, int j) { int res = a[i][j] - i - j + max(uppref[i - 1][j], uppref[i][j - 1]); res = max(res, a[i][j] - i + j + max(upsuff[i - 1][j], upsuff[i][j + 1])); res = max(res, a[i][j] + i - j + max(downpref[i][j - 1], downpref[i + 1][j])); res = max(res, a[i][j] + i + j + max(downsuff[i + 1][j], downsuff[i][j + 1])); return res - 1; } main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //file("pieaters"); cin >> n >> m; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { cin >> a[i][j]; } } calc(); int ans = -1; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { ans = max(ans, get(i, j)); //cout << get(i, j) << " "; //cout << uppref[i][j] << " "; } //cout << endl; } cout << ans; }

컴파일 시 표준 에러 (stderr) 메시지

maxcomp.cpp:69:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   69 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...