結果

問題 No.4 おもりと天秤
ユーザー 14番14番
提出日時 2016-03-28 15:49:01
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,509 bytes
コンパイル時間 1,953 ms
コンパイル使用メモリ 112,536 KB
実行使用メモリ 30,200 KB
最終ジャッジ日時 2024-04-10 04:51:50
合計ジャッジ時間 4,297 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
22,200 KB
testcase_01 AC 28 ms
24,208 KB
testcase_02 AC 34 ms
24,520 KB
testcase_03 AC 34 ms
24,624 KB
testcase_04 AC 32 ms
22,456 KB
testcase_05 AC 33 ms
24,500 KB
testcase_06 AC 32 ms
24,468 KB
testcase_07 AC 32 ms
24,368 KB
testcase_08 AC 30 ms
26,016 KB
testcase_09 AC 32 ms
22,320 KB
testcase_10 AC 33 ms
24,364 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 33 ms
24,376 KB
testcase_14 WA -
testcase_15 AC 32 ms
24,632 KB
testcase_16 AC 32 ms
24,364 KB
testcase_17 AC 32 ms
24,468 KB
testcase_18 AC 697 ms
30,200 KB
testcase_19 AC 32 ms
24,480 KB
testcase_20 AC 32 ms
26,440 KB
testcase_21 AC 32 ms
24,216 KB
testcase_22 AC 32 ms
24,652 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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();
    }
}
0