/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 1ms 576.0 KiB
#3 Wrong Answer 44ms 876.0 KiB

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]+max(dyno(2, y, 0), 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:08:32
Judged At
2024-11-11 03:33:25
Judged By
Score
0
Total Time
44ms
Peak Memory
876.0 KiB