/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 580.0 KiB
#2 Accepted 1ms 576.0 KiB
#3 Accepted 40ms 592.0 KiB
#4 Accepted 25ms 612.0 KiB
#5 Accepted 37ms 596.0 KiB
#6 Accepted 42ms 576.0 KiB
#7 Accepted 50ms 580.0 KiB
#8 Accepted 48ms 3.316 MiB
#9 Accepted 38ms 3.066 MiB

Code

#include <bits/stdc++.h>
using namespace std;

#define int long long

const int mx = 2e5+9;
const int mn = -1e15;

int a[3][mx], n;
int dp[mx][3][2];

int dyno (int x, int y, int z) {
  if (y == n+1) return mn;
  else if (x == 2 && y == n) return a[x][y];
  else if (dp[y][x][z] != LLONG_MIN) return dp[y][x][z];
  int ans;
  if (z) {
      ans = a[x][y]+max(dyno(x, y+1, 0), dyno(x, y+1, 1));
      if (x == 1) ans = max (ans, a[x][y]+dyno(2, y, 1));
  }
  else {
      ans = -1LL*y+max(dyno(x, y+1, 0), dyno(x, y+1, 1));
  }
  return dp[y][x][z] = ans;
}

int32_t main () {
  cin.tie(0)->sync_with_stdio(0);
  int t = 1;
  cin >> t;
  while (t--) {
      cin >> n;
      for (int i = 1; i <= n; i++) cin >> a[1][i];
      for (int i = 1; i <= n; i++) cin >> a[2][i];
      for (int i = 1; i <= n+1; i++) {
          for (int j = 0; j <= 2; j++) {
              dp[i][j][0] = dp[i][j][1] = LLONG_MIN;
          }
      }
      cout << dyno (1, 1, 1) << "\n";
  }
}

Information

Submit By
Type
Submission
Problem
P1050 Game on 2d grid
Contest
Brain Booster #3
Language
C++20 (G++ 13.2.0)
Submit At
2024-05-06 16:12:21
Judged At
2024-10-03 13:50:40
Judged By
Score
100
Total Time
50ms
Peak Memory
3.316 MiB