結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-03-28 15:49:01 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,509 bytes |
| コンパイル時間 | 896 ms |
| コンパイル使用メモリ | 106,368 KB |
| 実行使用メモリ | 24,576 KB |
| 最終ジャッジ日時 | 2024-10-02 06:21:39 |
| 合計ジャッジ時間 | 3,305 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 WA * 3 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Text;
using System.Collections.Generic;
public class Program
{
public void Proc() {
Reader.IsDebug = false;
int omoriCount = int.Parse(Reader.ReadLine());
this.OmoList.AddRange(Reader.GetInt());
int total = 0;
foreach (int num in this.OmoList)
{
total += num;
}
this.OmoList.Sort();
this.OmoList.Reverse();
bool ans = (total % 2 == 0);
if(ans) {
ans = CanBalance(0, total / 2);
}
Console.WriteLine(ans?"possible":"impossible");
}
private List<int> OmoList = new List<int>();
Dictionary<int,Dictionary<int, bool>> dic = new Dictionary<int,Dictionary<int, bool>>();
private bool CanBalance(int idx, int remain) {
if(!dic.ContainsKey(idx)) {
dic.Add(idx, new Dictionary<int, bool>());
}
if(dic[idx].ContainsKey(remain)) {
return dic[idx][remain];
}
if(remain == 0) {
return true;
}
if(remain < 0) {
return false;
}
if (idx >= this.OmoList.Count) {
return false;
}
bool ans = false;
for (int i=idx; i<this.OmoList.Count; i++) {
if(this.OmoList[i] <= remain) {
ans = ans || this.CanBalance(i, remain - this.OmoList[i]);
if(ans) {
break;
}
}
}
dic[idx].Add(remain, ans);
return ans;
}
public class Reader {
private static String InitText = @"
2
4 2
";
private static System.IO.StringReader sr = null;
public static bool IsDebug = true;
public static string ReadLine() {
if(IsDebug) {
if(sr == null) {
sr = new System.IO.StringReader(InitText.Trim());
}
return sr.ReadLine();
} else {
return Console.ReadLine();
}
}
public static int[] GetInt(char delimiter = ' ') {
string[] inpt = ReadLine().Split(delimiter);
int[] ret = new int[inpt.Length];
for(int i=0; i<inpt.Length; i++) {
ret[i] = int.Parse(inpt[i]);
}
return ret;
}
}
public static void Main(string[] args)
{
Program prg = new Program();
prg.Proc();
}
}
14番