QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#574651#7925. Chayassea_birdWA 0ms3620kbC++201.6kb2024-09-18 23:33:582024-09-18 23:34:07

Judging History

你现在查看的是最新测评结果

  • [2024-09-18 23:34:07]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3620kb
  • [2024-09-18 23:33:58]
  • 提交

answer

#include<bits/stdc++.h>
typedef long long ll;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
const ll mod = 998244353;
ll f[1 << 24];
bool g[25][25][25];
bool fg[25][25];
int cnt = 0;
pii arr[10100];
int np[25][25];
void solve() {
    int n, m;
    std::cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int a, b, c;
        std::cin >> a >> b >> c;
        g[a][b][c] = true;
        g[c][b][a] = true;
    }
    for (int a = 1; a <= n; a++) {
        for (int b = 1; b <= n; b++) {
            for (int c = 1; c <= n; c++) {
                if (g[c][a][b] or g[c][b][a]) {
                    np[a][b] |= (1 << (c - 1));
                }
            }
        }
    }
    for(int a = 1;a <= n;a++){
        for(int b = a;b <= n;b++){
            np[a][b] |= np[b][a];
        }
    }
    f[0] = 1;
    for (int p = 0; p < (1 << n); p++) {
        int x = 0;
        for (int a = 1; a <= n; a++) {
            if(!(p & (1 << (a - 1))))
                continue;
            for (int b = a; b <= n; b++) {
                if ((!(p & (1 << (b - 1))))) {
                    x |= np[a][b];
                }
            }
        }
        for (int c = 1; c <= n; c++) {
            if (p & (1 << (c - 1)))
                continue;
            if (!(x & (1 << (c - 1)))) {
                f[p | (1 << (c - 1))] = (f[p | (1 << (c - 1))] + f[p]) % mod;
            }
        }
    }
    std::cout << f[(1 << n) - 1] << "\n";
}
int main() {
    std::ios::sync_with_stdio(0);
    std::cin.tie(0), std::cout.tie(0);
    int t = 1;
    while (t--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3620kb

input:

5 4
1 2 4
2 3 5
3 2 4
1 3 2

output:

30

result:

wrong answer 1st lines differ - expected: '4', found: '30'