結果
| 問題 |
No.149 碁石の移動
|
| コンテスト | |
| ユーザー |
aketijyuuzou
|
| 提出日時 | 2024-10-10 22:56:06 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 29 ms / 2,000 ms |
| コード長 | 3,964 bytes |
| コンパイル時間 | 1,045 ms |
| コンパイル使用メモリ | 118,104 KB |
| 実行使用メモリ | 19,200 KB |
| 最終ジャッジ日時 | 2024-10-10 22:56:09 |
| 合計ジャッジ時間 | 2,304 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 13 |
コンパイルメッセージ
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("2 1");
WillReturn.Add("1 2");
WillReturn.Add("2 3");
//3
//袋Aには白い碁石が2個、黒い碁石が1個入っている。
//袋Bには白い碁石が1個、黒い碁石が2個入っている。
//例えば、袋Aから袋Bに移した2個の碁石が共に白い碁石であり、
//次に、袋Bから袋Aに移した3個の碁石がすべて白い碁石であれば、
//最終的に袋Aには最多で3個の白い碁石がある。
}
else if (InputPattern == "Input2") {
WillReturn.Add("2 0");
WillReturn.Add("0 3");
WillReturn.Add("2 1");
//1
//最初に袋Aから袋Bに移した2個の碁石はかならず白い碁石である。
//次に、袋Bから袋Aに移した1個の碁石が白い碁石であれば、
//最終的に袋Aには最多で1個の白い碁石がある。
}
else if (InputPattern == "Input3") {
WillReturn.Add("3 0");
WillReturn.Add("2 3");
WillReturn.Add("0 5");
//5
//最初に、袋Aから袋Bに0個碁石を移す。(つまり碁石の数は動かない。)
//次に、袋Bから袋Aに移した5個の碁石が白い碁石が2個、黒い碁石が3個であるので、
//最終的に袋Aには最多で5個の白い碁石がある。
}
else if (InputPattern == "Input4") {
WillReturn.Add("43682 82641");
WillReturn.Add("54647 3647");
WillReturn.Add("92674 64591");
//98240
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
int[] wkArr = { };
Action<int> SplitAct = (pIndY) =>
wkArr = InputList[pIndY].Split(' ').Select(X => int.Parse(X)).ToArray();
int ACntWhite, ACntBlack;
int BCntWhite, BCntBlack;
int TakeCntFromA, TakeCntFromB;
SplitAct(0); ACntWhite = wkArr[0]; ACntBlack = wkArr[1];
SplitAct(1); BCntWhite = wkArr[0]; BCntBlack = wkArr[1];
SplitAct(2); TakeCntFromA = wkArr[0]; TakeCntFromB = wkArr[1];
Action DebugPrintAct = () =>
{
Console.WriteLine(new string('■', 20));
Console.WriteLine("袋Aの白={0}、黒={1}。袋Bの白={2}、黒={3}",
ACntWhite, ACntBlack, BCntWhite, BCntBlack);
};
//DebugPrintAct();
//Aの袋からBの袋への移動
if (TakeCntFromA <= ACntBlack) {
ACntBlack -= TakeCntFromA;
BCntBlack += TakeCntFromA;
}
else {
int FirstMoveCnt = ACntBlack;
ACntBlack = 0;
BCntBlack += FirstMoveCnt;
int SecondMoveCnt = TakeCntFromA - FirstMoveCnt;
ACntWhite -= SecondMoveCnt;
BCntWhite += SecondMoveCnt;
}
//DebugPrintAct();
//Bの袋からAの袋への移動
if (TakeCntFromB <= BCntWhite) {
BCntWhite -= TakeCntFromB;
ACntWhite += TakeCntFromB;
}
else {
int FirstMoveCnt = BCntWhite;
BCntWhite = 0;
ACntWhite += FirstMoveCnt;
int SecondMoveCnt = TakeCntFromB - FirstMoveCnt;
BCntBlack -= SecondMoveCnt;
ACntBlack += SecondMoveCnt;
}
//DebugPrintAct();
Console.WriteLine(ACntWhite);
}
}
aketijyuuzou