답안 #971720

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
971720 2024-04-29T08:12:49 Z nguyentunglam Measures (CEOI22_measures) C++17
0 / 100
1500 ms 348 KB
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;

const int N = 2e5 + 30;

int n, m, d;

int a[N];

int32_t main() {
  #define task ""

  cin.tie(0) -> sync_with_stdio(0);

  if (fopen("task.inp", "r")) {
    freopen("task.inp", "r", stdin);
    freopen("task.out", "w", stdout);
  }

  if (fopen(task".inp", "r")) {
    freopen (task".inp", "r", stdin);
    freopen (task".out", "w", stdout);
  }

  cin >> n >> m >> d;

  d *= 2;

  for(int i = 1; i <= n; i++) cin >> a[i], a[i] *= 2;

  auto calc = [&] () {
    for(int i = 1; i <= n; i++) sort(a + 1, a + n + 1);

    auto check = [&] (int time) {
      int last = -1e9;
      for(int i = 1; i <= n; i++) {
        if (a[i] + time < last + d) return false;
        last =  max(last + d, a[i] - time);
      }
    };

    int l = 0, r = 2e9, last = -1;
    while (l <= r) {
      int mid = l + r >> 1;
      if (check(mid)) {
        last = mid;
        r = mid - 1;
      }
      else l = mid + 1;
    }
    return last;
  };

  while (m--) {
    ++n;
    cin >> a[n];
    a[n] *= 2;
    int ret = calc();
    cout << ret / 2;
    if (ret % 2) cout << ".5";
    cout << " ";
  }
}



Compilation message

Main.cpp: In lambda function:
Main.cpp:46:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |       int mid = l + r >> 1;
      |                 ~~^~~
Main.cpp: In function 'int32_t main()':
Main.cpp:18:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     freopen("task.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     freopen("task.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:23:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     freopen (task".inp", "r", stdin);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:24:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     freopen (task".out", "w", stdout);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In lambda function:
Main.cpp:42:5: warning: control reaches end of non-void function [-Wreturn-type]
   42 |     };
      |     ^
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1554 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1554 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1543 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1543 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -