QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#93950#6190. Graph ProblemScintillaWA 2ms3548kbC++141.4kb2023-04-04 10:39:292023-04-04 10:39:33

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-04 10:39:33]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3548kb
  • [2023-04-04 10:39:29]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define rep(i, s, e) for (int i = s; i <= e; ++i)
#define drep(i, s, e) for (int i = s; i >= e; --i)
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)
#define pv(a) cout << #a << " = " << a << endl
#define pa(a, l, r) cout << #a " : "; rep(_, l, r) cout << a[_] << ' '; cout << endl

const int INF = 1e18;

const int N = 1e5 + 10;

int read() {
  int x = 0, f = 1; char c = getchar();
  for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48;
  return x * f;
}

int n, a[N], f[N][2][2][2], ans;

signed main() {
  for (int tc = read(); tc; -- tc) {
    n = read(), ans = -INF;
    rep(i, 1, n) a[i] = read();
    rep(i, 2, n) rep(x, 0, 1) rep(y, 0, 1) rep(z, 0, 1) f[i][x][y][z] = -INF;
    f[1][0][0][0] = 0, f[1][1][1][0] = a[1];
    rep(i, 1, n - 1) rep(j, -1, 1) rep(x, 0, 1) rep(y, 0, 1) rep(z, 0, 1) if (max(x, i + 1 & 1 ? y : z) + j <= 1) {
      int nx = max(max(x + j, j), 0ll), ny = i + 1 & 1 ? (max(max(y + j, j), 0ll)) : y, nz = i + 1 & 1 ? z : max(max(z + j, j), 0ll);
      f[i + 1][nx][ny][nz] = max(f[i + 1][nx][ny][nz], f[i][x][y][z] + j * a[i + 1]);
    }
    rep(x, 0, 1) rep(y, 0, 1) rep(z, 0, 1) ans = max(ans, f[n][x][y][z]);
    printf("%lld\n", ans);
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3548kb

input:

5 4
1 2
2 3
3 4
4 5
2
1 4
2 1 5 1 3
3 5 3 4
1 1 2

output:

3
5
4
5
3

result:

wrong answer 1st lines differ - expected: '01', found: '3'