結果
問題 | No.4 おもりと天秤 |
ユーザー |
|
提出日時 | 2017-12-05 01:24:59 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 193 ms / 5,000 ms |
コード長 | 1,258 bytes |
コンパイル時間 | 1,159 ms |
コンパイル使用メモリ | 111,292 KB |
実行使用メモリ | 27,392 KB |
最終ジャッジ日時 | 2024-06-26 10:25:02 |
合計ジャッジ時間 | 3,211 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
コンパイルメッセージ
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 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 ).OrderByDescending( x => x ).ToList();const string POSSIBLE = "possible";const string IMPOSSIBLE = "impossible";if (w.Sum() % 2 == 1) return IMPOSSIBLE;var goal = w.Sum() / 2;var queue = new Queue<int>();queue.Enqueue( w[ 0 ] );queue.Enqueue( -1 );for (var i = 1; i != w.Count(); ++i) {while (true) {var s = queue.Dequeue();queue.Enqueue( s );if (s == -1) break;if (s == goal || s + w[ i ] == goal) return POSSIBLE;else if (s + w[ i ] < goal && !queue.Contains( s + w[ i ] )) queue.Enqueue( s + w[ i ] );}}return IMPOSSIBLE;}static void Main(string[] args) {Console.WriteLine( Solve( System.Console.In ) );}}}