結果

問題 No.398 ハーフパイプ(2)
ユーザー mamekinmamekin
提出日時 2016-10-07 16:32:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 2,763 bytes
コンパイル時間 1,011 ms
コンパイル使用メモリ 108,164 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2023-09-09 23:08:13
合計ジャッジ時間 2,075 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
7,296 KB
testcase_01 AC 13 ms
7,152 KB
testcase_02 AC 13 ms
7,072 KB
testcase_03 AC 14 ms
7,184 KB
testcase_04 AC 13 ms
7,264 KB
testcase_05 AC 14 ms
7,136 KB
testcase_06 AC 13 ms
7,136 KB
testcase_07 AC 13 ms
7,160 KB
testcase_08 AC 12 ms
7,032 KB
testcase_09 AC 13 ms
7,024 KB
testcase_10 AC 14 ms
7,028 KB
testcase_11 AC 14 ms
7,024 KB
testcase_12 AC 13 ms
7,028 KB
testcase_13 AC 14 ms
7,264 KB
testcase_14 AC 13 ms
7,264 KB
testcase_15 AC 13 ms
7,072 KB
testcase_16 AC 13 ms
7,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

/*
●解法
    点数の小さい順に値を確定させていく動的計画法。
    前回の点数、合計点数、連続した同じ点数の人数を状態として持つ。

    ・全員が違う点数
      A < B < C < D < E < F
      ↓
      6 * 5 * 4 * 3 * 2 * 1 通りの並べ方が存在

    ・同じ点数の人が存在
      A = B < C = D = E < F
      ↓
      6 * 5   4 * 3 * 2
      ----- * --------- * 1 通り
      1 * 2   1 * 2 * 3

      →同じ点数の人が2人いれば2で割る、3人いればさらに3で割る、…
        というように計算すると最低点、最高点を状態として持つ必要がなくなる。

●計算量
    審査員が n 人、各審査員の点数を s とすると、
    計算量は O((n*s)^3) となる。
*/

int main()
{
    const int n        = 6;
    const int score    = 100;
    const int maxScore = (n - 2) * score;

    vector<vector<vector<long long> > > dp(n, vector<vector<long long> >(score + 1, vector<long long>(maxScore + 1, 0)));
    dp[0][0][0] = 1;
    for(int i=1; i<=n; ++i)
        dp[0][0][0] *= i;

    for(int i=0; i<n; ++i){
        vector<vector<vector<long long> > > nextDp(n, vector<vector<long long> >(score + 1, vector<long long>(maxScore + 1, 0)));
        for(int a=0; a<n; ++a){
            for(int b=0; b<=score; ++b){
                for(int c=0; c<=maxScore; ++c){
                    if(dp[a][b][c] == 0)
                        continue;

                    for(int b2=b; b2<=score; ++b2){
                        int c2 = c;
                        if(0 < i && i < n - 1)
                            c2 += b2;

                        if(i > 0 && b == b2)
                            nextDp[a+1][b2][c2] += dp[a][b][c] / (a + 2);
                        else
                            nextDp[0][b2][c2] += dp[a][b][c];
                    }
                }
            }
        }
        dp.swap(nextDp);
    }

    int x1, x2;
    char c;
    cin >> x1 >> c >> x2;
    int x = x1 * 100 + x2;

    long long ans = 0;
    for(int a=0; a<n; ++a){
        for(int b=0; b<=100; ++b){
            for(int c=0; c<=maxScore; ++c){
                if(c * 100 / (n - 2) == x)
                    ans += dp[a][b][c];
            }
        }
    }
    cout << ans << endl;

    return 0;
}
0