結果

問題 No.617 Nafmo、買い出しに行く
ユーザー keymoonkeymoon
提出日時 2019-04-19 00:17:33
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,393 bytes
コンパイル時間 1,358 ms
コンパイル使用メモリ 111,868 KB
実行使用メモリ 25,524 KB
最終ジャッジ日時 2023-10-23 16:40:29
合計ジャッジ時間 3,356 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
25,524 KB
testcase_01 AC 30 ms
25,524 KB
testcase_02 AC 31 ms
25,524 KB
testcase_03 AC 30 ms
25,524 KB
testcase_04 AC 30 ms
25,524 KB
testcase_05 AC 31 ms
25,524 KB
testcase_06 AC 39 ms
25,524 KB
testcase_07 AC 38 ms
25,524 KB
testcase_08 AC 30 ms
25,524 KB
testcase_09 AC 30 ms
25,524 KB
testcase_10 AC 37 ms
25,524 KB
testcase_11 AC 37 ms
25,524 KB
testcase_12 AC 37 ms
25,524 KB
testcase_13 AC 39 ms
25,524 KB
testcase_14 AC 37 ms
25,524 KB
testcase_15 AC 37 ms
25,524 KB
testcase_16 AC 36 ms
25,524 KB
testcase_17 AC 37 ms
25,524 KB
testcase_18 AC 30 ms
25,524 KB
testcase_19 AC 30 ms
25,524 KB
testcase_20 AC 33 ms
25,524 KB
testcase_21 AC 30 ms
25,524 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;


static class P
{
    static void Main()
    {
        const uint DeBruijnSequence = 0b0000111011010111110011000101001U;
        int[] DeBruijnBitPosition = { 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14 };

        var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nk[0];
        var k = nk[1];
        var a = Enumerable.Repeat(0, nk[0]).Select(_ => int.Parse(Console.ReadLine())).ToArray();

        int sum = 0;
        int res = 0;
        for (int i = 1; i < (1 << n); i++)
        {
            int code = i ^ (i >> 1);

            uint lsb = (uint)(i & -i);
            int bitpos = DeBruijnBitPosition[(DeBruijnSequence * lsb) >> 27];

            if (((1 << bitpos) & code) != 0) sum += a[bitpos];
            else sum -= a[bitpos];

            if (sum <= k && res < sum) res = sum;
        }
        Console.WriteLine(res);
    }
}
0