結果
| 問題 |
No.297 カードの数式
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-05-15 11:34:49 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,455 bytes |
| コンパイル時間 | 901 ms |
| コンパイル使用メモリ | 116,232 KB |
| 実行使用メモリ | 27,936 KB |
| 最終ジャッジ日時 | 2024-10-06 03:18:19 |
| 合計ジャッジ時間 | 2,697 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 WA * 2 |
コンパイルメッセージ
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.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();
}
}
14番