結果

問題 No.3513 Greedy Yokan Party
コンテスト
ユーザー tnakao0123
提出日時 2026-04-25 17:03:34
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 1,058 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 422 ms
コンパイル使用メモリ 54,320 KB
実行使用メモリ 7,040 KB
最終ジャッジ日時 2026-04-25 17:03:45
合計ジャッジ時間 11,152 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 3513.cc:  No.3513 Greedy Yokan Party  - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

/* global variables */

int as[MAX_N + 2];
int dp[MAX_N + 2][3];

/* subroutines */

void setmax(int &a, int b) { if (a < b) a = b; }

int calc(int n, int x) {
  for (int i = 0; i <= n; i++) fill(dp[i], dp[i] + 3, -1);
  dp[0][0] = 0;
  for (int i = 0, i1 = 0; i < n; i++) {
    while (i1 < n && as[i1] - as[i] < x) i1++;
    for (int j = 0; j <= 2; j++)
      if (dp[i][j] >= 0) {
	setmax(dp[i + 1][j], dp[i][j] + 1);
	if (j < 2 && as[i1] - as[i] >= x)
	  setmax(dp[i1][j + 1], dp[i][j] + 1);
      }
  }
  return dp[n][2];
}

/* main */

int main() {
  int n, l, k;
  scanf("%d%d%d", &n, &l, &k);
  as[0] = 0, as[n + 1] = l;
  for (int i = 1; i <= n; i++) scanf("%d", as + i);
  n++;

  int x0 = 0, x1 = l;
  while (x0 + 1 < x1) {
    int x = (x0 + x1) / 2;
    if (calc(n, x) > k) x0 = x;
    else x1 = x;
  }

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

0