Submission #971723

# Submission time Handle Problem Language Result Execution time Memory
971723 2024-04-29T08:16:47 Z nguyentunglam Measures (CEOI22_measures) C++17
10 / 100
1500 ms 3920 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;

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 = [&] () {
    for(int i = 1; i <= n; i++) 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;
  };

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



Compilation message

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 time Memory Grader output
1 Correct 296 ms 348 KB Output is correct
2 Correct 322 ms 468 KB Output is correct
3 Correct 248 ms 476 KB Output is correct
4 Correct 298 ms 484 KB Output is correct
5 Correct 342 ms 596 KB Output is correct
6 Correct 319 ms 504 KB Output is correct
7 Correct 292 ms 344 KB Output is correct
8 Correct 288 ms 476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 296 ms 348 KB Output is correct
2 Correct 322 ms 468 KB Output is correct
3 Correct 248 ms 476 KB Output is correct
4 Correct 298 ms 484 KB Output is correct
5 Correct 342 ms 596 KB Output is correct
6 Correct 319 ms 504 KB Output is correct
7 Correct 292 ms 344 KB Output is correct
8 Correct 288 ms 476 KB Output is correct
9 Execution timed out 1590 ms 3920 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1560 ms 460 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1560 ms 460 KB Time limit exceeded
2 Halted 0 ms 0 KB -