結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2017-08-25 16:56:39 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,150 bytes |
コンパイル時間 | 841 ms |
コンパイル使用メモリ | 107,264 KB |
実行使用メモリ | 18,944 KB |
最終ジャッジ日時 | 2024-10-15 15:41:22 |
合計ジャッジ時間 | 2,330 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 WA * 1 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Linq; namespace OmoriTenbin { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] P = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); string R = MainProcess(N, P); Console.WriteLine(R); } private static string MainProcess(int N, int[] P) { const string imp = "impossible"; const string pos = "possible"; int sum = 0; foreach(int p in P) sum += p; if (sum % 2 != 0) return imp; int hlf = sum / 2; int max = P.Max(); if (max > hlf) return imp; if (max == hlf) return pos; bool[] W = new bool[sum + 1]; for (int i = 0;i < N ; i++) { W[P[i]] = true; for (int j = sum - 1 - P[i]; j > 0; j--) { W[j+ P[i]] |= W[j]; if (W[j + P[i]] && j + P[i] == hlf) return pos; } } return imp; } } }