QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#755528#9551. The Emperorucup-team045#WA 0ms3852kbC++202.1kb2024-11-16 17:35:122024-11-16 17:35:13

Judging History

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

  • [2024-11-16 17:35:13]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3852kb
  • [2024-11-16 17:35:12]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
using LL = long long;

struct Node{
    int a, b, c, d;
};

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int n;
    cin >> n;
    vector<Node> p(n + 1);
    for(int i = 1; i <= n; i++){
        string s;
        cin >> s;
        if (s[0] == 'H'){
            string _; int v1, v2;
            cin >> _ >> v1 >> _ >> v2;
            p[i] = {0, 0, v1, v2}; 
        }
        else{
            string _; int v1, v2, v3, v4;
            cin >> v1 >> _ >> v2 >> _ >> _ >> v3 >> _ >> v4;
            p[i] = {v1, v2, v3, v4};
        }
    }
    vector<int> len1(n + 1, -1), len2(n + 1, -1), out(n + 1);
    for(int i = 1; i <= n; i++) out[i] = i;
    for(int i = 1; i <= n; i++){
        auto [a, b, c, d] = p[i];
        if (a == 0){
            len1[i] = 0;
        }
        if (p[d].a == c){
            len2[i] = 2;
            out[i] = p[d].b;
        }
    }

    const int mod = 998244353;
    for(int _ = 0; _ < n; _++){
        for(int i = 1; i <= n; i++){
            if (len2[i] != -1 and len2[out[i]] != -1){
                len2[i] += len2[out[i]];
                if (len2[i] >= mod) len2[i] -= mod;
                out[i] = out[out[i]];
            }
            if (len1[i] == -1 and len1[out[i]] != -1){
                len1[i] = len2[i] + len1[out[i]];
                if (len1[i] >= mod) len1[i] -= mod;
            }
        }
        for(int i = 1; i <= n; i++){
            auto [a, b, c, d] = p[i];
            if (len2[i] == -1){
                if (len2[d] != -1 and p[out[d]].a == c){
                    len2[i] = len2[d] + 2;
                    if (len2[i] >= mod) len2[i] -= mod;
                    out[i] = p[out[d]].b;
                    if (p[out[i]].a == 0 and len1[i] == -1){
                        len1[i] = len2[i];
                    }
                }
            }
        }
    }
    if (len1[1] == -1) cout << -1 << '\n';
    else cout << (len1[1] + 1) % mod << '\n';

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3620kb

input:

1
HALT; PUSH 1 GOTO 1

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3852kb

input:

5
POP 1 GOTO 2; PUSH 1 GOTO 2
HALT; PUSH 1 GOTO 3
POP 1 GOTO 4; PUSH 2 GOTO 4
POP 1 GOTO 2; PUSH 2 GOTO 4
HALT; PUSH 99 GOTO 4

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3552kb

input:

1
POP 1 GOTO 1; PUSH 1 GOTO 1

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3556kb

input:

61
POP 62 GOTO 61; PUSH 30 GOTO 60
POP 1 GOTO 3; PUSH 62 GOTO 61
POP 2 GOTO 61; PUSH 62 GOTO 61
POP 4 GOTO 7; PUSH 2 GOTO 61
POP 62 GOTO 61; PUSH 3 GOTO 4
POP 62 GOTO 61; PUSH 3 GOTO 5
POP 5 GOTO 10; PUSH 3 GOTO 6
POP 62 GOTO 61; PUSH 4 GOTO 7
POP 62 GOTO 61; PUSH 4 GOTO 8
POP 6 GOTO 12; PUSH 4 GOTO...

output:

-1

result:

wrong answer 1st numbers differ - expected: '150994941', found: '-1'