답안 #348264

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
348264 2021-01-14T12:54:05 Z MrDomino Safety (NOI18_safety) C++14
33 / 100
2000 ms 1672 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define int ll

multiset<int> local_minimum(multiset<int> s, int h) {
  assert((int) s.size() % 2 == 0);
  multiset<int> s2;
  int slope = -(int) s.size() / 2;
  for (auto &x : s) {
    if (slope < 0) {
      s2.insert(x - h);
    }
    if (slope >= 0) {
      s2.insert(x + h);
    }
    slope++;
  }
  return s2;
}

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

vector<pair<int, int>> get(multiset<int> s, int a, int b) {
  vector<int> xs;
  for (auto &it : s) {
    xs.push_back(it);
  }
  int n = (int) xs.size();
  vector<pair<int, int>> ret;
  ret.push_back({a, b});
  for (int i = n - 1; i >= 0; i--) {
    /// (a - 1) * x + b2 = a * x + b
    /// a * x - x + b2 = a * x + b
    /// b2 - x = b
    /// b2 = x + b
    b += xs[i];
    a--;
    ret.push_back({a, b});
  }


  reverse(ret.begin(), ret.end());
  return ret;
}

const int c = 100;

void print(multiset<int> s, int b) {
  for (auto &x : s) {
    cout << x << " ";
  }
  cout << " :\n";
  int a = (int) s.size() / 2;

  /**

bug:
  3 1
7 7 7


  s.clear();
  s.insert(2);
  s.insert(8);
  s.insert(8);
  s.insert(8);
  b = -24;
  a = 4;**/

  vector<pair<int, int>> v = get(s, a, b);
  int last = -c;
  auto ko = s.begin();
  s.insert(+c);
  for (auto &it : v) {
    cout << "for x = " << last << "..." << *ko << " : ";
    last = *ko;
    ko++;
    cout << "f(x) = x * " << it.first << " + " << it.second << "\n";
  }
  cout << "\n";
}


int solve(multiset<int> s, int b) {
  int a = (int) s.size() / 2;
  vector<pair<int, int>> v = get(s, a, b);
  for (auto &it : v) {
    if (it.first == 0) {
      return it.second;
    }
  }
  assert(0);
}

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

  //freopen ("input", "r", stdin);

  multiset<int> s;
  int n, h, x, b = 0;
  cin >> n >> h >> x;
  s.insert(x);
  s.insert(x);
  b = -x;

  for (int i = 2; i <= n; i++) {
    s = local_minimum(s, h);
    cin >> x;
    b -= (i - 1) * h; /// I have no clue why this happens lol

    /**if (i == n) {
      cout << "lol\n";
      print(s, b);
      return 0;
    }**/

    s.insert(x);
    s.insert(x);
    auto it = s.end();
    it--;
    b -= x;
//    print(s, b);
//    cout << "\n";
  //  return 0;
  //  cout << " => " << b << "\n";
  //  print(s, b);
  //  return 0;
  }

  int a = (int) s.size() / 2;

  /**

bug:
  3 1
7 7 7


  s.clear();
  s.insert(2);
  s.insert(8);
  s.insert(8);
  s.insert(8);
  b = -24;
  a = 4;**/

  vector<pair<int, int>> v = get(s, a, b);
  for (auto &it : v)
 {

   if (it.first == 0) {
    cout << it.second << "\n";
   }
 } // print(s, b);

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2043 ms 1672 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 31 ms 492 KB Output is correct
14 Correct 29 ms 492 KB Output is correct
15 Correct 29 ms 492 KB Output is correct
16 Correct 31 ms 492 KB Output is correct
17 Correct 24 ms 492 KB Output is correct
18 Correct 16 ms 492 KB Output is correct
19 Correct 28 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 31 ms 492 KB Output is correct
14 Correct 29 ms 492 KB Output is correct
15 Correct 29 ms 492 KB Output is correct
16 Correct 31 ms 492 KB Output is correct
17 Correct 24 ms 492 KB Output is correct
18 Correct 16 ms 492 KB Output is correct
19 Correct 28 ms 492 KB Output is correct
20 Correct 29 ms 492 KB Output is correct
21 Correct 32 ms 492 KB Output is correct
22 Correct 21 ms 492 KB Output is correct
23 Correct 18 ms 492 KB Output is correct
24 Correct 27 ms 492 KB Output is correct
25 Correct 19 ms 492 KB Output is correct
26 Correct 31 ms 492 KB Output is correct
27 Correct 27 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 31 ms 492 KB Output is correct
14 Correct 29 ms 492 KB Output is correct
15 Correct 29 ms 492 KB Output is correct
16 Correct 31 ms 492 KB Output is correct
17 Correct 24 ms 492 KB Output is correct
18 Correct 16 ms 492 KB Output is correct
19 Correct 28 ms 492 KB Output is correct
20 Correct 29 ms 492 KB Output is correct
21 Correct 32 ms 492 KB Output is correct
22 Correct 21 ms 492 KB Output is correct
23 Correct 18 ms 492 KB Output is correct
24 Correct 27 ms 492 KB Output is correct
25 Correct 19 ms 492 KB Output is correct
26 Correct 31 ms 492 KB Output is correct
27 Correct 27 ms 492 KB Output is correct
28 Execution timed out 2084 ms 1400 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 31 ms 492 KB Output is correct
20 Correct 29 ms 492 KB Output is correct
21 Correct 29 ms 492 KB Output is correct
22 Correct 31 ms 492 KB Output is correct
23 Correct 24 ms 492 KB Output is correct
24 Correct 16 ms 492 KB Output is correct
25 Correct 28 ms 492 KB Output is correct
26 Correct 29 ms 492 KB Output is correct
27 Correct 32 ms 492 KB Output is correct
28 Correct 21 ms 492 KB Output is correct
29 Correct 18 ms 492 KB Output is correct
30 Correct 27 ms 492 KB Output is correct
31 Correct 19 ms 492 KB Output is correct
32 Correct 31 ms 492 KB Output is correct
33 Correct 27 ms 492 KB Output is correct
34 Execution timed out 2084 ms 1400 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Execution timed out 2043 ms 1672 KB Time limit exceeded
20 Halted 0 ms 0 KB -