結果

問題 No.1035 Color Box
ユーザー simojisimoji
提出日時 2020-04-27 18:30:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,704 bytes
コンパイル時間 1,653 ms
コンパイル使用メモリ 171,308 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-05-01 20:14:22
合計ジャッジ時間 5,242 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 RE -
testcase_02 WA -
testcase_03 AC 2 ms
5,376 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
long mod = 0;
long getDublicatedPatterns(int cubes, int colors);
inline long getCombination(int all, int select);
int main(){
    int n,m;
    cin >> n;
    cin >> m;
    //s << "n " << n << " m " << m << endl;
    int numInkBottol = m;
    int numWanabePainted =n;
    long patterns = 1;
    mod = (long)pow(10,9)+7;

    //long tmp = getCombination(45,43);
    //cout << tmp << endl;
    //return 0;

    if (numWanabePainted > numInkBottol) {

        patterns = getDublicatedPatterns(numWanabePainted,numInkBottol);
        //cout << patterns << endl;
        int plusMinus = 1;
        for(int i = numInkBottol;i > 0; i--){
            patterns = patterns - (plusMinus * getCombination(numInkBottol,i -1) * getDublicatedPatterns(numWanabePainted,i-1));
            patterns = patterns % mod;
            plusMinus *= -1;
            //cout << patterns << endl;
        }
        if(patterns < 0){
            patterns = mod + patterns;
        }

    }else{
        //インクの種類が十分多い
        //順番にインクのバケツにいれる。
        for (int i = numInkBottol; i > 0; i--){
            patterns = patterns * i;
            patterns = patterns % mod;
        }
    }
    cout << patterns << endl;
}
inline long getDublicatedPatterns(int cubes, int colors){
    long ret = 1;
    for(int i = cubes;i>0;i--){
        ret = ret*colors;
        ret = ret % mod;
        //cout << "i " << i << " colors " <<colors << " ret " << ret << endl;
    }
    //cout << "colors " <<colors << " ret " << ret << endl;
    return ret;
}
inline long getCombination(int all, int select){
    long ret = 1;
    vector <int> top;
    vector <int> bottom;
    for(int i = select;i > 0; i--){
        top.push_back(all-(select-i));
        bottom.push_back(i);
    }
    for(int i = 0; i < select;i++){
        //cout << " " << top[i];
    }
    //cout << endl;
    for(int i = 0; i < select;i++){
        //cout << " " << bottom[i];
    }
    //cout << endl;
    for(int i = 0; i< select;i++){
        if(bottom[i]!=1){
            for(int j =0 ; j < select; j++){
                if(top[j]%bottom[i]==0){
                    top[j] = (top[j]/bottom[i]);
                    bottom[i] = 1;
                }
            }
        }
    }
    long topTmp = 1;
    long bottomTmp = 1;
    for(int i = 0; i < select;i++){
        //cout << " " << top[i];
        topTmp*=top[i];
        bottomTmp*=bottom[i];
    }
    //cout << endl;
    for(int i = 0; i < select;i++){
        //cout << " " << bottom[i];
    }
    ret = topTmp/bottomTmp;

    //cout << "conbination " << ret << " all " << all << " select " << select<<  endl;
     return ret;
}
0