답안 #64004

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
64004 2018-08-03T08:14:24 Z Just_Solve_The_Problem Homecoming (BOI18_homecoming) C++11
13 / 100
1000 ms 110236 KB
#include "homecoming.h"
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const int N = (int)2e6 + 7;
const ll linf = (ll)1e18 + 7;

ll pref[N + N];
ll dp[N][2][2];

ll get(int l, int r) {
  if (!l) return pref[r];
  return pref[r] - pref[l - 1];
}

ll solve(int n, int k, int a[], int b[]) {
  pref[0] = b[0];
  for (int i = 0; i < n + n; i++) {
    pref[i + 1] = pref[i] + b[(i + 1) % n];
  }
  for (int i = 0; i < N; i++)
    for (int j = 0; j < 2; j++)
      for (int l = 0; l < 2; l++)
        dp[i][j][l] = -linf;
  dp[0][1][1] = a[0] - pref[k - 1];
  dp[0][0][0] = 0;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < 2; j++) {
      dp[i][0][j] = max(dp[i - 1][0][j], dp[i - 1][1][j]);
      if (j == 0 || i + k - 1 < n) {
        dp[i][1][j] = max(dp[i - 1][0][j] + a[i] - get(i, i + k - 1), dp[i - 1][1][j] + a[i] - b[(i + k - 1) % n]);
      } else {
        dp[i][1][j] = max(dp[i - 1][0][j] + a[i] - get(i, n - 1), dp[i - 1][1][j] + a[i]);
      }
//      cout << i << ' ' << j << ' ' << dp[i][0][j] << ' ' << dp[i][1][j] << endl;
    }
  }
  ll ans = 0;
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++)
      ans = max(ans, dp[n - 1][i][j]);
  return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 62968 KB Output is correct
2 Correct 65 ms 63076 KB Output is correct
3 Correct 271 ms 63132 KB Output is correct
4 Correct 63 ms 63132 KB Output is correct
5 Correct 101 ms 63220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 62968 KB Output is correct
2 Correct 65 ms 63076 KB Output is correct
3 Correct 271 ms 63132 KB Output is correct
4 Correct 63 ms 63132 KB Output is correct
5 Correct 101 ms 63220 KB Output is correct
6 Correct 66 ms 63288 KB Output is correct
7 Correct 62 ms 63288 KB Output is correct
8 Correct 109 ms 63288 KB Output is correct
9 Correct 64 ms 63336 KB Output is correct
10 Execution timed out 1078 ms 63336 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 75020 KB Output is correct
2 Correct 491 ms 75020 KB Output is correct
3 Correct 319 ms 110236 KB Output is correct
4 Correct 65 ms 110236 KB Output is correct
5 Execution timed out 1069 ms 110236 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 62968 KB Output is correct
2 Correct 65 ms 63076 KB Output is correct
3 Correct 271 ms 63132 KB Output is correct
4 Correct 63 ms 63132 KB Output is correct
5 Correct 101 ms 63220 KB Output is correct
6 Correct 66 ms 63288 KB Output is correct
7 Correct 62 ms 63288 KB Output is correct
8 Correct 109 ms 63288 KB Output is correct
9 Correct 64 ms 63336 KB Output is correct
10 Execution timed out 1078 ms 63336 KB Time limit exceeded