結果
問題 | No.154 市バス |
ユーザー | matsu |
提出日時 | 2018-09-13 13:29:26 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 75 ms / 2,000 ms |
コード長 | 1,823 bytes |
コンパイル時間 | 2,052 ms |
コンパイル使用メモリ | 104,828 KB |
実行使用メモリ | 26,868 KB |
最終ジャッジ日時 | 2023-09-13 19:48:47 |
合計ジャッジ時間 | 3,425 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 74 ms
26,868 KB |
testcase_01 | AC | 75 ms
26,840 KB |
testcase_02 | AC | 74 ms
24,884 KB |
testcase_03 | AC | 72 ms
26,868 KB |
testcase_04 | AC | 74 ms
26,844 KB |
testcase_05 | AC | 54 ms
22,688 KB |
testcase_06 | AC | 54 ms
20,596 KB |
testcase_07 | AC | 70 ms
24,752 KB |
testcase_08 | AC | 53 ms
20,712 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; namespace bus { class Program { static void Main(string[] args) { // テストケースの数 整数 "T" int Num_T = int.Parse(Console.ReadLine()); // テストケース文字列を1文字ずつ判定 for (int i = 0; i < Num_T; i++) { // テストケース文字列 "S" string str_S = Console.ReadLine(); Console.WriteLine(judgingLight(str_S)); } } static string judgingLight(string str) { int wht = 0; // 白色カウント int grn = 0; // 緑色カウント int red = 0; // 赤色カウント char pre = ' '; // 直前の色を記憶 // 一文字ずつ検索する for (int i = 0; i < str.Length; i++) { if (str[i] == 'W') { wht++; } if (str[i] == 'G') { grn++; } if (str[i] == 'R') { red++; } else { pre = str[i]; } // "白 < 緑"もしくは"緑 < 赤" になるタイミングは絶対に存在しない if (wht < grn || grn < red) { return "impossible"; } } // 最後の直前が "G(緑)" かつ "緑と赤の数が同じ"ときのみ存在する if (pre == 'G' && grn == red) { return "possible"; } else { return "impossible"; } } } }