結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-09-14 14:17:43 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 26 ms / 5,000 ms |
| コード長 | 1,084 bytes |
| コンパイル時間 | 915 ms |
| コンパイル使用メモリ | 107,392 KB |
| 実行使用メモリ | 19,200 KB |
| 最終ジャッジ日時 | 2024-07-05 22:20:34 |
| 合計ジャッジ時間 | 1,957 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / 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.Collections.Generic;
using System.Linq;
namespace Test01
{
class Program
{
static void Main(string[] args)
{
int N = int.Parse(Console.ReadLine());
string[] input = Console.ReadLine().Split(' ');
int[] w = new int[N + 1];
for(int i = 1; i <= N; i++)
{
w[i] = int.Parse(input[i - 1]);
}
int sum = w.Sum();
if(sum % 2 == 1)
{
Console.WriteLine("impossible");
return;
}
int max = sum / 2;
bool[] dp = new bool[max + 1];
dp[0] = true;
w = w.OrderBy(x => x).ToArray();
for(int i = 1; i <= N; i++)
{
for(int j = max; j >= 0; j--)
{
if (w[i] + j <= max) dp[w[i] + j] |= dp[j];
}
}
if (dp[max]) Console.WriteLine("possible");
else Console.WriteLine("impossible");
}
}
}