結果

問題 No.2142 Segment Zero
ユーザー kakel-san
提出日時 2023-09-17 20:05:17
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 226 ms / 2,000 ms
コード長 781 bytes
コンパイル時間 1,998 ms
コンパイル使用メモリ 105,344 KB
実行使用メモリ 62,256 KB
最終ジャッジ日時 2024-07-04 14:19:51
合計ジャッジ時間 7,976 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 35
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static int NN => int.Parse(ReadLine());
    static long[] NList => ReadLine().Split().Select(long.Parse).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, k) = (c[0], c[1]);
        var rest = n * (n + 1) / 2 - k;
        var set = new HashSet<long>();
        set.Add(0);
        for (var i = 1L; i <= n; ++i)
        {
            var d = i * (i + 1) / 2;
            if (set.Contains(d - rest))
            {
                WriteLine(1);
                return;
            }
            set.Add(d);
        }
        WriteLine(2);
    }
}
0