結果
問題 |
No.4 おもりと天秤
|
ユーザー |
|
提出日時 | 2016-10-23 01:49:11 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 676 bytes |
コンパイル時間 | 2,827 ms |
コンパイル使用メモリ | 114,416 KB |
実行使用メモリ | 826,636 KB |
最終ジャッジ日時 | 2024-11-23 17:48:11 |
合計ジャッジ時間 | 28,104 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 MLE * 9 |
コンパイルメッセージ
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.Linq; public class Program { public static void Main() { int N = int.Parse(Console.ReadLine()); int[] W = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (W.Sum() % 2 == 1) { Console.WriteLine("impossible"); return; } int target = W.Sum() / 2; var flg = new bool[N + 1]; flg[0] = true; var q = new Queue<int>(); q.Enqueue(0); for (int i = 0; i < N; i++) { int len = q.Count; for (int j = 0; j < len; j++) { var t = q.Dequeue(); q.Enqueue(t); q.Enqueue(t + W[i]); } } Console.WriteLine(q.Any(i => i == target) ? "possible" : "impossible"); } }