結果

問題 No.73 helloworld
ユーザー なおなお
提出日時 2014-11-21 00:23:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,142 bytes
コンパイル時間 1,184 ms
コンパイル使用メモリ 145,912 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-11 07:26:19
合計ジャッジ時間 1,993 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))
#define REPEAT(i, k, n)     for(int(i)=(k);(i)<((k)+(n));++(i))

int C[27],U[27];

int comb(int n, int m){
    int k = 1;
    for(int i = 0; i < m; i++){
        k *= (n-i);
    }
    for(int i = 2; i <= m; i++){
        k /= i;
    }
    return k;
}

int main(){
    const string s = "helloworld";
    REP(i,27){
        cin >> C[i];
    }
    REP(i,(int)s.size()){
        int c = s[i]-'a';
        U[c]++;
        if(C[c]-U[c] < 0){
            cout << 0 << endl;
            return 0;
        }
    }
    ll k = 1;
    REP(i,27){
        if(!U[i]) continue;
        if(i == ('l'-'a')){
        } else if(i == ('o'-'a')){
        } else {
            k *= C[i];
        }
    }
    ll maxv = 0;
    int i = 'l'-'a';
    REP(j,C[i]-U[i]+1){
        maxv = max(maxv, k*comb(j+2,2)*(C[i]-U[i]-j+1));
    }
    k = maxv;

    i = 'o'-'a';
    REP(j,C[i]-U[i]+1){
        maxv = max(maxv, k*(j+1)*(C[i]-U[i]-j+1));
    }

    cout << maxv << endl;
    return 0;
}
0