/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 46ms 584.0 KiB
#4 Accepted 34ms 592.0 KiB
#5 Accepted 39ms 568.0 KiB
#6 Accepted 45ms 648.0 KiB
#7 Accepted 49ms 596.0 KiB
#8 Accepted 49ms 1.305 MiB
#9 Accepted 37ms 1.301 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-11-11 03:32:39
Judged By
Score
100
Total Time
49ms
Peak Memory
1.305 MiB