結果

問題 No.297 カードの数式
ユーザー 14番14番
提出日時 2016-05-15 11:34:49
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,455 bytes
コンパイル時間 1,122 ms
コンパイル使用メモリ 108,928 KB
実行使用メモリ 20,224 KB
最終ジャッジ日時 2024-04-15 21:48:45
合計ジャッジ時間 2,695 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
19,712 KB
testcase_01 AC 45 ms
19,456 KB
testcase_02 AC 42 ms
19,712 KB
testcase_03 AC 43 ms
19,712 KB
testcase_04 AC 43 ms
19,712 KB
testcase_05 AC 42 ms
19,840 KB
testcase_06 WA -
testcase_07 AC 42 ms
19,584 KB
testcase_08 AC 42 ms
19,712 KB
testcase_09 AC 41 ms
19,584 KB
testcase_10 AC 42 ms
19,584 KB
testcase_11 AC 42 ms
19,840 KB
testcase_12 AC 41 ms
19,840 KB
testcase_13 AC 40 ms
19,456 KB
testcase_14 AC 41 ms
19,584 KB
testcase_15 AC 43 ms
19,968 KB
testcase_16 AC 41 ms
19,840 KB
testcase_17 AC 42 ms
19,456 KB
testcase_18 AC 41 ms
19,840 KB
testcase_19 AC 44 ms
19,840 KB
testcase_20 AC 42 ms
19,968 KB
testcase_21 AC 43 ms
19,712 KB
testcase_22 AC 43 ms
19,584 KB
testcase_23 AC 42 ms
19,456 KB
testcase_24 AC 44 ms
19,712 KB
testcase_25 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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
        {
            numList = numList.Reverse().ToArray();
            int yousosu = enzansi.Length + 1;
            int[] tmp = numList;
            int idx = 0;
            bool isBigger = true;
            for(int i=0; i<numList.Length; i++) {
                if(listSub.Count < yousosu) {
                    listSub.Add(numList[i]);
                } else
                {
                    listSub[idx] = long.Parse("" + listSub[idx] + numList[i]);
                }
                if(isBigger) {
                    idx++;
                    if(idx >= yousosu) {
                        isBigger = false;
                        idx = yousosu - 1;
                    }
                } else
                {
                    idx--;
                    if(idx < 0) {
                        isBigger = true;
                        idx = 0;
                    }
                }
            }
        }
        
        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 = @"


8
+ 1 2 3 4 5 6 +


 
";
        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