結果

問題 No.2393 Bit Grid Connected Component
ユーザー InTheBloomInTheBloom
提出日時 2023-07-28 22:01:12
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 280 ms / 2,000 ms
コード長 934 bytes
コンパイル時間 1,611 ms
コンパイル使用メモリ 173,224 KB
実行使用メモリ 7,808 KB
最終ジャッジ日時 2024-04-16 05:56:03
合計ジャッジ時間 3,604 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 7 ms
6,940 KB
testcase_15 AC 10 ms
6,944 KB
testcase_16 AC 81 ms
6,940 KB
testcase_17 AC 248 ms
7,764 KB
testcase_18 AC 243 ms
7,808 KB
testcase_19 AC 280 ms
7,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main () {
    int T = readln.chomp.to!int;
    foreach (_; 0..T) {
        long x;
        int y;
        readln.read(x, y);
        solve(x, y);
    }
}

void solve (long x, int y) {
    byte[64] bit;
    bit[] = 0;
    // x を2進数変換
    int i = 0;
    long base = 2;
    while (x != 0) {
        bit[i] = cast(byte) (x % base);
        x /= base;
        i++;
    }

    /* visualize
    bit.each!(a => write(a));
    write("\n");
    */

    // yからたどれる一番右に行く
    while (true) {
        if (bit[y+1] == 0) {
            break;
        }
        y++;
    }

    // 最大高さyであるような連結成分を出力
    long res = 0;
    while (y >= 0) {
        res += pow(2L, y);
        y--;
    }

    // output
    writeln(res);
}

void read(T...)(string S, ref T args) {
    auto buf = S.split;
    foreach (i, ref arg; args) {
        arg = buf[i].to!(typeof(arg));
    }
}
0