답안 #348277

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
348277 2021-01-14T13:19:48 Z MrDomino Safety (NOI18_safety) C++14
71 / 100
476 ms 62988 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define int ll

multiset<int> form(multiset<int> s1, multiset<int> s2, int add1, int add2) {
  multiset<int> s;
  for (auto &x : s1) {
    s.insert(x + add1);
  }
  for (auto &x : s2) {
    s.insert(x + add2);
  }
  return s;
}

void print(multiset<int> s) {
  cout << " : ";
  for (auto &x : s) {
    cout << x << " ";
  }
  cout << "\n";
}


int get(multiset<int> s, int a, int b) {
  int n = (int) s.size();
  vector<int> xs;
  for (auto &it : s) {
    xs.push_back(it);
  }
  for (int i = n - 1; i >= 0; i--) {
    b += xs[i];
    a--;
    if (a == 0) {
      return b;
    }
  }
  assert(0);
}



signed main() {
  ios::sync_with_stdio(0); cin.tie(0);

  multiset<int> s1, s2;
  int n, h, x, b = 0, add1 = 0, add2 = 0;
  cin >> n >> h >> x;
  s1.insert(x);
  s2.insert(x);
  b = -x;
  b -= h * (n - 1) * n / 2;

  for (int i = 2; i <= n; i++) {
    add1 -= h;
    add2 += h;
    int cut = *s2.begin() + add2;
    int x;
    cin >> x;
    b -= x;
    if (x < cut) {
      s1.insert(x - add1);
      s1.insert(x - add1);
      auto it = s1.end();
      it--;
      int val = *it + add1;
      s1.erase(it);
      s2.insert(val - add2);
    } else {
      s2.insert(x - add2);
      s2.insert(x - add2);
      auto it = s2.begin();
      int val = *it + add2;
      s2.erase(it);
      s1.insert(val - add1);
    }
  }
  multiset<int> s = form(s1, s2, add1, add2);
  cout << get(s, (int) s.size() / 2, b) << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 266 ms 42716 KB Output is correct
2 Correct 401 ms 59136 KB Output is correct
3 Correct 432 ms 61532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 6 ms 1900 KB Output is correct
29 Correct 6 ms 1772 KB Output is correct
30 Correct 6 ms 1900 KB Output is correct
31 Correct 5 ms 1644 KB Output is correct
32 Correct 5 ms 1644 KB Output is correct
33 Correct 6 ms 2048 KB Output is correct
34 Correct 6 ms 1900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 0 ms 364 KB Output is correct
17 Correct 0 ms 364 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 6 ms 1900 KB Output is correct
35 Correct 6 ms 1772 KB Output is correct
36 Correct 6 ms 1900 KB Output is correct
37 Correct 5 ms 1644 KB Output is correct
38 Correct 5 ms 1644 KB Output is correct
39 Correct 6 ms 2048 KB Output is correct
40 Correct 6 ms 1900 KB Output is correct
41 Correct 7 ms 2028 KB Output is correct
42 Correct 5 ms 1644 KB Output is correct
43 Correct 6 ms 1900 KB Output is correct
44 Correct 6 ms 1900 KB Output is correct
45 Correct 5 ms 1900 KB Output is correct
46 Correct 5 ms 1772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 0 ms 364 KB Output is correct
17 Correct 0 ms 364 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 266 ms 42716 KB Output is correct
20 Correct 401 ms 59136 KB Output is correct
21 Correct 432 ms 61532 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 1 ms 492 KB Output is correct
35 Correct 1 ms 492 KB Output is correct
36 Correct 1 ms 492 KB Output is correct
37 Correct 6 ms 1900 KB Output is correct
38 Correct 6 ms 1772 KB Output is correct
39 Correct 6 ms 1900 KB Output is correct
40 Correct 5 ms 1644 KB Output is correct
41 Correct 5 ms 1644 KB Output is correct
42 Correct 6 ms 2048 KB Output is correct
43 Correct 6 ms 1900 KB Output is correct
44 Correct 7 ms 2028 KB Output is correct
45 Correct 5 ms 1644 KB Output is correct
46 Correct 6 ms 1900 KB Output is correct
47 Correct 6 ms 1900 KB Output is correct
48 Correct 5 ms 1900 KB Output is correct
49 Correct 5 ms 1772 KB Output is correct
50 Correct 476 ms 62988 KB Output is correct
51 Correct 356 ms 52832 KB Output is correct
52 Incorrect 244 ms 50908 KB Output isn't correct
53 Halted 0 ms 0 KB -