/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 4ms 4.555 MiB
#2 Accepted 3ms 4.559 MiB
#3 Accepted 77ms 4.566 MiB
#4 Accepted 48ms 4.598 MiB
#5 Accepted 67ms 4.574 MiB
#6 Accepted 76ms 6.664 MiB
#7 Accepted 93ms 4.672 MiB
#8 Accepted 92ms 8.992 MiB
#9 Accepted 67ms 8.371 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-11-11 03:33:20
Judged By
Score
100
Total Time
93ms
Peak Memory
8.992 MiB