結果

問題 No.2142 Segment Zero
コンテスト
ユーザー chro_96
提出日時 2022-12-02 21:51:43
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 699 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 139 ms
コンパイル使用メモリ 38,592 KB
最終ジャッジ日時 2026-02-22 09:50:15
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>

int main () {
  long long n = 0LL;
  long long k = 0LL;
  
  int res = 0;
  
  long long tmp = 0LL;
  
  res = scanf("%lld", &n);
  res = scanf("%lld", &k);
  
  k = (n*(n+1LL))/2LL-k;
  tmp = n;
  
  while (tmp > 0LL) {
    long long sum = (tmp*(tmp+1LL))/2LL;
    if (sum >= k) {
      long long lr[2] = { 0LL, tmp };
      while (lr[1] - lr[0] > 1LL) {
        long long nxt = (lr[0]+lr[1])/2LL;
        if ((nxt*(nxt+1LL))/2LL <= sum-k) {
          lr[0] = nxt;
        } else {
          lr[1] = nxt;
        }
      }
      if ((lr[0]*(lr[0]+1LL))/2LL == sum-k) {
        printf("1\n");
        return 0;
      }
    }
    tmp -= 1LL;
  }
  
  printf("2\n");
  return 0;
}
0