답안 #668422

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
668422 2022-12-03T20:29:36 Z 600Mihnea Safety (NOI18_safety) C++17
66 / 100
2000 ms 612 KB
#include <bits/stdc++.h>


using namespace std;

#define int long long


signed main()
{
#ifdef ONPC
  freopen ("input.txt", "r", stdin);
#endif // ONPC

#ifndef ONPC
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif // ONPC

  int n, dmax, sol = 0, lazy = 0;
  cin >> n >> dmax;

  vector<int> a, b;

  for (int i = 0; i < n; i++)
  {
    int x;
    cin >> x;
    if (i == 0)
    {
      a.push_back(x);
      b.push_back(x);
      continue;
    }
    lazy += dmax;
    for (auto &it : b)
    {
      it += dmax;
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    if (x <= a.back() - lazy)
    {
      sol += a.back() - lazy - x;
      b.push_back(a.back() - lazy);
      a.pop_back();
      a.push_back(x + lazy);
      a.push_back(x + lazy);
    }
    else
    {
      if (x >= b[0])
      {
        sol += x - b[0];
        a.push_back(b[0] + lazy);
        reverse(b.begin(), b.end());
        b.pop_back();
        b.push_back(x);
        b.push_back(x);
      }
      else
      {
        a.push_back(x + lazy);
        b.push_back(x);
      }
    }
  }
  cout << sol << "\n";


  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2069 ms 612 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 4 ms 212 KB Output is correct
14 Correct 7 ms 212 KB Output is correct
15 Correct 5 ms 328 KB Output is correct
16 Correct 4 ms 212 KB Output is correct
17 Correct 4 ms 212 KB Output is correct
18 Correct 3 ms 212 KB Output is correct
19 Correct 4 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 4 ms 212 KB Output is correct
14 Correct 7 ms 212 KB Output is correct
15 Correct 5 ms 328 KB Output is correct
16 Correct 4 ms 212 KB Output is correct
17 Correct 4 ms 212 KB Output is correct
18 Correct 3 ms 212 KB Output is correct
19 Correct 4 ms 212 KB Output is correct
20 Correct 5 ms 340 KB Output is correct
21 Correct 5 ms 212 KB Output is correct
22 Correct 4 ms 212 KB Output is correct
23 Correct 3 ms 320 KB Output is correct
24 Correct 4 ms 212 KB Output is correct
25 Correct 4 ms 212 KB Output is correct
26 Correct 4 ms 212 KB Output is correct
27 Correct 5 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 4 ms 212 KB Output is correct
14 Correct 7 ms 212 KB Output is correct
15 Correct 5 ms 328 KB Output is correct
16 Correct 4 ms 212 KB Output is correct
17 Correct 4 ms 212 KB Output is correct
18 Correct 3 ms 212 KB Output is correct
19 Correct 4 ms 212 KB Output is correct
20 Correct 5 ms 340 KB Output is correct
21 Correct 5 ms 212 KB Output is correct
22 Correct 4 ms 212 KB Output is correct
23 Correct 3 ms 320 KB Output is correct
24 Correct 4 ms 212 KB Output is correct
25 Correct 4 ms 212 KB Output is correct
26 Correct 4 ms 212 KB Output is correct
27 Correct 5 ms 212 KB Output is correct
28 Correct 657 ms 544 KB Output is correct
29 Correct 542 ms 492 KB Output is correct
30 Correct 574 ms 460 KB Output is correct
31 Correct 501 ms 392 KB Output is correct
32 Correct 508 ms 512 KB Output is correct
33 Correct 523 ms 600 KB Output is correct
34 Correct 735 ms 472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 4 ms 212 KB Output is correct
20 Correct 7 ms 212 KB Output is correct
21 Correct 5 ms 328 KB Output is correct
22 Correct 4 ms 212 KB Output is correct
23 Correct 4 ms 212 KB Output is correct
24 Correct 3 ms 212 KB Output is correct
25 Correct 4 ms 212 KB Output is correct
26 Correct 5 ms 340 KB Output is correct
27 Correct 5 ms 212 KB Output is correct
28 Correct 4 ms 212 KB Output is correct
29 Correct 3 ms 320 KB Output is correct
30 Correct 4 ms 212 KB Output is correct
31 Correct 4 ms 212 KB Output is correct
32 Correct 4 ms 212 KB Output is correct
33 Correct 5 ms 212 KB Output is correct
34 Correct 657 ms 544 KB Output is correct
35 Correct 542 ms 492 KB Output is correct
36 Correct 574 ms 460 KB Output is correct
37 Correct 501 ms 392 KB Output is correct
38 Correct 508 ms 512 KB Output is correct
39 Correct 523 ms 600 KB Output is correct
40 Correct 735 ms 472 KB Output is correct
41 Correct 776 ms 476 KB Output is correct
42 Correct 443 ms 348 KB Output is correct
43 Correct 696 ms 360 KB Output is correct
44 Correct 591 ms 376 KB Output is correct
45 Correct 611 ms 472 KB Output is correct
46 Correct 526 ms 420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Execution timed out 2069 ms 612 KB Time limit exceeded
20 Halted 0 ms 0 KB -