結果
問題 |
No.617 Nafmo、買い出しに行く
|
ユーザー |
![]() |
提出日時 | 2019-04-19 00:17:33 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 38 ms / 2,000 ms |
コード長 | 1,393 bytes |
コンパイル時間 | 1,163 ms |
コンパイル使用メモリ | 113,656 KB |
実行使用メモリ | 27,372 KB |
最終ジャッジ日時 | 2024-09-22 10:48:52 |
合計ジャッジ時間 | 2,651 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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); } }