結果
問題 |
No.2567 A_1 > A_2 > ... > A_N
|
ユーザー |
![]() |
提出日時 | 2025-02-18 15:47:56 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 354 ms / 2,000 ms |
コード長 | 2,094 bytes |
コンパイル時間 | 5,798 ms |
コンパイル使用メモリ | 112,956 KB |
実行使用メモリ | 42,752 KB |
最終ジャッジ日時 | 2025-02-18 15:48:07 |
合計ジャッジ時間 | 11,063 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 16 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "InputX"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("3"); WillReturn.Add("4 10"); WillReturn.Add("3 5"); WillReturn.Add("3 9"); } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List<string> InputList = GetInputList(); long[] wkArr = { }; Action<string> SplitAct = pStr => wkArr = pStr.Split(' ').Select(pX => long.Parse(pX)).ToArray(); foreach (string EachStr in InputList.Skip(1)) { SplitAct(EachStr); long N = wkArr[0]; long X = wkArr[1]; string Result = Solve(N, X); Console.WriteLine(Result); } } static string Solve(long pN, long pX) { long[] AnswerArr = new long[pN]; long UB = AnswerArr.GetUpperBound(0); long InitVal = 1; for (long I = UB; 0 <= I; I--) { AnswerArr[I] = InitVal++; } long SumVal = AnswerArr.Sum(); if (SumVal > pX) { return "-1"; } long Rest = pX - SumVal; long AddVal = Rest / pN; for (long I = 0; I <= UB; I++) { AnswerArr[I] += AddVal; } Rest -= AddVal * pN; for (long I = 0; I <= UB; I++) { if (Rest > 0) { AnswerArr[I]++; Rest--; } } return LongEnumJoin(" ", AnswerArr); } // セパレータとLong型の列挙を引数として、結合したstringを返す static string LongEnumJoin(string pSeparater, IEnumerable<long> pEnum) { string[] StrArr = Array.ConvertAll(pEnum.ToArray(), pX => pX.ToString()); return string.Join(pSeparater, StrArr); } }