結果

問題 No.297 カードの数式
ユーザー 14番14番
提出日時 2016-05-15 22:51:54
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 87 ms / 1,000 ms
コード長 3,014 bytes
コンパイル時間 2,423 ms
コンパイル使用メモリ 108,260 KB
実行使用メモリ 24,484 KB
最終ジャッジ日時 2023-08-26 22:54:10
合計ジャッジ時間 5,972 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
20,292 KB
testcase_01 AC 84 ms
22,220 KB
testcase_02 AC 86 ms
22,440 KB
testcase_03 AC 83 ms
24,244 KB
testcase_04 AC 85 ms
22,292 KB
testcase_05 AC 85 ms
24,308 KB
testcase_06 AC 86 ms
24,332 KB
testcase_07 AC 85 ms
22,348 KB
testcase_08 AC 87 ms
22,456 KB
testcase_09 AC 83 ms
22,408 KB
testcase_10 AC 85 ms
24,484 KB
testcase_11 AC 84 ms
24,320 KB
testcase_12 AC 84 ms
22,296 KB
testcase_13 AC 84 ms
22,268 KB
testcase_14 AC 84 ms
22,456 KB
testcase_15 AC 85 ms
22,268 KB
testcase_16 AC 85 ms
24,396 KB
testcase_17 AC 85 ms
24,384 KB
testcase_18 AC 83 ms
22,352 KB
testcase_19 AC 84 ms
24,268 KB
testcase_20 AC 86 ms
24,436 KB
testcase_21 AC 85 ms
22,252 KB
testcase_22 AC 83 ms
22,184 KB
testcase_23 AC 84 ms
24,392 KB
testcase_24 AC 85 ms
22,376 KB
testcase_25 AC 86 ms
24,320 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int itemCount = int.Parse(Reader.ReadLine());
        string[] inpt = Reader.ReadLine().Split(' ');
        
        char[] enzansi = inpt.Where(a=>a.Equals("+") || a.Equals("-")).Select(a=>a[0]).OrderBy(a=>a).ToArray();
        int[] numList = inpt.Where(a=>(!a.Equals("+")) && (!a.Equals("-"))).Select(a=>int.Parse(a)).OrderByDescending(a=>a).ToArray();
        
        
        int saidaiKeta = numList.Length - enzansi.Length;
        
        List<long> listSub = new List<long>();
        long ans1 = 0;
        
        listSub.Add(long.Parse(string.Join(string.Empty, numList.Take(saidaiKeta))));
        listSub.AddRange(numList.Skip(saidaiKeta).Select(a=>(long)a));
        
        ans1 = listSub[0];
        listSub.RemoveAt(0);
        for(int i=0; i<enzansi.Length; i++) {
            if(enzansi[i] == '+') {
                ans1 += listSub[i];
            } else
            {
                ans1 -= listSub[i];
            }
        }

        
        listSub = new List<long>();
        long ans2 = 0;
        
        enzansi = enzansi.Reverse().ToArray();
        if(enzansi.Count(a=>a=='-') > 0) {
            listSub.Add(long.Parse(string.Join(string.Empty, numList.Take(saidaiKeta))));
            listSub.AddRange(numList.Skip(saidaiKeta).Select(a=>(long)a));
        } else
        {
            List<long> tmpList = new List<long>();
            for(int i=0; i<numList.Length; i++) {
                if(tmpList.Count <= enzansi.Length) {
                    tmpList.Add(numList[i]);
                } else
                {
                    int idx = tmpList.IndexOf(tmpList.Min());
                    tmpList[idx] = long.Parse(numList[i]  + string.Empty + tmpList[idx]);
                }
            }
            listSub = tmpList;
        }
        
        ans2 = listSub.Last();
        listSub.RemoveAt(listSub.Count - 1);

        for(int i=0; i<enzansi.Length; i++) {
            if(enzansi[i] == '+') {
                ans2 += listSub[i];
            } else
            {
                ans2 -= listSub[i];
            }
        }
        
        Console.WriteLine(ans1 + " " + ans2);

        
    }


    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


15
1 2 3 4 5 6 7 8 9 0 0 0 9 + +

 
";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0