結果
| 問題 |
No.154 市バス
|
| コンテスト | |
| ユーザー |
aketijyuuzou
|
| 提出日時 | 2024-10-10 21:00:22 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 70 ms / 2,000 ms |
| コード長 | 2,400 bytes |
| コンパイル時間 | 979 ms |
| コンパイル使用メモリ | 112,164 KB |
| 実行使用メモリ | 32,532 KB |
| 最終ジャッジ日時 | 2024-10-10 21:00:24 |
| 合計ジャッジ時間 | 2,172 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 8 |
コンパイルメッセージ
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("5");
WillReturn.Add("WWWWWWWWWGR");
WillReturn.Add("WWWWGWGRR");
WillReturn.Add("WWWWWWWWWWWWWWGRRG");
WillReturn.Add("WGRWGR");
WillReturn.Add("WWWWWWWWWWWWWWWWWGGWGWGGWGWGGGWGG");
//possible
//possible
//impossible
//possible
//impossible
//1つ目:1つの系統のバスしかありません
//2つ目:2つの系統のバスがあります
//3つ目:片方の系統において,
// 終バスの後に緑のライトのバスが走っている感じでなんかおかしいです.
//4つ目:1つの系統の終バスが終わってから,
// もう一方の系統が走り始めるなんてこともあるんですね.
//5つ目:終バスがないなんてことはない
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
foreach (string EachStr in InputList.Skip(1)) {
if (IsPossible(EachStr)) Console.WriteLine("possible");
else Console.WriteLine("impossible");
}
}
static bool IsPossible(string pStr)
{
//正規表現RBW+を受信するオートマンの、現在位置ごとの件数
int RCnt = 0;
int GCnt = 0;
int WCnt = 0;
foreach (char CurrChar in pStr.Reverse()) {
if (CurrChar == 'R') {
RCnt++;
}
else if (CurrChar == 'G') {
if (RCnt == 0) return false;
RCnt--; GCnt++;
}
else if (CurrChar == 'W') {
if (GCnt > 0) {
GCnt--; WCnt++;
}
else if (WCnt == 0) return false;
}
}
if (RCnt > 0) return false;
if (GCnt > 0) return false;
return true;
}
}
aketijyuuzou