結果

問題 No.145 yukiover
ユーザー HachimoriHachimori
提出日時 2015-02-06 00:17:34
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,889 bytes
コンパイル時間 358 ms
コンパイル使用メモリ 53,584 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-05 13:23:17
合計ジャッジ時間 1,339 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
using namespace std;
const int INF = 1<<30;

string s;

void read() {
    int n;
    cin >> n >> s;
}


void work() {
    int cnt[128] = {};
    for (int i = 0; i < s.size(); ++i)
        ++cnt[(int)s[i]];
    
    int ans = 0;
    
    for (int i = 'y' + 1; i <= 'z'; ++i) {
        int nUse = cnt[i];
        ans += nUse;
        cnt[i] -= nUse;
    }
    
    for (int i = 'u' + 1; i <= 'z'; ++i) {
        int nUse = INF;
        if (i == 'y') {
            nUse = min(nUse, cnt[i] / 2);
        }
        else {
            nUse = min(nUse, cnt[i]);
        }
        
        ans += nUse;
        cnt[(int)'y'] -= nUse;
        cnt[i]        -= nUse;
    }

    for (int i = 'k' + 1; i <= 'z'; ++i) {
        int nUse = INF;
        if (i == 'y') {
            nUse = min(nUse, cnt[i] / 2);
        }
        else {
            nUse = min(nUse, cnt[i]);
        }
        if (i == 'u') {
            nUse = min(nUse, cnt[i] / 2);
        }
        else {
            nUse = min(nUse, cnt[i]);
        }
        
        ans += nUse;
        cnt[(int)'y'] -= nUse;
        cnt[(int)'u'] -= nUse;
        cnt[i]        -= nUse;
    }

    for (int i = 'i' + 1; i <= 'z'; ++i) {
        int nUse = INF;
        if (i == 'y') {
            nUse = min(nUse, cnt[i] / 2);
        }
        else {
            nUse = min(nUse, cnt[i]);
        }
        if (i == 'u') {
            nUse = min(nUse, cnt[i] / 2);
        }
        else {
            nUse = min(nUse, cnt[i]);
        }
        if (i == 'k') {
            nUse = min(nUse, cnt[i] / 2);
        }
        else {
            nUse = min(nUse, cnt[i]);
        }
        
        ans += nUse;
        cnt[(int)'y'] -= nUse;
        cnt[(int)'u'] -= nUse;
        cnt[(int)'k'] -= nUse;
        cnt[i]        -= nUse;
    }
    
    cout << ans << endl;
}


int main() {
    read();
    work();
    return 0;
}
0