/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 580.0 KiB
#2 Wrong Answer 1ms 568.0 KiB
#3 Wrong Answer 42ms 648.0 KiB
#4 Wrong Answer 26ms 672.0 KiB
#5 Wrong Answer 38ms 612.0 KiB
#6 Wrong Answer 43ms 700.0 KiB
#7 Wrong Answer 52ms 712.0 KiB
#8 Accepted 50ms 3.316 MiB
#9 Accepted 39ms 3.312 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]+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-10-03 13:50:46
Judged By
Score
40
Total Time
52ms
Peak Memory
3.316 MiB