結果

問題 No.1742 Binary Indexed Train
ユーザー 👑 kakel-sankakel-san
提出日時 2023-12-29 14:20:55
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 644 ms / 3,000 ms
コード長 1,693 bytes
コンパイル時間 7,496 ms
コンパイル使用メモリ 158,544 KB
実行使用メモリ 211,996 KB
最終ジャッジ日時 2023-12-29 14:21:17
合計ジャッジ時間 22,036 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
33,060 KB
testcase_01 AC 80 ms
33,060 KB
testcase_02 AC 80 ms
33,060 KB
testcase_03 AC 408 ms
67,752 KB
testcase_04 AC 387 ms
67,752 KB
testcase_05 AC 383 ms
67,752 KB
testcase_06 AC 186 ms
64,112 KB
testcase_07 AC 196 ms
64,112 KB
testcase_08 AC 620 ms
66,856 KB
testcase_09 AC 642 ms
66,856 KB
testcase_10 AC 618 ms
66,984 KB
testcase_11 AC 644 ms
66,856 KB
testcase_12 AC 620 ms
66,856 KB
testcase_13 AC 388 ms
68,052 KB
testcase_14 AC 369 ms
68,052 KB
testcase_15 AC 167 ms
55,588 KB
testcase_16 AC 164 ms
52,004 KB
testcase_17 AC 335 ms
68,240 KB
testcase_18 AC 318 ms
67,688 KB
testcase_19 AC 180 ms
60,968 KB
testcase_20 AC 89 ms
35,748 KB
testcase_21 AC 190 ms
59,684 KB
testcase_22 AC 360 ms
67,916 KB
testcase_23 AC 103 ms
39,076 KB
testcase_24 AC 89 ms
35,876 KB
testcase_25 AC 351 ms
63,360 KB
testcase_26 AC 200 ms
61,492 KB
testcase_27 AC 330 ms
62,896 KB
testcase_28 AC 100 ms
39,204 KB
testcase_29 AC 363 ms
66,484 KB
testcase_30 AC 187 ms
59,940 KB
testcase_31 AC 375 ms
67,724 KB
testcase_32 AC 210 ms
59,812 KB
testcase_33 AC 118 ms
45,732 KB
testcase_34 AC 264 ms
211,996 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (105 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

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();
    static long[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, q) = ((int)c[0], (int)c[1]);
        var query = NArr(q);
        var ans = new List<int>(q);
        foreach (var que in query)
        {
            var s = Pop(que[0]);
            var t = Pop(que[1]);
            while (s.Count > 0 && t.Count > 0 && s[0] == t[0])
            {
                s.RemoveAt(0);
                t.RemoveAt(0);
            }
            var ai = 0;
            while (true)
            {
                if (s.Count == 0 || (s.Count == 1 && s[0] == t[0])) break;
                ++ai;
                var cur = s[^1];
                s.RemoveAt(s.Count - 1);
                while (s.Count > 0 && s[^1] == cur + 1)
                {
                    ++cur;
                    s.RemoveAt(s.Count - 1);
                }
                s.Add(cur + 1);
            }
            ans.Add(ai + t.Count - s.Count);
        }
        WriteLine(string.Join("\n", ans));
    }
    static List<int> Pop(long a)
    {
        var ans = new List<int>();
        var pos = 0;
        while (a > 0)
        {
            if (a % 2 == 1) ans.Add(pos);
            a >>= 1;
            ++pos;
        }
        ans.Reverse();
        return ans;
    }
}
0