結果

問題 No.1450 nahco314's First Problem
ユーザー bluemeganebluemegane
提出日時 2021-05-20 11:38:49
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,017 bytes
コンパイル時間 897 ms
コンパイル使用メモリ 111,960 KB
実行使用メモリ 25,952 KB
最終ジャッジ日時 2024-04-26 02:09:00
合計ジャッジ時間 3,485 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
25,684 KB
testcase_01 AC 22 ms
25,680 KB
testcase_02 AC 23 ms
25,932 KB
testcase_03 WA -
testcase_04 AC 22 ms
23,856 KB
testcase_05 AC 22 ms
23,900 KB
testcase_06 AC 22 ms
23,776 KB
testcase_07 AC 20 ms
21,808 KB
testcase_08 AC 23 ms
25,680 KB
testcase_09 AC 22 ms
23,900 KB
testcase_10 AC 24 ms
25,936 KB
testcase_11 AC 22 ms
24,024 KB
testcase_12 AC 21 ms
25,804 KB
testcase_13 AC 21 ms
25,556 KB
testcase_14 AC 21 ms
23,516 KB
testcase_15 AC 21 ms
23,984 KB
testcase_16 AC 23 ms
21,432 KB
testcase_17 AC 21 ms
23,776 KB
testcase_18 AC 20 ms
21,940 KB
testcase_19 AC 20 ms
23,896 KB
testcase_20 AC 21 ms
25,716 KB
testcase_21 AC 23 ms
23,776 KB
testcase_22 AC 22 ms
23,516 KB
testcase_23 AC 22 ms
25,808 KB
testcase_24 AC 21 ms
23,388 KB
testcase_25 AC 21 ms
23,516 KB
testcase_26 AC 21 ms
23,900 KB
testcase_27 AC 22 ms
23,884 KB
testcase_28 AC 22 ms
25,688 KB
testcase_29 AC 21 ms
25,676 KB
testcase_30 AC 22 ms
23,772 KB
testcase_31 AC 22 ms
25,568 KB
testcase_32 AC 21 ms
25,808 KB
testcase_33 AC 20 ms
23,596 KB
testcase_34 AC 20 ms
23,908 KB
testcase_35 AC 21 ms
25,952 KB
testcase_36 AC 21 ms
25,684 KB
testcase_37 AC 22 ms
23,628 KB
testcase_38 AC 21 ms
21,936 KB
testcase_39 AC 22 ms
23,808 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using static System.Math;
using System;

public class Hello
{
    static void Main()
    {
        var x = long.Parse(Console.ReadLine().Trim());
        getAns(x);
    }
    static void getAns(long x)
    {
        var imin = Max(0, x - 60);
        var imax = x + 60;
        for (long i = imin; i <= imax; i++)
        {
            var bc = bitCount((ulong)i);
            var chk = i ^ bc;
            if (chk == x) { Console.WriteLine(i); return; }
        }
        Console.WriteLine(-1);
    }
    static int bitCount(ulong bits)
    {
        bits = (bits & 0x5555555555555555) + (bits >> 1 & 0x5555555555555555);
        bits = (bits & 0x3333333333333333) + (bits >> 2 & 0x3333333333333333);
        bits = (bits & 0x0f0f0f0f0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f0f0f0f0f);
        bits = (bits & 0x00ff00ff00ff00ff) + (bits >> 8 & 0x00ff00ff00ff00ff);
        bits = (bits & 0x0000ffff0000ffff) + (bits >> 16 & 0x0000ffff0000ffff);
        return (int)(bits & 0x00000000ffffffff) + (int)(bits >> 32);
    }
}
0