結果

問題 No.145 yukiover
ユーザー h_noson
提出日時 2016-06-08 22:57:54
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,803 bytes
コンパイル時間 648 ms
コンパイル使用メモリ 66,652 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-09 04:54:39
合計ジャッジ時間 1,714 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 14 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP (i,0,(int)(n)-1)
#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP (i,(int)(n)-1,0)
#define INF (int)1e8
#define MOD (int)(1e9+7)

typedef long long ll;

int main(void) {
    int n;
    string s;
    cin >> n >> s;

    int ans = 0;
    int cnt[256] {}, sum[256];
    for (auto c : s) 
        cnt[c]++;
    ans += cnt['z'];
    n -= cnt['z'];
    cnt['z'] = 0;
    sum['z'] = 0;
    for (char c = 'y'; c >= 'a'; c--)
        sum[c] = sum[c+1] + cnt[c];
    int x = min({sum['y'],sum['u']/2,sum['k']/3,sum['j']/4});
    ans += x;
    cnt['y'] -= x;
    int tmp = x;
    for (char c = 'j'; tmp > 0 && c <= 'y'; c++) {
        int y = min(cnt[c],tmp);
        tmp -= y;
        cnt[c] -= y;
    }
    tmp = tmp;
    for (char c = 'k'; tmp > 0 && c <= 'y'; c++) {
        int y = min(cnt[c],tmp);
        tmp -= y;
        cnt[c] -= y;
    }
    tmp = tmp;
    for (char c = 'u'; tmp > 0 && c <= 'y'; c++) {
        int y = min(cnt[c],tmp);
        tmp -= y;
        cnt[c] -= y;
    }

    sum['z'] = 0;
    for (char c = 'y'; c >= 'a'; c--)
        sum[c] = sum[c+1] + cnt[c];
    x = min({sum['y'],sum['u']/2,sum['l']/3});
    ans += x;
    cnt['y'] -= x;
    tmp = x;
    for (char c = 'l'; tmp > 0 && c <= 'y'; c++) {
        int y = min(cnt[c],tmp);
        tmp -= y;
        cnt[c] -= y;
    }
    tmp = x;
    for (char c = 'u'; tmp > 0 && c <= 'y'; c++) {
        int y = min(cnt[c],tmp);
        tmp -= y;
        cnt[c] -= y;
    }

    sum['z'] = 0;
    for (char c = 'y'; c >= 'a'; c--)
        sum[c] = sum[c+1] + cnt[c];
    x = min({sum['y'],sum['v']/2});
    ans += x;
    cout << ans << endl;
    return 0;
}
0