結果

問題 No.3252 Constrained Moving
ユーザー tnakao0123
提出日時 2025-09-06 12:17:34
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 604 bytes
コンパイル時間 435 ms
コンパイル使用メモリ 41,808 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-09-06 12:17:37
合計ジャッジ時間 3,016 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:27:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   27 |   scanf("%d%d%d%d", &n, &s, &t, &k);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:29:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |   for (int i = 0; i < n; i++) scanf("%d", as + i);
      |                               ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 3252.cc:  No.3252 Constrained Moving - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

/* global variables */

int as[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, s, t, k;
  scanf("%d%d%d%d", &n, &s, &t, &k);
  s--, t--;
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  if (as[s] + as[t] <= k) puts("1");
  else {
    int mina = *min_element(as, as + n);
    if (as[s] + mina <= k && mina + as[t] <= k)
      puts("2");
    else
      puts("-1");
  }

  return 0;
}
0