/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 496.0 KiB
#2 Accepted 2ms 332.0 KiB
#3 Accepted 74ms 660.0 KiB
#4 Accepted 58ms 668.0 KiB
#5 Accepted 62ms 612.0 KiB
#6 Accepted 75ms 596.0 KiB
#7 Accepted 77ms 604.0 KiB
#8 Accepted 76ms 1.301 MiB
#9 Accepted 54ms 1.238 MiB

Code


#include <bits/stdc++.h>

#ifdef LOCAL
#include "../algo/debug.h"
#else 
#define debug(...) 0
#endif

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    vector a(2, vector<long long> (n + 1));
    for (int j = 0; j < 2; j++) {
      for (int i = 1; i <= n; i++) {
        cin >> a[j][i];
      }
    }
    long long inf = 8e18;
    vector f(2, vector<long long> (n + 1, -inf));
    for (int j = 0; j < 2; j++) {
      long long mx = -inf;
      for (int i = 1; i <= n; i++) {
        if (i == 1 && j == 0) {
          f[j][i] = a[j][i] * 2;
          continue;
        }
        if (i > 1) {
          f[j][i] = max(f[j][i], f[j][i - 1] + a[j][i] * 2);
        }
        if (j > 0) {
          f[j][i] = max(f[j][i], f[j - 1][i] + a[j][i] * 2);
        }
        if (i > 1) {
          mx = max(mx, f[j][i - 1] + i - 1 + (i - 1) * 1ll * (i - 1));
          f[j][i] = max(f[j][i], mx - i * 1ll * i + i + a[j][i] * 2);
        }
      }
    }
    cout << f[1][n] / 2 << '\n';
  }
  return 0;
}

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:57:07
Judged At
2024-10-03 13:49:21
Judged By
Score
100
Total Time
77ms
Peak Memory
1.301 MiB