結果
問題 | No.115 遠足のおやつ |
ユーザー | mban |
提出日時 | 2017-01-12 08:27:13 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 2,071 ms / 5,000 ms |
コード長 | 2,681 bytes |
コンパイル時間 | 776 ms |
コンパイル使用メモリ | 107,776 KB |
実行使用メモリ | 329,048 KB |
最終ジャッジ日時 | 2024-06-10 23:48:13 |
合計ジャッジ時間 | 10,619 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 22 ms
18,944 KB |
testcase_01 | AC | 23 ms
18,812 KB |
testcase_02 | AC | 25 ms
19,968 KB |
testcase_03 | AC | 22 ms
19,072 KB |
testcase_04 | AC | 459 ms
95,724 KB |
testcase_05 | AC | 25 ms
19,188 KB |
testcase_06 | AC | 23 ms
19,072 KB |
testcase_07 | AC | 27 ms
20,352 KB |
testcase_08 | AC | 32 ms
22,528 KB |
testcase_09 | AC | 125 ms
41,724 KB |
testcase_10 | AC | 188 ms
56,816 KB |
testcase_11 | AC | 27 ms
19,152 KB |
testcase_12 | AC | 137 ms
42,880 KB |
testcase_13 | AC | 23 ms
19,072 KB |
testcase_14 | AC | 31 ms
22,272 KB |
testcase_15 | AC | 234 ms
63,872 KB |
testcase_16 | AC | 361 ms
79,064 KB |
testcase_17 | AC | 110 ms
37,484 KB |
testcase_18 | AC | 23 ms
18,928 KB |
testcase_19 | AC | 35 ms
24,448 KB |
testcase_20 | AC | 28 ms
20,864 KB |
testcase_21 | AC | 91 ms
33,408 KB |
testcase_22 | AC | 220 ms
59,884 KB |
testcase_23 | AC | 29 ms
21,120 KB |
testcase_24 | AC | 144 ms
45,308 KB |
testcase_25 | AC | 106 ms
37,888 KB |
testcase_26 | AC | 66 ms
27,520 KB |
testcase_27 | AC | 84 ms
31,232 KB |
testcase_28 | AC | 73 ms
28,288 KB |
testcase_29 | AC | 113 ms
39,024 KB |
testcase_30 | AC | 160 ms
48,892 KB |
testcase_31 | AC | 149 ms
46,832 KB |
testcase_32 | AC | 316 ms
74,752 KB |
testcase_33 | AC | 69 ms
28,908 KB |
testcase_34 | AC | 433 ms
94,176 KB |
testcase_35 | AC | 183 ms
52,608 KB |
testcase_36 | AC | 117 ms
38,512 KB |
testcase_37 | AC | 367 ms
80,236 KB |
testcase_38 | AC | 1,936 ms
307,136 KB |
testcase_39 | AC | 2,071 ms
329,048 KB |
testcase_40 | AC | 23 ms
19,072 KB |
testcase_41 | AC | 24 ms
19,072 KB |
testcase_42 | AC | 23 ms
19,200 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[1001, 101, 101]; 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; } }