QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#80112#5523. Graph Problem With Small $n$WTR2007WA 2ms3536kbC++141.4kb2023-02-22 12:42:122023-02-22 12:42:15

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-22 12:42:15]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3536kb
  • [2023-02-22 12:42:12]
  • 提交

answer

#include<bits/stdc++.h>
#define MULT_TEST 0
using namespace std;
const int INF = 0x3f3f3f3f;
const int M = 24;
const int N = (1 << M);
char tmp[M];
int dp[N], to[M];
inline int read() {
    int w = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if(ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        w = (w << 1) + (w << 3) + ch - 48;
        ch = getchar();
    }
    return w * f;
}
inline void Solve() {
    int n;
    n = read();
    for (int i = 0; i < n; i++) {
        scanf("%s", tmp);
        for (int j = 0; j < n; j++) to[i] |= (tmp[j] - '0') * (1 << j);
        cout << to[i]  << endl;
    }
    dp[1] = 1;
    for (int S = 2; S < (1 << n); S++) {
        for (int i = 0; i < n; i++) {
            if (!((S >> i) & 1)) continue;
            if (dp[S - (1 << i)] & to[i]) dp[S] |= (1 << i);
        }
    }
    for (int i = 0; i < n; i++) {
        int ans = 0;
        for (int S = 0; S < (1 << n); S++) {
            if (!((S >> i) & 1)) continue;
            ans |= dp[(1 << n) - S] & to[i];
        }
        for (int j = 0; j < n; j++) {
            if ((ans >> j) & 1) printf("1");
            else printf("0");
        }
        puts("");
    }
}
signed main() {
    int T = 1;
#if MULT_TEST
    T = read();
#endif 
    while (T--) Solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3536kb

input:

4
0110
1010
1101
0010

output:

6
5
11
4
0110
1010
1100
0010

result:

wrong answer 1st lines differ - expected: '0001', found: '6'