結果
| 問題 |
No.2561 みんな大好きmod 998
|
| コンテスト | |
| ユーザー |
aketijyuuzou
|
| 提出日時 | 2025-02-20 22:47:59 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 3,291 ms / 4,000 ms |
| コード長 | 3,149 bytes |
| コンパイル時間 | 4,955 ms |
| コンパイル使用メモリ | 120,292 KB |
| 実行使用メモリ | 34,360 KB |
| 最終ジャッジ日時 | 2025-02-20 22:48:44 |
| 合計ジャッジ時間 | 45,558 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 44 |
コンパイルメッセージ
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;
// https://yukicoder.me/problems/no/2561
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("4 2");
WillReturn.Add("300 400 500 600");
}
else if (InputPattern == "Input2") {
WillReturn.Add("20 8");
WillReturn.Add("2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2");
}
else if (InputPattern == "Input3") {
WillReturn.Add("8 8");
WillReturn.Add("812087642 562447828 487989038 879550309 409027146 501712355 131601217 18035145");
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
int[] wkArr = InputList[0].TrimEnd().Split(' ').Select(pX => int.Parse(pX)).ToArray();
int K = wkArr[1];
long[] AArr = InputList[1].TrimEnd().Split(' ').Select(pX => long.Parse(pX)).ToArray();
long Answer = 0;
foreach (long[] EachArr in RubyPatternClass<long>.Combination(AArr, K)) {
long Sum1 = 0;
long Sum2 = 0;
foreach (long EachVal in EachArr) {
Sum1 += EachVal;
Sum2 += EachVal;
Sum1 %= 998;
Sum2 %= 998244353;
}
if (Sum1 >= Sum2) {
Answer++;
Answer %= 998;
}
}
Console.WriteLine(Answer);
}
}
#region RubyPatternClass
// Rubyの場合の数
internal static class RubyPatternClass<Type>
{
// 組合せを返す
private struct JyoutaiDef_Combination
{
internal int CurrP;
internal List<int> SelectedIndList;
}
internal static IEnumerable<Type[]> Combination(IEnumerable<Type> pEnum, int pR)
{
if (pR == 0) yield break;
Type[] pArr = pEnum.ToArray();
if (pArr.Length < pR) yield break;
var Stk = new Stack<JyoutaiDef_Combination>();
JyoutaiDef_Combination WillPush;
for (int I = pArr.GetUpperBound(0); 0 <= I; I--) {
WillPush.CurrP = I;
WillPush.SelectedIndList = new List<int>() { I };
Stk.Push(WillPush);
}
while (Stk.Count > 0) {
JyoutaiDef_Combination Popped = Stk.Pop();
// クリア判定
if (Popped.SelectedIndList.Count == pR) {
var WillReturn = new List<Type>();
Popped.SelectedIndList.ForEach(X => WillReturn.Add(pArr[X]));
yield return WillReturn.ToArray();
continue;
}
for (int I = pArr.GetUpperBound(0); Popped.CurrP + 1 <= I; I--) {
WillPush.CurrP = I;
WillPush.SelectedIndList = new List<int>(Popped.SelectedIndList) { I };
Stk.Push(WillPush);
}
}
}
}
#endregion
aketijyuuzou