結果

問題 No.154 市バス
ユーザー furafyfurafy
提出日時 2015-05-27 00:54:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 858 bytes
コンパイル時間 559 ms
コンパイル使用メモリ 60,128 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 08:32:46
合計ジャッジ時間 1,466 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
5,248 KB
testcase_01 AC 26 ms
5,376 KB
testcase_02 AC 26 ms
5,376 KB
testcase_03 AC 25 ms
5,376 KB
testcase_04 AC 24 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 21 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘bool judge(std::string)’:
main.cpp:44:24: warning: ‘r’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   44 |                 count[r]++;
      |                        ^

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>

using namespace std;

bool judge(string);

int main(int argc, char *argv[]) {
	int T;
	string pattern;
	cin >> T;
	for (int i = 0; i < T; i++) {
		cin >> pattern;
		cout << (judge(pattern) ? "possible" : "impossible") << endl;
	}
	return 0;
}
bool judge(string s) {
	vector<int> count(3);
	vector<int> final(3);
	int len = s.length();
	int ch;
	int r;
	for (int i = 0; i < len; i++) {
		ch = s[i];
		switch (ch) {
		case 'W':
			r = 0;
			break;
		case 'G':
			r = 1;

			break;
		case 'R':
			r = 2;

			break;
		}
		if (count[1] > count[0])
			return false;
		if (count[2] > count[1])
			return false;
		count[r]++;
		final[r] = i;
	}
	if (count[2] == 0)
		return false;
	if (count[2] != count[1])
		return false;
	if ((final[0] > final[1]) || (final[0] > final[2]))
		return false;
	return true;
}
0