結果

問題 No.2543 Many Meetings
ユーザー kusaf_kusaf_
提出日時 2023-12-08 11:37:38
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 898 bytes
コンパイル時間 3,408 ms
コンパイル使用メモリ 266,060 KB
実行使用メモリ 39,168 KB
最終ジャッジ日時 2023-12-08 11:37:47
合計ジャッジ時間 9,326 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 111 ms
39,168 KB
testcase_04 AC 111 ms
39,168 KB
testcase_05 AC 111 ms
39,168 KB
testcase_06 AC 109 ms
39,168 KB
testcase_07 AC 111 ms
39,168 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 76 ms
29,696 KB
testcase_29 AC 26 ms
12,160 KB
testcase_30 AC 25 ms
12,288 KB
testcase_31 AC 21 ms
10,752 KB
testcase_32 AC 69 ms
27,904 KB
testcase_33 AC 2 ms
6,676 KB
testcase_34 AC 1 ms
6,676 KB
testcase_35 AC 2 ms
6,676 KB
testcase_36 WA -
testcase_37 AC 1 ms
6,676 KB
testcase_38 AC 2 ms
6,676 KB
testcase_39 WA -
testcase_40 AC 2 ms
6,676 KB
testcase_41 AC 1 ms
6,676 KB
testcase_42 AC 1 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

  ll N, K;
  cin >> N >> K;

  vector<pair<ll, ll>> v(N);
  for(auto &[x, y] : v) { cin >> x >> y; }
  ranges::sort(v);

  vector<vector<ll>> nxt(20, vector<ll>(N, -1));
  for(ll i = 0; i < N; i++) {
    auto it = ranges::lower_bound(v, make_pair(v[i].second, 0LL));
    if(it != v.end()) { nxt[0][i] = it - v.begin(); }
  }

  for(ll i = 0; i < 20; i++) {
    for(ll j = 0; j < N; j++) {
      if(nxt[i][j] == -1) { continue; }
      nxt[i + 1][j] = nxt[i][nxt[i][j]];
    }
  }

  ll r = 1e18;
  for(ll i = 0; i < N; i++) {
    ll k = K - 1, cur = i;
    while(k && cur != -1) {
      ll t = __builtin_ctz(k);
      cur = nxt[t][cur];
      k ^= 1 << t;
    }
    if(cur != -1) { r = min(r, v[cur].second - v[i].first); }
  }

  cout << (r == 1e18 ? -1 : r) << "\n";
}
0