結果

問題 No.2132 1 or X Game
ユーザー kotatsugamekotatsugame
提出日時 2022-11-25 22:16:13
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 611 bytes
コンパイル時間 123 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,800 KB
最終ジャッジ日時 2024-04-10 03:25:54
合計ジャッジ時間 15,170 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
12,416 KB
testcase_01 WA -
testcase_02 AC 1,266 ms
12,416 KB
testcase_03 WA -
testcase_04 AC 1,272 ms
12,672 KB
testcase_05 AC 1,198 ms
12,672 KB
testcase_06 AC 1,165 ms
12,544 KB
testcase_07 AC 1,185 ms
12,544 KB
testcase_08 AC 1,184 ms
12,416 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

gets.to_i.times{
  n,x=gets.split.map &:to_i
  ans=0
  n+=1
  if x%2==1
    ans+=n/2
  else
    t=x*(x+1)
    ans+=n/t*(x/2*(x+2))
    n%=t
    if n<=x
      ans+=n/2
    else
      n-=x
      ans+=x/2
      if n<=x
        ans+=(n+1)/2
      else
        n-=x
        ans+=x/2
        t=n/x
        ans+=2*t
        ans+=(x/2-2)*t
        ans+=(t+1)/2
        n%=x
        if n<=t+1
          if t%2==0
            ans+=(n+1)/2
          else
            ans+=n/2
          end
        else
          ans+=(t+2)/2
          n-=t+1
          ans+=(n+1)/2
        end
      end
    end
  end
  p ans%998244353
}
0