結果

問題 No.4 おもりと天秤
ユーザー akichi
提出日時 2017-08-18 02:39:29
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 54 ms / 5,000 ms
コード長 588 bytes
コンパイル時間 3,517 ms
コンパイル使用メモリ 113,756 KB
実行使用メモリ 23,296 KB
最終ジャッジ日時 2024-06-26 10:22:23
合計ジャッジ時間 2,811 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
class Program {
    static void Main() {
        string ans = "impossible";
        Console.ReadLine();
        int[] ws = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int sum = ws.Sum();
        if (sum % 2 == 0) {
            HashSet<int> leftW = new HashSet<int> { 0 };

            foreach (int w in ws) {
                leftW.UnionWith(leftW.Select(x => x + w).ToArray());
            }
            if (leftW.Contains(sum / 2)) ans = "possible";
        }
        Console.WriteLine(ans);
    }
}
0