結果

問題 No.3325 陰陽師
コンテスト
ユーザー tnakao0123
提出日時 2025-11-07 11:58:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,341 bytes
コンパイル時間 583 ms
コンパイル使用メモリ 56,348 KB
実行使用メモリ 22,436 KB
最終ジャッジ日時 2025-11-07 11:58:39
合計ジャッジ時間 9,000 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 11 WA * 7 TLE * 6 -- * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:59:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   59 |   scanf("%d%d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~
main.cpp:60:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   60 |   for (int i = 0; i < n; i++) scanf("%d", ss + i);
      |                               ~~~~~^~~~~~~~~~~~~~
main.cpp:61:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   61 |   for (int i = 0; i < m; i++) scanf("%d", ts + i);
      |                               ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 3325.cc:  No.3325 髯ー髯ス蟶ォ - yukicoder
 */

#include<cstdio>
#include<set>
#include<algorithm>
#include<utility>

using namespace std;

/* constant */

const int MAX_N = 200000;
const int MAX_M = 200000;

/* typedef */

using msi = multiset<int>;
using pii = pair<int,int>;

/* global variables */

int ss[MAX_N], ts[MAX_M];

/* subroutines */

pii calcmax(int n, int m) {
  msi as(ss, ss + n);
  int maxd = 0;
  for (int i = 0; i < m; i++) {
    auto sit = as.lower_bound(ts[i]);
    if (sit != as.end()) {
      maxd = max(maxd, *sit - ts[i]);
      as.erase(sit);
    }
    else return {maxd, i};
  }
  return {maxd, m};
}

int calc(int n, int m, int d) {
  msi as(ss, ss + n);
  for (int i = 0; i < m; i++) {
    auto sit = as.upper_bound(ts[i] + d);
    if (sit == as.begin()) return i;
    sit--;
    if (*sit < ts[i]) return i;
    as.erase(sit);
  }
  return m;
}

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", ss + i);
  for (int i = 0; i < m; i++) scanf("%d", ts + i);

  auto [maxd, maxx] = calcmax(n, m);
  //printf(" maxd=%d,maxx=%d\n", maxd, maxx);

  int d0 = -1, d1 = maxd;
  while (d0 + 1 < d1) {
    int d = (d0 + d1) / 2;
    if (calc(n, m, d) >= maxx) d1 = d;
    else d0 = d;
  }

  printf("%d\n", d1);
  
  return 0;
}

0