結果

問題 No.4 おもりと天秤
ユーザー outoforderoutoforder
提出日時 2017-07-23 16:24:18
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,236 bytes
コンパイル時間 901 ms
コンパイル使用メモリ 107,392 KB
実行使用メモリ 19,328 KB
最終ジャッジ日時 2024-04-17 16:51:47
合計ジャッジ時間 2,515 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
19,072 KB
testcase_01 AC 30 ms
19,072 KB
testcase_02 AC 29 ms
19,072 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 30 ms
19,200 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 30 ms
19,072 KB
testcase_10 AC 31 ms
19,200 KB
testcase_11 AC 31 ms
19,200 KB
testcase_12 WA -
testcase_13 AC 31 ms
19,200 KB
testcase_14 AC 30 ms
19,072 KB
testcase_15 AC 31 ms
19,072 KB
testcase_16 WA -
testcase_17 AC 31 ms
19,328 KB
testcase_18 AC 32 ms
19,200 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 32 ms
19,200 KB
testcase_22 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.Linq;
using System.Text;

namespace procon
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var inputs = Console.ReadLine().Split().Select(int.Parse).ToArray();
            
            var weight_half = inputs.Sum() / 2;
            var stack = new Stack<int>();
            var pos = 0;

            while (pos < n)
            {
                for (int i = pos; i < n; i++)
                {
                    stack.Push(i);

                    var sum = stack.Select(index => inputs[index]).Sum();
                    if (sum > weight_half)
                    {
                        pos = stack.Pop() + 1;
                        break;
                    }
                    else if (sum == weight_half)
                    {
                        // 到達
                        Console.WriteLine("possible");
                        Console.Out.Flush();
                        return;
                    }
                }
            }
            
            Console.WriteLine("impossible");
            Console.Out.Flush();
        }
    }
}
0