結果
問題 | No.115 遠足のおやつ |
ユーザー | mban |
提出日時 | 2017-01-12 08:27:13 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 2,339 ms / 5,000 ms |
コード長 | 2,681 bytes |
コンパイル時間 | 1,076 ms |
コンパイル使用メモリ | 108,032 KB |
実行使用メモリ | 329,300 KB |
最終ジャッジ日時 | 2025-01-03 01:20:43 |
合計ジャッジ時間 | 12,336 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 26 ms
19,456 KB |
testcase_01 | AC | 30 ms
19,584 KB |
testcase_02 | AC | 31 ms
20,224 KB |
testcase_03 | AC | 29 ms
19,584 KB |
testcase_04 | AC | 519 ms
96,612 KB |
testcase_05 | AC | 27 ms
19,704 KB |
testcase_06 | AC | 26 ms
19,584 KB |
testcase_07 | AC | 31 ms
20,736 KB |
testcase_08 | AC | 36 ms
23,296 KB |
testcase_09 | AC | 148 ms
41,968 KB |
testcase_10 | AC | 221 ms
57,328 KB |
testcase_11 | AC | 29 ms
19,800 KB |
testcase_12 | AC | 149 ms
43,520 KB |
testcase_13 | AC | 26 ms
19,456 KB |
testcase_14 | AC | 38 ms
23,040 KB |
testcase_15 | AC | 264 ms
64,508 KB |
testcase_16 | AC | 415 ms
79,976 KB |
testcase_17 | AC | 124 ms
37,888 KB |
testcase_18 | AC | 28 ms
19,440 KB |
testcase_19 | AC | 38 ms
25,216 KB |
testcase_20 | AC | 32 ms
21,248 KB |
testcase_21 | AC | 103 ms
33,792 KB |
testcase_22 | AC | 244 ms
60,144 KB |
testcase_23 | AC | 36 ms
21,888 KB |
testcase_24 | AC | 164 ms
45,568 KB |
testcase_25 | AC | 119 ms
38,144 KB |
testcase_26 | AC | 76 ms
28,032 KB |
testcase_27 | AC | 93 ms
31,616 KB |
testcase_28 | AC | 81 ms
28,800 KB |
testcase_29 | AC | 129 ms
39,668 KB |
testcase_30 | AC | 181 ms
49,508 KB |
testcase_31 | AC | 174 ms
47,104 KB |
testcase_32 | AC | 362 ms
74,996 KB |
testcase_33 | AC | 84 ms
29,676 KB |
testcase_34 | AC | 497 ms
94,580 KB |
testcase_35 | AC | 209 ms
53,248 KB |
testcase_36 | AC | 138 ms
39,168 KB |
testcase_37 | AC | 418 ms
80,628 KB |
testcase_38 | AC | 2,256 ms
307,656 KB |
testcase_39 | AC | 2,339 ms
329,300 KB |
testcase_40 | AC | 27 ms
19,456 KB |
testcase_41 | AC | 27 ms
19,584 KB |
testcase_42 | AC | 28 ms
19,584 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; } }