結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
masakt
|
| 提出日時 | 2017-04-16 02:04:49 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,244 bytes |
| コンパイル時間 | 3,217 ms |
| コンパイル使用メモリ | 109,592 KB |
| 実行使用メモリ | 48,480 KB |
| 最終ジャッジ日時 | 2024-07-18 21:29:23 |
| 合計ジャッジ時間 | 10,570 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 WA * 1 TLE * 1 -- * 4 |
コンパイルメッセージ
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;
class P
{
static int[] w;
static bool dfs(int i, int sum, int goal)
{
bool ret = false;
if (goal == sum)
{
ret = true;
}
else if (goal <sum || i == 0)
{
ret = false;
}
else
{
ret = dfs(i - 1, sum + w[i], goal) || dfs(i - 1, sum, goal);
}
return ret;
}
static void Main()
{
int n = int.Parse(Console.ReadLine());
string[] _ = new string[n];
_ = Console.ReadLine().Split(' ');
n = _.Length;
w = new int[n];
int sum = 0;
string ans = "";
for (int i = 0; i < _.Length; i++)
{
w[i] = int.Parse(_[i]);
sum += w[i];
}
if (sum % 2 == 0)
{
sum /= 2;
Array.Sort(w);
if (sum > w.Last())
{
ans = dfs(n - 1, 0, sum) ? "possible" : "impossible";
}
else
{
ans = "impossible";
}
}
else
{
ans = "impossible";
}
Console.WriteLine(ans);
}
}
masakt