結果
問題 | No.115 遠足のおやつ |
ユーザー | mban |
提出日時 | 2017-01-12 08:25:37 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,692 bytes |
コンパイル時間 | 1,106 ms |
コンパイル使用メモリ | 115,176 KB |
実行使用メモリ | 337,056 KB |
最終ジャッジ日時 | 2024-06-01 06:21:25 |
合計ジャッジ時間 | 11,976 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | AC | 29 ms
26,972 KB |
testcase_02 | AC | 31 ms
25,008 KB |
testcase_03 | RE | - |
testcase_04 | AC | 531 ms
98,912 KB |
testcase_05 | AC | 30 ms
25,192 KB |
testcase_06 | AC | 28 ms
24,820 KB |
testcase_07 | AC | 32 ms
25,272 KB |
testcase_08 | AC | 36 ms
26,888 KB |
testcase_09 | AC | 125 ms
47,536 KB |
testcase_10 | AC | 196 ms
56,852 KB |
testcase_11 | AC | 30 ms
26,976 KB |
testcase_12 | AC | 145 ms
48,656 KB |
testcase_13 | AC | 30 ms
24,928 KB |
testcase_14 | AC | 35 ms
27,188 KB |
testcase_15 | AC | 278 ms
67,456 KB |
testcase_16 | AC | 384 ms
84,556 KB |
testcase_17 | AC | 102 ms
42,096 KB |
testcase_18 | AC | 30 ms
27,096 KB |
testcase_19 | AC | 41 ms
28,444 KB |
testcase_20 | AC | 33 ms
25,396 KB |
testcase_21 | AC | 77 ms
40,360 KB |
testcase_22 | AC | 229 ms
65,268 KB |
testcase_23 | AC | 32 ms
27,032 KB |
testcase_24 | AC | 149 ms
44,876 KB |
testcase_25 | AC | 101 ms
47,076 KB |
testcase_26 | AC | 46 ms
28,964 KB |
testcase_27 | AC | 67 ms
38,676 KB |
testcase_28 | AC | 51 ms
32,984 KB |
testcase_29 | AC | 108 ms
43,944 KB |
testcase_30 | AC | 170 ms
50,096 KB |
testcase_31 | AC | 157 ms
51,468 KB |
testcase_32 | AC | 326 ms
74,020 KB |
testcase_33 | AC | 55 ms
33,748 KB |
testcase_34 | AC | 512 ms
96,752 KB |
testcase_35 | AC | 191 ms
56,232 KB |
testcase_36 | AC | 103 ms
40,316 KB |
testcase_37 | AC | 432 ms
92,000 KB |
testcase_38 | AC | 2,271 ms
316,624 KB |
testcase_39 | AC | 2,482 ms
337,056 KB |
testcase_40 | RE | - |
testcase_41 | AC | 29 ms
24,880 KB |
testcase_42 | AC | 31 ms
25,184 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using System.Linq; using System.IO; class Program { static private Magatro M = new Magatro(); static private void Main(string[]args) { M.Scan(); M.Solve(); } } public class Scanner { private string[] S; private int Index; private char Separator; public Scanner(char separator = ' ') { Index = 0; Separator = separator; } private string[] Line() { return Console.ReadLine().Split(Separator); } public string Next() { string result; if (S == null || Index >= S.Length) { S = Line(); Index = 0; } result = S[Index]; Index++; return result; } public int NextInt() { return int.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } } public class Magatro { private int N, D, K; public void Scan() { Scanner sc = new Scanner(); N = sc.NextInt(); D = sc.NextInt(); K = sc.NextInt(); } public void Solve() { //合計,N個目,N個買った Count[,,] dp = new Count[(D + 1), (N + 1), (N + 1)]; dp[0, 0, 0].Buy = new List<int>(); for (int i = 1; i <= N; i++) { for (int j = 0; j <= D; j++) { for (int k = 0; k < i; k++) { if (dp[j, i - 1, k].Buy == null) continue; Count cp = dp[j, i - 1, k].Copy(); dp[j, i, k] = Min(dp[j, i, k], cp); cp.Buy.Add(i); if (j + i > D) continue; dp[j + i, i, k + 1] = Min(cp, dp[j + i, i, k + 1]); } } } List<int> ans = dp[D, N, K].Buy; if (ans == null || ans.Count == 0) Console.WriteLine(-1); else Console.WriteLine(string.Join(" ",ans)); } private Count Min(Count a, Count b) { if (a.Buy == null) return b.Copy(); if (b.Buy == null) return a.Copy(); for (int i = 0; i < a.Buy.Count; i++) { if (a.Buy[i] < b.Buy[i]) return a.Copy(); else if (a.Buy[i] > b.Buy[i]) return b.Copy(); } return a.Copy(); } } public struct Count { public List<int> Buy; public Count Copy() { Count ret; ret.Buy = Buy.ToList(); return ret; } }