結果
問題 | No.297 カードの数式 |
ユーザー | nanophoto12 |
提出日時 | 2015-12-08 23:47:07 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,482 bytes |
コンパイル時間 | 1,624 ms |
コンパイル使用メモリ | 111,932 KB |
実行使用メモリ | 27,388 KB |
最終ジャッジ日時 | 2024-09-14 20:27:07 |
合計ジャッジ時間 | 3,754 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
19,200 KB |
testcase_01 | AC | 33 ms
19,328 KB |
testcase_02 | AC | 32 ms
19,072 KB |
testcase_03 | AC | 32 ms
19,072 KB |
testcase_04 | WA | - |
testcase_05 | RE | - |
testcase_06 | AC | 32 ms
19,072 KB |
testcase_07 | AC | 32 ms
19,200 KB |
testcase_08 | AC | 33 ms
19,328 KB |
testcase_09 | RE | - |
testcase_10 | AC | 33 ms
19,200 KB |
testcase_11 | AC | 33 ms
18,944 KB |
testcase_12 | WA | - |
testcase_13 | AC | 33 ms
19,072 KB |
testcase_14 | AC | 33 ms
19,200 KB |
testcase_15 | AC | 33 ms
19,328 KB |
testcase_16 | AC | 33 ms
19,328 KB |
testcase_17 | AC | 33 ms
19,072 KB |
testcase_18 | AC | 32 ms
19,072 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 32 ms
19,200 KB |
testcase_23 | WA | - |
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 (); int minIndex = 0; long minValue = 0; foreach (var element in minBuffer) { if (element != 0) { minValue = element; break; } minIndex++; } minBuffer.RemoveAt (minIndex); 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); } } }