結果

問題 No.1001 注文の多い順列
ユーザー tsutajtsutaj
提出日時 2020-02-23 12:29:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 814 bytes
コンパイル時間 559 ms
コンパイル使用メモリ 66,268 KB
実行使用メモリ 68,736 KB
最終ジャッジ日時 2024-04-18 08:32:32
合計ジャッジ時間 8,333 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 74 ms
20,480 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 4 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 198 ms
39,296 KB
testcase_12 AC 3 ms
6,940 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const ll mod=1e9+7 ;


ll dp[20][1<<20];
int main(){
    int n;
    cin>>n;
    int all = 1<<n;
    dp[0][0]=1;
    rep(i,n){
        int x, y;
        cin>>x>>y;
        if(x){
            rep(j,all)REP(k,y-1,n){
                if(j & (1<<k))continue;
                dp[i+1][j|(1<<k)]+=dp[i][j];
                if(dp[i+1][j|(1<<k)]>=mod)dp[i+1][j|(1<<k)]-=mod;
            }
        }
        else {
            rep(j,all)rep(k,y){
                if(j & (1<<k))continue;
                dp[i+1][j|(1<<k)]+=dp[i][j];
                if(dp[i+1][j|(1<<k)]>=mod)dp[i+1][j|(1<<k)]-=mod;
            }
        }
    }
    cout<<dp[n][all-1]<<endl;
    return 0;
}
0