Submission #1308040


Source Code Expand

#include <iostream>
#include <vector>
using namespace std;

bool is_valid(int idx, long long prev, const vector<vector<bool>> & xy){
    int pos = 0;
    while (prev){
        if (prev & 1){
            if (xy[idx][pos]) return false;
        }
        prev >>= 1;
        ++pos;
    }
    return true;
}

void update_dp(long long pat, int N, vector<long long> & dp,const vector<vector<bool>> & xy){
    for (int idx = 0; idx != N; ++idx){
        if (pat & (1LL << idx)){
            long long prev = pat - (1LL << idx);
            if (dp[prev] and is_valid(idx, prev, xy)) dp[pat] += dp[prev];
        }
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    long long L = 1LL << N;
    vector<vector<bool>> xy(N, vector<bool>(N, false));
    for (int m = 0; m != M; ++m){
        int x, y;
        cin >> x >> y;
        xy[x - 1][y - 1] = true;
    }
    vector<long long> dp(L, 0LL);
    dp[0] = 1LL;
    for (long long pat = 1LL; pat != L; ++pat){
        update_dp(pat, N, dp, xy);
    }
    cout << dp[L - 1] << endl;
    return 0;
}

Submission Info

Submission Time
Task D - 徒競走
User rpy3cpp
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1088 Byte
Status AC
Exec Time 30 ms
Memory 768 KB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 30 / 30 70 / 70
Status
AC × 3
AC × 15
AC × 32
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt
Subtask1 0_00.txt, 0_01.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 2_00.txt, 2_01.txt, 2_02.txt, 2_03.txt, 2_04.txt, 2_05.txt, 2_06.txt, 2_07.txt, 2_08.txt, 2_09.txt, 2_10.txt, 2_11.txt, 2_12.txt, 2_13.txt, 2_14.txt, 2_15.txt
Case Name Status Exec Time Memory
0_00.txt AC 1 ms 256 KB
0_01.txt AC 1 ms 256 KB
0_02.txt AC 30 ms 768 KB
1_00.txt AC 1 ms 256 KB
1_01.txt AC 1 ms 256 KB
1_02.txt AC 1 ms 256 KB
1_03.txt AC 1 ms 256 KB
1_04.txt AC 1 ms 256 KB
1_05.txt AC 1 ms 256 KB
1_06.txt AC 1 ms 256 KB
1_07.txt AC 1 ms 256 KB
1_08.txt AC 1 ms 256 KB
1_09.txt AC 1 ms 256 KB
1_10.txt AC 1 ms 256 KB
1_11.txt AC 1 ms 256 KB
1_12.txt AC 1 ms 256 KB
2_00.txt AC 30 ms 768 KB
2_01.txt AC 23 ms 768 KB
2_02.txt AC 23 ms 768 KB
2_03.txt AC 24 ms 768 KB
2_04.txt AC 11 ms 512 KB
2_05.txt AC 7 ms 512 KB
2_06.txt AC 11 ms 512 KB
2_07.txt AC 8 ms 512 KB
2_08.txt AC 25 ms 768 KB
2_09.txt AC 20 ms 768 KB
2_10.txt AC 19 ms 768 KB
2_11.txt AC 11 ms 768 KB
2_12.txt AC 28 ms 768 KB
2_13.txt AC 26 ms 768 KB
2_14.txt AC 27 ms 768 KB
2_15.txt AC 28 ms 768 KB