結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
aketijyuuzou
|
| 提出日時 | 2024-10-10 21:26:56 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 49 ms / 5,000 ms |
| コード長 | 2,049 bytes |
| コンパイル時間 | 1,883 ms |
| コンパイル使用メモリ | 112,840 KB |
| 実行使用メモリ | 27,288 KB |
| 最終ジャッジ日時 | 2024-10-10 21:27:00 |
| 合計ジャッジ時間 | 2,643 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("3");
WillReturn.Add("1 2 3");
//possible
//左側に1と2 右側に3を置くことで水平になります。
}
else if (InputPattern == "Input2") {
WillReturn.Add("5");
WillReturn.Add("1 2 3 4 5");
//impossible
//すべてのおもりを使って水平になる組み合わせは存在しません
}
else if (InputPattern == "Input3") {
WillReturn.Add("15");
WillReturn.Add("62 8 90 2 24 62 38 64 76 60 30 76 80 74 72");
//impossible
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
int[] OmoriArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray();
//事前に総合計を求めておく
int OmoriSum = OmoriArr.Sum();
//総合計が奇数なら解なし
if (OmoriSum % 2 == 1) {
Console.WriteLine("impossible");
return;
}
//作成可否[重りの合計]なDP表
bool[] DPArr = new bool[OmoriSum / 2 + 1];
DPArr[0] = true;
foreach (int EachOmosa in OmoriArr) {
//01ナップサックなのでリバースループ
for (int I = DPArr.GetUpperBound(0); 0 <= I; I--) {
if (DPArr[I] == false) continue;
int wkInd = I + EachOmosa;
if (wkInd <= DPArr.GetUpperBound(0))
DPArr[wkInd] = true;
}
}
Console.WriteLine(DPArr[OmoriSum / 2] ? "possible" : "impossible");
}
}
aketijyuuzou