結果

問題 No.332 数列をプレゼントに
ユーザー HimatsubushinHimatsubushin
提出日時 2015-12-28 18:32:30
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,747 bytes
コンパイル時間 3,057 ms
コンパイル使用メモリ 110,240 KB
実行使用メモリ 28,456 KB
最終ジャッジ日時 2023-10-19 11:44:09
合計ジャッジ時間 8,312 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
24,336 KB
testcase_01 AC 28 ms
24,240 KB
testcase_02 AC 28 ms
24,212 KB
testcase_03 AC 26 ms
24,140 KB
testcase_04 AC 29 ms
24,332 KB
testcase_05 AC 29 ms
24,320 KB
testcase_06 AC 34 ms
26,392 KB
testcase_07 AC 28 ms
24,268 KB
testcase_08 AC 30 ms
24,344 KB
testcase_09 AC 28 ms
24,252 KB
testcase_10 AC 29 ms
24,256 KB
testcase_11 AC 29 ms
24,320 KB
testcase_12 AC 29 ms
24,344 KB
testcase_13 AC 29 ms
24,344 KB
testcase_14 AC 29 ms
24,332 KB
testcase_15 AC 299 ms
28,456 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Collections;

namespace No_332
{
	class MainClass
	{
        private struct Progression
        {
            public long value;
            public int number;
        }

        private static int n;
        private static long x;
        private static Progression[] S;
        private static ArrayList result = new ArrayList();

		public static void Main (string[] args)
        {
            ArrayList sumPos = new ArrayList();

            string[] data = Console.ReadLine().Split(' ');
            int.TryParse(data[0], out n);
            long.TryParse(data[1], out x);
            string[] output = new string[n];

            data = Console.ReadLine().Split(' ');
            S = new Progression[data.Length];
            for (int i = 0; i < data.Length; i++)
            {
                long.TryParse(data[i], out S[i].value);
                S[i].number = i;
            }

            long[] value = new long[S.Length];
            for (int i = 0; i < value.Length; i++)
                value[i] = S[i].value;

            Array.Sort(value, S);

            for (int i = S.Length - 1; S[i].value > x; i--)
                n = i;

            bool success = false;
            long sum = 0;

            for (int i = 0; i < n; i++)
                sum += S[i].value;
            if (sum >= x)
            {
                for (int i = 0; i < output.Length; i++)
                    output[i] = "x";

                for (int i = 0; i < n; i++)
                {
                    if (TotalCheck(i, 0, sumPos))
                    {

                        for (int j = 0; j < result.Count; j++)
                            output[(int)result[j]] = "o";

                        for (int j = 0; j < output.Length; j++)
                            Console.Write(output[j]);

                        Console.WriteLine();
                        success = true;
                        break;
                    }
                }
            }
            if (!success)
                Console.WriteLine("No");
        }

        private static bool TotalCheck(int pos, long sum, ArrayList sumPos)
        {
            sum += S[pos].value;
            
            if (sum == x)
            {
                sumPos.Add(S[pos].number);
                result = new ArrayList(sumPos);
                return true;
            }
            else if (sum < x)
            {
                for (int i = pos + 1; i < n; i++)
                {
                    sumPos.Add(S[pos].number);
                    if (TotalCheck(i, sum, sumPos))
                        return true;
                    sumPos.RemoveAt(sumPos.Count - 1);
                }
            }

            return false;
        }
	}
}
0