結果
| 問題 |
No.617 Nafmo、買い出しに行く
|
| コンテスト | |
| ユーザー |
keymoon
|
| 提出日時 | 2019-04-19 00:18:15 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 38 ms / 2,000 ms |
| コード長 | 1,459 bytes |
| コンパイル時間 | 1,272 ms |
| コンパイル使用メモリ | 115,584 KB |
| 実行使用メモリ | 27,316 KB |
| 最終ジャッジ日時 | 2024-09-22 10:48:59 |
| 合計ジャッジ時間 | 2,612 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
//DeBruijnBitPosition[i] := 上のDe Bruijn Sequenceにて、対応しているシフト幅
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);
int bitpos = 0;
while (((1 << bitpos) & i) == 0) bitpos++;
if (((1 << bitpos) & code) != 0) sum += a[bitpos];
else sum -= a[bitpos];
if (sum <= k && res < sum) res = sum;
}
Console.WriteLine(res);
}
}
keymoon