結果

問題 No.1035 Color Box
ユーザー simojisimoji
提出日時 2020-04-26 20:46:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,004 bytes
コンパイル時間 1,523 ms
コンパイル使用メモリ 166,336 KB
実行使用メモリ 13,888 KB
最終ジャッジ日時 2024-04-29 07:22:12
合計ジャッジ時間 5,124 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
10,020 KB
testcase_01 WA -
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;
    //cout << "n " << n << " m " << m << endl;
    int numInkBottol = m;
    int numWanabePainted =n;
    long patterns = 1;
    mod = (long)pow(10,9)+7;
    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;
        }

    }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;
    long top = 1;
    long bottom = 1;
    //cout << "all " << all << " select " << select << endl;
    for (int i = 0; i < select; i++){
        top *= all-i;
        bottom *= select-i;
        top %= mod;
        bottom %= mod;
        //cout << "i " << i  << " top " << top << " bottom " << bottom << endl;
    }
    if(top < bottom){
        top+=mod;
    }
    ret = top / bottom;
    //cout << "combination " << ret  << " top " << top << " bottom " << bottom << endl;
    return ret;
}
0