結果

問題 No.145 yukiover
ユーザー greentea011greentea011
提出日時 2019-04-09 15:36:16
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,813 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 42,824 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 15:52:31
合計ジャッジ時間 1,451 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <algorithm>

int main() {
    int a[9] = {0};
    int n;
    char c;
    scanf("%d\n",&n);
    for(int i=0;i<n;i++){
        scanf("%c",&c);
        if      (c <= 'h') a[0]++;
        else if (c == 'i') a[1]++;
        else if (c == 'j') a[2]++;
        else if (c == 'k') a[3]++;
        else if (c <= 't') a[4]++;
        else if (c == 'u') a[5]++;
        else if (c <= 'x') a[6]++;
        else if (c == 'y') a[7]++;
        else               a[8]++;
    }
    int happy=a[8];
    a[8]=0;
    if (a[7] && a[6]) {
        int dd=std::min({a[7],a[6]});
        happy+=dd;
        a[7]-=dd;
        a[6]-=dd;
    }
    if (a[7] && a[5] && a[4]) {
        int dd=std::min({a[7],a[5],a[4]});
        happy+=dd;
        a[7]-=dd;
        a[5]-=dd;
        a[4]-=dd;
    }
    if (a[7] && a[5] && a[3] && a[2]) {
        int dd=std::min({a[7],a[5],a[3],a[2]});
        happy+=dd;
        a[7]-=dd;
        a[5]-=dd;
        a[3]-=dd;
        a[2]-=dd;
    }
    if (a[7] && a[5] && a[3] && a[1] && a[0]) {
        int dd=std::min({a[7],a[5],a[3],a[1],a[0]});
        happy+=dd;
        a[7]-=dd;
        a[5]-=dd;
        a[3]-=dd;
        a[1]-=dd;
        a[0]-=dd;
    }
    if (a[7] && a[5] && a[3] && (a[1]>=2)) {
        int dd=std::min({a[7],a[5],a[3],a[1]/2});
        happy+=dd;
        a[7]-=dd;
        a[5]-=dd;
        a[3]-=dd;
        a[1]-=(2*dd);
    }
    if (a[7] && a[5] && (a[3]>=2)) {
        int dd=std::min({a[7],a[5],a[3]/2});
        happy+=dd;
        a[7]-=dd;
        a[5]-=dd;
        a[3]-=(2*dd);
    }
    if (a[7] && (a[5]>=2)) {
        int dd=std::min({a[7],a[5]/2});
        happy+=dd;
        a[7]-=dd;
        a[5]-=(2*dd);
    }
    if (a[7]>=2) {
        int dd=a[7]/2;
        happy+=dd;
        a[7]-=(2*dd);
    }
    printf ("%d\n",happy);
}
0