結果
問題 | No.297 カードの数式 |
ユーザー | nanophoto12 |
提出日時 | 2015-12-08 23:53:02 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,337 bytes |
コンパイル時間 | 845 ms |
コンパイル使用メモリ | 106,880 KB |
実行使用メモリ | 19,328 KB |
最終ジャッジ日時 | 2024-09-14 20:27:15 |
合計ジャッジ時間 | 2,487 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge6 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
19,072 KB |
testcase_01 | AC | 32 ms
19,200 KB |
testcase_02 | AC | 32 ms
19,328 KB |
testcase_03 | AC | 31 ms
19,328 KB |
testcase_04 | AC | 31 ms
19,328 KB |
testcase_05 | AC | 31 ms
19,200 KB |
testcase_06 | AC | 30 ms
19,328 KB |
testcase_07 | AC | 31 ms
19,200 KB |
testcase_08 | AC | 32 ms
18,944 KB |
testcase_09 | AC | 32 ms
19,200 KB |
testcase_10 | AC | 32 ms
18,944 KB |
testcase_11 | AC | 31 ms
19,200 KB |
testcase_12 | AC | 31 ms
19,200 KB |
testcase_13 | AC | 31 ms
19,072 KB |
testcase_14 | AC | 31 ms
18,944 KB |
testcase_15 | AC | 31 ms
18,944 KB |
testcase_16 | AC | 30 ms
19,200 KB |
testcase_17 | AC | 32 ms
19,200 KB |
testcase_18 | AC | 31 ms
19,200 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 31 ms
19,200 KB |
testcase_23 | AC | 31 ms
19,328 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
コンパイルメッセージ
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.Generic; using System.Linq; using System.Text; namespace No297 { class MainClass { private static long Build(IList<int> source) { var values = new List<int> (source); long value = 0; for (int i = 0; i < values.Count; i++) { value *= 10; value += values [i]; } return value; } static long CalculateMax (List<int> items, int plusCount, int minusCount, int operandSum) { List<int> maxBuffer = new List<int> (items); maxBuffer.Sort (); maxBuffer.Reverse (); var maxFront = Build (maxBuffer.Take (maxBuffer.Count - operandSum).ToList ()); for (int i = 0; i < plusCount; i++) { maxFront += maxBuffer [maxBuffer.Count - operandSum + i]; } for (int i = 0; i < minusCount; i++) { maxFront -= maxBuffer [maxBuffer.Count - minusCount + i]; } return maxFront; } static long CalculateMin (List<int> items, int plusCount, int minusCount, int operandSum) { var minBuffer = new List<int> (items); minBuffer.Sort (); long minValue = minBuffer[0]; minBuffer.RemoveAt (0); if (minusCount == 0) { for (int i = 0; i < minBuffer.Count - plusCount; i++) { minValue *= 10; minValue += minBuffer [i]; } for (int i = 0; i < plusCount; i++) { minValue += minBuffer [minBuffer.Count - plusCount + i]; } return minValue; } else { minValue -= Build (minBuffer.Skip (operandSum - 1).Reverse().ToList ()); for (int i = 0; i < plusCount; i++) { minValue += minBuffer [i]; } for (int i = plusCount; i < plusCount + minusCount - 1; i++) { minValue -= minBuffer [i]; } return minValue; } } public static void Main (string[] args) { var n = Console.ReadLine (); var keys = Console.ReadLine ().Split(' ').ToList(); List<int> items = new List<int> (); int plusCount = 0; int minusCount = 0; foreach (var element in keys) { if (element == "+") { plusCount++; } else if (element == "-") { minusCount++; } else { items.Add (Convert.ToInt32(element)); } } int operandSum = plusCount + minusCount; var maxValue = CalculateMax (items, plusCount, minusCount, operandSum); var minValue = CalculateMin (items, plusCount, minusCount, operandSum); Console.WriteLine(maxValue + " " + minValue); } } }