Submission #1149532

#TimeUsernameProblemLanguageResultExecution timeMemory
1149532adlinMaxcomp (info1cup18_maxcomp)C++20
100 / 100
81 ms39496 KiB
//#pragma GCC optimize("O3,unroll-loops") //#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include <bits/stdc++.h> #define pb push_back #define ll long long #define F first #define S second #define all(v) (v).begin(),(v).end() #define ull unsigned long long #define ahahahant ios_base::sync_with_stdio(0);cin.tie(0); #define int long long using namespace std; //mt19937 rng( chrono::steady_clock::now().time_since_epoch().count()); // //ll rand( ll l, ll r ) //{ // uniform_int_distribution <ll> uid( l, r ); // return uid( rng ); //} ll lcm(ll x, ll y){ return x / __gcd(x,y) * y; } ll binpow(ll a, ll b, ll m){ if(!b) return 1ll; if(b & 1) return binpow(a,b-1,m) * a % m; int res = binpow(a,b/2,m) % m; return res * res % m; } const int maxn = 1e6 + 6; const int mod = 1e9 + 7; const int mod2 = 998244353; const ll inf = 1e18; const int inf2 = 1e9; const int K = 300; int n,a[1002][1002],m; int dp1[1002][1002]; int dp2[1002][1002]; int dp3[1002][1002]; int dp4[1002][1002]; void who(){ cin >> n >> m; for(int i = 0; i <= n + 1; i++){ for(int j = 0; j <= m + 1; j++){ dp1[i][j] = -1e18; dp2[i][j] = -1e18; dp3[i][j] = -1e18; dp4[i][j] = -1e18; } } 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++){ dp1[i][j] = max({dp1[i - 1][j], dp1[i][j - 1], +j+i-a[i][j]-1}); } } for(int i = n; i >= 1; i--){ for(int j = m; j >= 1; j--){ dp4[i][j] = max({dp4[i + 1][j], dp4[i][j + 1], -j-i-a[i][j]-1}); } } for(int i = n; i >= 1; i--){ for(int j = 1; j <= m; j++){ dp3[i][j] = max({dp3[i + 1][j], dp3[i][j - 1], -i+j-a[i][j]-1}); } } for(int i = 1; i <= n; i++){ for(int j = m; j >= 1; j--){ dp2[i][j] = max({dp2[i - 1][j], dp2[i][j + 1], +i-j-a[i][j]-1}); } } ll ans = -1; for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ ans = max(ans, dp1[i][j] - i - j + a[i][j]); ans = max(ans, dp4[i][j] + i + j + a[i][j]); ans = max(ans, dp2[i][j] - i + j + a[i][j]); ans = max(ans, dp3[i][j] + i - j + a[i][j]); } } cout << ans << '\n'; } signed main(){ // freopen("yinyang.in", "r", stdin); // freopen("yinyang.out", "w", stdout); ahahahant int tt = 1; // cin >> tt; while(tt--){ who(); } return 0; } /* __builtin_popcount __builtin_clz __builtin_ctz __builtin_parity int get(int r){ int res = 0; for(; r >= 0; r = (r & (r + 1)) - 1) res += f[r]; return res; } void upd(int i, int val){ for(; i <= n; i = (i | (i + 1))) f[i] += val; } */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...