結果
問題 | No.297 カードの数式 |
ユーザー | nanophoto12 |
提出日時 | 2015-12-09 00:05:28 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 33 ms / 1,000 ms |
コード長 | 2,361 bytes |
コンパイル時間 | 1,735 ms |
コンパイル使用メモリ | 108,032 KB |
実行使用メモリ | 19,456 KB |
最終ジャッジ日時 | 2024-06-07 18:15:34 |
合計ジャッジ時間 | 3,383 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 33 ms
19,328 KB |
testcase_01 | AC | 31 ms
19,328 KB |
testcase_02 | AC | 32 ms
19,328 KB |
testcase_03 | AC | 32 ms
19,456 KB |
testcase_04 | AC | 32 ms
19,200 KB |
testcase_05 | AC | 32 ms
19,328 KB |
testcase_06 | AC | 32 ms
19,328 KB |
testcase_07 | AC | 33 ms
19,456 KB |
testcase_08 | AC | 32 ms
19,200 KB |
testcase_09 | AC | 31 ms
19,328 KB |
testcase_10 | AC | 32 ms
19,200 KB |
testcase_11 | AC | 32 ms
18,944 KB |
testcase_12 | AC | 32 ms
19,328 KB |
testcase_13 | AC | 31 ms
19,200 KB |
testcase_14 | AC | 31 ms
19,328 KB |
testcase_15 | AC | 30 ms
19,200 KB |
testcase_16 | AC | 30 ms
19,328 KB |
testcase_17 | AC | 30 ms
19,328 KB |
testcase_18 | AC | 31 ms
19,328 KB |
testcase_19 | AC | 31 ms
19,200 KB |
testcase_20 | AC | 31 ms
19,328 KB |
testcase_21 | AC | 31 ms
19,456 KB |
testcase_22 | AC | 32 ms
19,328 KB |
testcase_23 | AC | 32 ms
19,200 KB |
testcase_24 | AC | 33 ms
19,328 KB |
testcase_25 | AC | 31 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.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 (); if (minusCount == 0) { var tokens = new long[plusCount + 1]; int index = 0; while (minBuffer.Count > 0) { tokens [index] *= 10; tokens [index] += minBuffer [0]; minBuffer.RemoveAt (0); index++; index = index % tokens.Length; } return tokens.Sum (); } else { long minValue = minBuffer[0]; minBuffer.RemoveAt (0); 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); } } }