結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-12-21 14:53:20 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 26 ms / 5,000 ms |
| コード長 | 1,145 bytes |
| コンパイル時間 | 2,173 ms |
| コンパイル使用メモリ | 105,472 KB |
| 実行使用メモリ | 19,200 KB |
| 最終ジャッジ日時 | 2024-07-19 09:20:55 |
| 合計ジャッジ時間 | 3,411 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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 No004_おもりと天秤
{
class Program
{
static void Main()
{
int n = int.Parse(Console.ReadLine());
string[] input = Console.ReadLine().Split(' ');
int[] list = input.Select(int.Parse).ToArray();
int sum = list.Sum();
bool[,] dp = new bool[101, sum + 1];
if (sum % 2 == 1)
{
Console.WriteLine("impossible");
}
else
{
dp[0, 0] = true;
for (int i = 0; i < list.Length; i++)
{
for (int j = 0; j <= sum; j++)
{
if (dp[i, j])
{
dp[i + 1, j + list[i]] = true;
dp[i + 1, j] = true;
}
}
}
if (dp[list.Length, sum / 2])
Console.WriteLine("possible");
else
Console.WriteLine("impossible");
}
}
}
}