結果
問題 |
No.4 おもりと天秤
|
ユーザー |
|
提出日時 | 2017-11-30 01:56:11 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,450 bytes |
コンパイル時間 | 989 ms |
コンパイル使用メモリ | 113,012 KB |
実行使用メモリ | 826,852 KB |
最終ジャッジ日時 | 2024-11-27 19:23:04 |
合計ジャッジ時間 | 46,607 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 TLE * 1 MLE * 8 |
コンパイルメッセージ
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; namespace yuki0004 { public struct Node { public int s0, s1; } public class Program { static internal string Solve(System.IO.TextReader reader) { var n = int.Parse( reader.ReadLine() ); var w = reader.ReadLine().Split().ToList().ConvertAll( int.Parse ); var aim = w.Sum() / 2; if (w.Sum() % 2 == 1 || w.Max() > aim) return "impossible"; if (w.Contains( aim )) return "possible"; var q = new Queue<Node>(); Node node = new Node { s0 = 0, s1 = w[ 0 ] }; q.Enqueue( node ); for (var i = 1; i <= n; ++i) { var r = new List<Node>(); while (q.Any()) { var t0 = q.Dequeue(); Node t1 = new Node { s0 = t0.s0 + w[ i ], s1 = t0.s1 }; Node t2 = new Node { s0 = t0.s0, s1 = t0.s1 + w[ i ] }; if (t1.s0 == aim) return "possible"; else if (t1.s0 < aim) r.Add( t1 ); if (t2.s1 == aim) return "possible"; else if (t2.s1 < aim) r.Add( t2 ); } foreach (var e in r) q.Enqueue( e ); } return "impossible"; } static void Main(string[] args) { Console.WriteLine( Solve( System.Console.In ) ); } } }