結果

問題 No.332 数列をプレゼントに
ユーザー HimatsubushinHimatsubushin
提出日時 2015-12-28 17:55:57
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,546 bytes
コンパイル時間 995 ms
コンパイル使用メモリ 105,888 KB
実行使用メモリ 36,268 KB
最終ジャッジ日時 2024-09-19 07:38:44
合計ジャッジ時間 5,329 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 2
other AC * 2 TLE * 1 -- * 39
権限があれば一括ダウンロードができます
コンパイルメッセージ
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)
        {
            bool success;
            ArrayList sumPos = new ArrayList();

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

            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);

            success = false;
            for (int i = 0; i < S.Length; i++)
            {
                if (TotalCheck(i, 0, sumPos))
                {
                    string[] output = new string[n];

                    for (int j = 0; j < output.Length; j++)
                        output[j] = "x";

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

        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;
            }

            if (sum > x)
                return false;

            if (sum < x)
            {
                for (int i = pos + 1; i < S.Length; i++)
                {
                    sumPos.Add(S[pos].number);
                    if (TotalCheck(i, sum, sumPos))
                        return true;
                    sumPos.RemoveAt(sumPos.Count - 1);
                }
            }

            return false;
        }
	}
}
0