結果

問題 No.2152 [Cherry Anniversary 2] 19 Petals of Cherry
ユーザー lddlinan
提出日時 2023-03-23 22:21:14
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,710 bytes
コンパイル時間 785 ms
コンパイル使用メモリ 87,324 KB
最終ジャッジ日時 2025-02-11 16:32:14
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 38 TLE * 11
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:63:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   63 |         scanf("%d", &n); cs[i]=n;
      |         ~~~~~^~~~~~~~~~
main.cpp:65:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   65 |             scanf("%d", &vs[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~~

ソースコード

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