QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#554286#8551. DFS Order 5ucup-team1231#WA 1ms12012kbC++141.6kb2024-09-09 09:58:452024-09-09 09:58:45

Judging History

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

  • [2024-09-09 09:58:45]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:12012kb
  • [2024-09-09 09:58:45]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MOD = 998244353;

int n;
int lf[3005][3005], up[3005][3005], lu[3005][3005];
char S[3005][3005];
int dp[3005][3005];

int main() {
    scanf("%d", &n);
    for(int i = 0; i < n; i++) scanf("%s", S);

    dp[n][n] = 1;

    for(int i = 0; i < n; i++) {
        int cnt = 1;
        bool ok = true;
        for(int j = 0; j <= n; j++) {
            lf[i][j] = cnt;
            if(S[i][j] == '0') ok = false;
            else if(S[i][j] == '1') cnt = 0;
            cnt += ok;
        }
    }
    for(int i = 0; i < n; i++) {
        int cnt = 1;
        bool ok = true;
        for(int j = 0; j < n; j++) {
            if(S[j][i] == '0') ok = false;
            else if(S[j][i] == '1') cnt = 0;
            cnt += ok;
            up[j][i] = cnt;
            lu[j][i] = ok && i > 0 && S[j][i - 1] == '0' ? lf[j][i - 1] : 0;
        }
    }

    for(int i = n - 1; i >= 0; i--) {
        // dp[i+1][j] -> dp[i][k]: up0[i][j-1]*up0[i][j-2]*...*up0[i][k+1]*up1[i][k]

        for(int j = 0; j <= n; j++)
            dp[i][j] = (dp[i][j] + 1LL * dp[i + 1][j] * lf[i][j]) % MOD;
        
        int cs = 0;
        for(int j = n; j >= 0; j--) {
            dp[i][j] = (dp[i][j] + 1LL * cs * lu[i][j]) % MOD;
            cs = (1LL * cs * up[i][j] + dp[i + 1][j]) % MOD;
        }
    }

    for(int i = 0; i <= n; i++) {
        for(int j = 0; j <= n; j++)
            printf("%d ", dp[i][j]);
            printf("\n");
    }

    int ans = 0;
    for(int i = 0; i <= n; i++) ans = (ans + dp[0][i]) % MOD;
    printf("%d\n", ans);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 12012kb

input:

6 7
1 2
1 3
2 4
3 5
2 6
2 4 1
2 4 2
2 4 3
2 4 4
2 4 5
2 4 6
6 1 2 6 4 3 5

output:

0 0 0 0 0 0 117649 
0 0 0 0 0 0 16807 
0 0 0 0 0 0 2401 
0 0 0 0 0 0 343 
0 0 0 0 0 0 49 
0 0 0 0 0 0 7 
0 0 0 0 0 0 1 
117649

result:

wrong answer 1st words differ - expected: 'No', found: '0'