結果

問題 No.291 黒い文字列
ユーザー tubo28tubo28
提出日時 2015-10-16 23:09:44
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,009 bytes
コンパイル時間 1,208 ms
コンパイル使用メモリ 146,240 KB
実行使用メモリ 41,824 KB
最終ジャッジ日時 2023-09-29 01:39:34
合計ジャッジ時間 3,115 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
41,508 KB
testcase_01 AC 22 ms
41,492 KB
testcase_02 AC 21 ms
41,540 KB
testcase_03 AC 21 ms
41,508 KB
testcase_04 AC 22 ms
41,560 KB
testcase_05 AC 21 ms
41,560 KB
testcase_06 AC 22 ms
41,536 KB
testcase_07 AC 22 ms
41,508 KB
testcase_08 AC 22 ms
41,536 KB
testcase_09 AC 22 ms
41,820 KB
testcase_10 AC 22 ms
41,548 KB
testcase_11 AC 22 ms
41,556 KB
testcase_12 AC 22 ms
41,576 KB
testcase_13 AC 22 ms
41,628 KB
testcase_14 AC 22 ms
41,624 KB
testcase_15 AC 22 ms
41,540 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 24 ms
41,552 KB
testcase_19 WA -
testcase_20 AC 28 ms
41,508 KB
testcase_21 AC 22 ms
41,632 KB
testcase_22 WA -
testcase_23 AC 27 ms
41,544 KB
testcase_24 WA -
testcase_25 AC 21 ms
41,744 KB
testcase_26 AC 22 ms
41,820 KB
testcase_27 AC 22 ms
41,552 KB
testcase_28 AC 22 ms
41,568 KB
testcase_29 AC 22 ms
41,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) begin(c), end(c)
#define range(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) range(i,0,b)
#define rangei(i,a,b) for(ll a=a;i<=ll(b);i++)
#define repi(i,b) rangei(i,1,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator << (ostream &os, vector<T> const &);
template<int n, class...T>
typename enable_if<(n>=sizeof...(T))>::type
_ot(ostream &, tuple<T...> const &){}
template<int n, class...T>
typename enable_if<(n< sizeof...(T))>::type
_ot(ostream &os, tuple<T...> const &t){
    os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t);
}
template<class...T>
ostream & operator << (ostream &os, tuple<T...> const &t){
    _ot<0>(os, t); return os;
}
template<class T, class U>
ostream & operator<<(ostream &os, pair<T,U> const &p){
    return os << "(" << p.first << ", " << p.second << ") ";
}
template<class T>
ostream & operator<<(ostream &os, vector<T> const &v){
    rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os;
}
#ifdef DEBUG
#define dump(...) (cerr << #__VA_ARGS__ << " = " << mt(__VA_ARGS__) \
                   << " [" << __LINE__ << "]" << endl)
#else
#define dump(...)
#endif
void fastios(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    // #define endl '\n'
}
template<class T>
size_t uniq(vector<T> &v){
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v.size();
}
template<class T>
size_t uniq(T *l, size_t n){
    sort(l,l+n);
    return unique(l,l+n) - l;
}
#define mems(arr,val) memset(arr,val,sizeof(arr));
int const inf = numeric_limits<int>::max()/8;

int dp[25][25][25][25][25];
int n;
string s;

int rec(int k, int u, int r, int o, int i, int pos){
    int & res = dp[k][u][r][o][i];
    char c = s[pos];
    if(res != -1) return res;
    if(pos == n) return res = 0;
    // res = 0;
    if((c == 'k' || (c == '?')) && k != 0){
        res = max(res, rec(k-1,u+1,r,o,i,pos+1));
    }
    if((c == 'u' || (c == '?')) && u != 0){
        res = max(res, rec(k,u-1,r+1,o,i,pos+1));
    }
    if((c == 'r' || (c == '?')) && r != 0){
        res = max(res, rec(k,u,r-1,o+1,i,pos+1));
    }
    if((c == 'o' || (c == '?')) && o != 0){
        res = max(res, rec(k,u,r,o-1,i+1,pos+1));
    }
    if((c == 'i' || (c == '?')) && i != 0){
        res = max(res, rec(k,u,r,o,i-1,pos+1) + 1);
    } 
    res = max(res, rec(k,u,r,o,i,pos+1));
    dump(k,u,r,o,i,pos, res);
    return res;
}

int solve(){
    n = s.size();
    memset(dp,-1,sizeof(dp));
    for(char &c : s) c = tolower(c);
    int ans = rec(24,0,0,0,0,0);
    int *b = (int*)dp;
    int *e = b + sizeof(dp) / sizeof(int);
    ans = max(ans, *max_element(b,e));
    return ans;
}

int main(){
    while(cin >> s && s != "~") cout << solve() << endl;
}
0