結果

問題 No.4 おもりと天秤
ユーザー outoforder
提出日時 2017-07-23 16:24:18
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,236 bytes
コンパイル時間 934 ms
コンパイル使用メモリ 111,724 KB
実行使用メモリ 27,360 KB
最終ジャッジ日時 2024-10-09 10:58:48
合計ジャッジ時間 2,640 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13 WA * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
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