結果
| 問題 |
No.291 黒い文字列
|
| コンテスト | |
| ユーザー |
hirokazu1020
|
| 提出日時 | 2015-10-16 23:46:07 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,452 bytes |
| コンパイル時間 | 955 ms |
| コンパイル使用メモリ | 97,444 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-21 20:46:57 |
| 合計ジャッジ時間 | 1,582 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 19 WA * 7 |
コンパイルメッセージ
main.cpp:29:11: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
29 | char *c = "KUROI";
| ^~~~~~~
ソースコード
#define _CRT_SECURE_NO_WARNINGS
#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())
#define indexOf(v,x) (find(all(v),x)-v.begin())
char *c = "KUROI";
int count(string s) {
int cnt = 0;
while (1) {
int i = 0;
bool k = false;
rep(j, s.size()) {
if (c[i] == s[j]) {
i++;
if (i == 5) {
i = 0;
cnt++;
k = true;
}
s[j] = '.';
}
}
if (!k)break;
}
return cnt;
}
bool f(string s, int n) {
int a[5] = {};
rep(i, s.size()) {
if (s[i] != '?') {
if (s[i] == 'K')a[0]++;
else if (s[i] == 'U'&&a[0]>a[1])a[1]++;
else if (s[i] == 'R'&&a[1]>a[2])a[2]++;
else if (s[i] == 'O'&&a[2]>a[3])a[3]++;
else if (s[i] == 'I'&&a[3]>a[4])a[4]++;
}
else {
rep(j, 5) {
if (a[j]<n) {
s[i] = c[j];
a[j]++;
break;
}
}
}
}
return n <= count(s);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string s;
cin >> s;
int ans = 0;
rep(i, s.size() / 5 + 1) {
if (f(s, i))ans = i;
}
cout << ans << endl;
return 0;
}
hirokazu1020