Submission #3895415


Source Code Expand

Copy
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
  #define debug(...) printf(__VA_ARGS__)
#else
  #define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MAXN = 2e5 + 100;
ll X[MAXN];
ll preX[MAXN];
ll sufX[MAXN];

int main() {
  ll L;
  int N;
  scanf("%lld%d", &L, &N);
  for (int i = 0; i < N; i++)
    scanf("%lld", &X[i]);
  preX[0] = X[0];
  for (int i = 1; i < N; i++)
    preX[i] = preX[i - 1] + X[i];
  sufX[0] = L - X[0];
  for (int i = 1; i < N; i++)
    sufX[i] = sufX[i - 1] + (L - X[i]);

  ll ans = 0;
  for (int lst = 0; lst < N; lst++) {
    do {
      ll sum = X[lst];
      int l = lst;
      int r = N - lst - 1;
      l = min(l, r);
      r = min(r, l + 1);
      if (l < 0)
        break;
      sum += 2 * ((lst - 1 >= 0 ? preX[lst - 1] : 0) - (lst - l - 1 >= 0 ? preX[lst - l - 1] : 0));
      debug("sum %lld\n", sum);
      sum += 2 * (sufX[lst + r] - sufX[lst]);
      debug("sum %lld\n", sum);
      debug("lst %d  %lld (%d %d)\n", lst, sum, l, r);
      ans = max(ans, sum);
    } while (0);
    do {
      ll sum = L - X[lst];
      int l = lst;
      int r = N - lst - 1;
      l = min(l, r + 1);
      r = min(r, l);
      if (r < 0)
        break;
      sum += 2 * (preX[lst - 1] - (lst - l - 1 >= 0 ? preX[lst - l - 1] : 0));
      sum += 2 * (sufX[lst + r] - sufX[lst]);
      debug("lst %d  %lld (%d %d)\n", lst, sum, l, r);
      ans = max(ans, sum);
    } while (0);
  }
  cout << ans << endl;
  return 0;
}

Submission Info

Submission Time
Task B - Tree Burning
User t1016d
Language C++14 (GCC 5.4.1)
Score 800
Code Size 1732 Byte
Status AC
Exec Time 27 ms
Memory 4992 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:26:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%d", &L, &N);
                          ^
./Main.cpp:28:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld", &X[i]);
                         ^

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 300 / 300 500 / 500
Status
AC × 3
AC × 29
AC × 43
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
Subtask1 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 39.txt, 40.txt, s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 2 ms 2304 KB
02.txt AC 2 ms 2304 KB
03.txt AC 2 ms 2304 KB
04.txt AC 2 ms 2304 KB
05.txt AC 2 ms 2304 KB
06.txt AC 2 ms 2304 KB
07.txt AC 2 ms 2304 KB
08.txt AC 2 ms 2304 KB
09.txt AC 2 ms 2304 KB
10.txt AC 2 ms 2304 KB
11.txt AC 2 ms 2304 KB
12.txt AC 2 ms 2304 KB
13.txt AC 2 ms 2304 KB
14.txt AC 2 ms 2304 KB
15.txt AC 2 ms 2304 KB
16.txt AC 2 ms 2304 KB
17.txt AC 2 ms 2304 KB
18.txt AC 2 ms 2304 KB
19.txt AC 2 ms 2304 KB
20.txt AC 2 ms 2304 KB
21.txt AC 2 ms 2304 KB
22.txt AC 2 ms 2304 KB
23.txt AC 2 ms 2304 KB
24.txt AC 2 ms 2304 KB
25.txt AC 27 ms 4992 KB
26.txt AC 27 ms 4992 KB
27.txt AC 27 ms 4992 KB
28.txt AC 27 ms 4992 KB
29.txt AC 27 ms 4992 KB
30.txt AC 27 ms 4992 KB
31.txt AC 26 ms 4992 KB
32.txt AC 27 ms 4992 KB
33.txt AC 27 ms 4992 KB
34.txt AC 25 ms 4992 KB
35.txt AC 27 ms 4992 KB
36.txt AC 27 ms 4992 KB
37.txt AC 27 ms 4992 KB
38.txt AC 24 ms 4992 KB
39.txt AC 2 ms 2304 KB
40.txt AC 2 ms 2304 KB
s1.txt AC 2 ms 2304 KB
s2.txt AC 2 ms 2304 KB
s3.txt AC 2 ms 2304 KB