結果

問題 No.145 yukiover
ユーザー cormorancormoran
提出日時 2016-12-27 18:25:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,525 bytes
コンパイル時間 1,483 ms
コンパイル使用メモリ 167,584 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-21 15:00:56
合計ジャッジ時間 2,474 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;

int ha(char c) {
    return c - 'a';
}

class Solver {
  public:
    bool solve() {
        int N; cin >> N;
        string S; cin >> S;
        vector<int> alpha(ha('z') + 1);
        for(char c : S) alpha[ha(c)]++;
        int ans = 0;
        ans += alpha[ha('z')];
        alpha[ha('z')] = 0;

        const string yuki = "yuki";
        for(int i = 3; i >= 0; i--) {
            {
                int prefix_num = INF;
                rep(j, i + 1) set_min(prefix_num, alpha[ha(yuki[j])]);
                int suffix_num = accumulate(&alpha[i < 3 ? ha(yuki[i + 1]) + 1 : 0], &alpha[ha(yuki[i])], 0);
                int s = min(prefix_num, suffix_num);
                ans += s;
                rep(j, i + 1) alpha[ha(yuki[j])] -= s;
                for(int j = 0; s > 0; j++) {
                    int a = min(s, alpha[j]);
                    alpha[j] -= a;
                    s -= a;
                }
            }
            {
                int prefix_num = INF;
                rep(j, i + 1) set_min(prefix_num, alpha[ha(yuki[j])]);
                int suffix_num = max(alpha[ha(yuki[i])] - prefix_num,
                                     min(prefix_num, alpha[ha(yuki[i])] / 2));                
                int s = min(prefix_num, suffix_num);
                ans += s;
                rep(j, i + 1) alpha[ha(yuki[j])] -= s;               
                alpha[ha(yuki[i])] -= s;
            }
        }
        cout << ans << endl;        
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}
0