結果
| 問題 |
No.291 黒い文字列
|
| コンテスト | |
| ユーザー |
startcpp
|
| 提出日時 | 2015-10-16 23:38:46 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 864 bytes |
| コンパイル時間 | 641 ms |
| コンパイル使用メモリ | 56,580 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-21 20:44:26 |
| 合計ジャッジ時間 | 1,490 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 13 WA * 13 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:14:21: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
14 | char *sub = "KUROI";
| ^~~~~~~
ソースコード
//自信のない解法。左からgreedyにKUROIを作っていく、?は無視する。
//もう一度左からKUROIを作っていく。
#include <iostream>
#include <string>
using namespace std;
int main()
{
static string s;
static bool used[100] = {false};
cin >> s;
char *sub = "KUROI";
int cor = 0, cnt = 0;
for( int i = 0; i < s.length(); i++ ){
if( s[i] == sub[cor] ){
cor = (cor + 1) % 5;
cnt += (cor == 0);
used[i] = true;
}
}
//中途半端な分を再度使えるようにする
for( int i = s.length() - 1; i >= 0; i-- ){
if( cor == 0 )
break;
if( used[i] ){
cor = (cor + 4) % 5;
used[i] = false;
}
}
for( int i = 0; i < s.length(); i++ ){
if( (s[i] == sub[cor] || s[i] == '?') && !used[i] ){
cor = (cor + 1) % 5;
cnt += (cor == 0);
used[i] = true;
}
}
cout << cnt << endl;
return 0;
}
startcpp