結果

問題 No.4 おもりと天秤
ユーザー HimatsubushinHimatsubushin
提出日時 2019-01-23 12:27:05
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,056 bytes
コンパイル時間 2,597 ms
コンパイル使用メモリ 105,868 KB
実行使用メモリ 25,756 KB
最終ジャッジ日時 2023-10-14 09:21:46
合計ジャッジ時間 4,969 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
21,704 KB
testcase_01 AC 58 ms
21,632 KB
testcase_02 AC 58 ms
21,668 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 59 ms
21,632 KB
testcase_07 WA -
testcase_08 AC 59 ms
21,604 KB
testcase_09 AC 59 ms
19,748 KB
testcase_10 AC 60 ms
23,716 KB
testcase_11 AC 59 ms
21,664 KB
testcase_12 AC 59 ms
23,784 KB
testcase_13 AC 58 ms
21,644 KB
testcase_14 AC 58 ms
23,700 KB
testcase_15 AC 58 ms
21,648 KB
testcase_16 WA -
testcase_17 AC 59 ms
23,716 KB
testcase_18 AC 59 ms
23,752 KB
testcase_19 AC 59 ms
21,720 KB
testcase_20 AC 58 ms
21,596 KB
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Linq;

namespace No004_おもりと天秤
{
    class Program
    {
        static private int N;
        static private int[] W;
        static private int AllSum;

        static void Main(string[] args)
        {
            N = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');
            W = input.Select(int.Parse).ToArray();

            AllSum = 0;
            foreach (int a in W)
                AllSum += a;

            for (int i = 0; i < N; i++)
                Count(i, 0);

            Count(0, 0);

            if (AllSum == -1)
                Console.WriteLine("possible");
            else
                Console.WriteLine("impossible");
        }

        static void Count(int level, int sum)
        {
            sum += W[level];

            if (AllSum - sum == sum)
            {
                AllSum = -1;
            }
            else if (AllSum != -1 && level < N - 1)
            {
                Count(level + 1, sum);
            }
        }
    }
}
0