結果
問題 | No.4 おもりと天秤 |
ユーザー |
![]() |
提出日時 | 2017-08-28 10:29:50 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 33 ms / 5,000 ms |
コード長 | 1,174 bytes |
コンパイル時間 | 933 ms |
コンパイル使用メモリ | 111,948 KB |
実行使用メモリ | 27,416 KB |
最終ジャッジ日時 | 2024-06-26 10:22:36 |
合計ジャッジ時間 | 2,429 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.
ソースコード
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++) { 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; } W[P[i]] = true; } return imp; } } }