結果

問題 No.2142 Segment Zero
ユーザー tnakao0123
提出日時 2022-12-03 17:08:41
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 555 bytes
コンパイル時間 352 ms
コンパイル使用メモリ 41,544 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-10 19:37:29
合計ジャッジ時間 1,410 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2142.cc:  No.2142 Segment Zero - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 1000000;

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

/* main */

int main() {
  int n;
  ll k;
  scanf("%d%lld", &n, &k);

  ll r = (ll)k * (k + 1) / 2 - k;
  ll sum = 0;

  for (int i = 1, j = 1; i <= n; i++) {
    while (j <= n && sum < r) sum += j++;
    if (sum == r) { puts("1"); return 0; }
    sum -= i;
  }

  puts("2");
  return 0;
}
0