# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
88225 | 2018-12-04T15:48:17 Z | kjain_1810 | Maja (COCI18_maja) | C++11 | 111 ms | 872 KB |
#include <bits/stdc++.h> #define pb push_back #define f first #define s second #define ind(a) scanf("%d", &a) #define inlld(a) scanf("%lld", &a) #define ind2(a, b) scanf("%d%d", &a, &b) #define inlld2(a, b) scanf("%lld%lld", &a, &b) #define ind3(a, b, c) scanf("%d%d%d", &a, &b, &c) #define inlld3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c) using namespace std; const int N=105+5; const int MOD=1e9+7; typedef long long ll; typedef long double ld; ll n, m, stx, sty, k, dp[2][N][N], arr[N][N]; int main() { inlld2(n, m); inlld2(stx, sty); inlld(k); for(ll a=1; a<=n; a++) for(ll b=1; b<=m; b++) { inlld(arr[a][b]); for(ll c=0; c<=n+m; c++) dp[c][a][b]=-1e18; } dp[0][stx][sty]=0; for(ll steps=1; steps<=min(k/2, n*m-1); steps++) for(ll a=1; a<=n; a++) for(ll b=1; b<=m; b++) { if(a>1) dp[steps%2][a][b]=max(dp[steps%2][a][b], dp[(steps-1)%2][a-1][b]+arr[a][b]); if(b>1) dp[steps%2][a][b]=max(dp[steps%2][a][b], dp[(steps-1)%2][a][b-1]+arr[a][b]); if(a<n) dp[steps%2][a][b]=max(dp[steps%2][a][b], dp[(steps-1)%2][a+1][b]+arr[a][b]); if(b<m) dp[steps%2][a][b]=max(dp[steps%2][a][b], dp[(steps-1)%2][a][b+1]+arr[a][b]); // printf("%lld %lld %lld %lld\n", steps, a, b, dp[steps][a][b]); } if(k/2<=n*m-1) { ll ans=0; for(ll a=1; a<=n; a++) for(ll b=1; b<=m; b++) ans=max(ans, 2*dp[(k/2)%2][a][b]-arr[a][b]); printf("%lld\n", ans); return 0; } ll ans=0; for(ll a=1; a<=n; a++) for(ll b=1; b<=m; b++) { ll here=dp[(n*m-1)%2][a][b]; ll toadd=0; if(a>1) toadd=max(toadd, arr[a-1][b]); if(a<n) toadd=max(toadd, arr[a+1][b]); if(b<m) toadd=max(toadd, arr[a][b+1]); if(b>1) toadd=max(toadd, arr[a][b-1]); ans=max(ans, 2*here+((k-2*n*m+2)*(toadd+arr[a][b]))/2-2*arr[a][b]); } printf("%lld\n", ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 576 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 576 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 576 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 21 ms | 576 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 576 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 111 ms | 832 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 16 ms | 832 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 8 ms | 832 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 13 ms | 872 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |