제출 #971727

#제출 시각아이디문제언어결과실행 시간메모리
971727nguyentunglamMeasures (CEOI22_measures)C++17
24 / 100
1598 ms3964 KiB
#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;

long long 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 = [&] () {
    sort(a + 1, a + n + 1);

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

    long long l = 0, r = 1e17, last = -1;
    while (l <= r) {
      long long 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;
    long long ret = calc();
    cout << ret / 2;
    if (ret % 2) cout << ".5";
    cout << " ";
  }
}



컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In lambda function:
Main.cpp:48:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   48 |       long long 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);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...