結果

問題 No.2152 [Cherry Anniversary 2] 19 Petals of Cherry
ユーザー lddlinanlddlinan
提出日時 2023-03-23 22:21:14
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,710 bytes
コンパイル時間 705 ms
コンパイル使用メモリ 86,204 KB
実行使用メモリ 163,612 KB
最終ジャッジ日時 2023-10-18 19:41:46
合計ジャッジ時間 32,391 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
93,980 KB
testcase_01 AC 32 ms
143,132 KB
testcase_02 AC 6 ms
20,252 KB
testcase_03 AC 844 ms
163,612 KB
testcase_04 AC 285 ms
163,612 KB
testcase_05 AC 640 ms
163,612 KB
testcase_06 AC 336 ms
163,612 KB
testcase_07 AC 263 ms
163,612 KB
testcase_08 AC 112 ms
163,612 KB
testcase_09 AC 148 ms
163,612 KB
testcase_10 AC 532 ms
163,612 KB
testcase_11 AC 179 ms
163,612 KB
testcase_12 AC 126 ms
163,612 KB
testcase_13 AC 207 ms
163,612 KB
testcase_14 AC 502 ms
163,612 KB
testcase_15 AC 377 ms
163,612 KB
testcase_16 AC 265 ms
163,612 KB
testcase_17 AC 587 ms
163,612 KB
testcase_18 AC 686 ms
163,612 KB
testcase_19 AC 495 ms
163,612 KB
testcase_20 AC 40 ms
163,612 KB
testcase_21 AC 537 ms
163,612 KB
testcase_22 AC 276 ms
163,612 KB
testcase_23 AC 273 ms
163,612 KB
testcase_24 TLE -
testcase_25 AC 398 ms
163,612 KB
testcase_26 AC 715 ms
163,612 KB
testcase_27 AC 375 ms
163,612 KB
testcase_28 AC 20 ms
93,980 KB
testcase_29 AC 35 ms
163,612 KB
testcase_30 AC 62 ms
163,612 KB
testcase_31 AC 169 ms
163,612 KB
testcase_32 AC 337 ms
163,612 KB
testcase_33 AC 514 ms
163,612 KB
testcase_34 AC 662 ms
163,612 KB
testcase_35 AC 799 ms
163,612 KB
testcase_36 AC 882 ms
163,612 KB
testcase_37 TLE -
testcase_38 TLE -
testcase_39 TLE -
testcase_40 TLE -
testcase_41 TLE -
testcase_42 TLE -
testcase_43 TLE -
testcase_44 TLE -
testcase_45 TLE -
testcase_46 TLE -
testcase_47 AC 6 ms
20,252 KB
testcase_48 AC 395 ms
163,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <algorithm>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <string>
using namespace std;

bool rcmp(int a, int b) { return a>b; }
typedef long long LL;
class mypcmp {
public:
    bool operator()(const int& a, const int& b) {
        return a<b;
    }
};


int vs[19][19];
int cs[19];
LL dp[2][19][1<<19];
char dpm[19][1<<19];
void dfs(int i, int m) {
    if (m==0) i=0;
    if (dpm[i][m]) return;
    dpm[i][m]=1;
    int nm, x;
    LL r1=0, r0=0;
    int j=0; for (j=0; j<19; j++) if ((1<<j)&m) break;
    int nj; for (nj=j+1; nj<19; nj++) if ((1<<nj)&m) break;
    if (nj>=19) nj=0;
    // printf("dfs %d %x, j is %d, nj is %d\n", i, m, j, nj);
    int k; for (k=0; k<cs[i]; k++) {
        x = vs[i][k];
        if (x==j) {
            if (((1<<x)&m)==0) printf("something wrong\n");
            nm = m^(1<<x);
            dfs(nj, nm);
            r0+=dp[1][nj][nm];
            r1+=dp[0][nj][nm];
        } else {
            if (((1<<x)&m)==0) continue;
            nm = m^(1<<x);
            dfs(x, nm);
            r1+=dp[1][x][nm];
            r0+=dp[0][x][nm];
        }
    }
    dp[0][i][m]=r0;
    dp[1][i][m]=r1;
}
int main() {
    int n, i, j, mm;
    for (i=0; i<19; i++) {
        scanf("%d", &n); cs[i]=n;
        for (j=0; j<n; j++) {
            scanf("%d", &vs[i][j]);
            vs[i][j]--;
        }
    }
    memset(dpm, 0, sizeof(dpm));
    dp[0][0][0]=0; dp[1][0][0]=1;
    dpm[0][0]=1;
    mm=(1<<19)-1;
    dfs(0, mm);
    printf("%lld %lld\n", dp[0][0][mm], dp[1][0][mm]);
    return 0;
}
0