QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#754956#9551. The Emperorucup-team045#WA 20ms3604kbC++201.2kb2024-11-16 16:08:312024-11-16 16:08:32

Judging History

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

  • [2024-11-16 16:08:32]
  • 评测
  • 测评结果:WA
  • 用时:20ms
  • 内存:3604kb
  • [2024-11-16 16:08:31]
  • 提交

answer

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

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

int stk[(1 << 23) + 10], top;

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};
        }
    }
    int cur = 1;

    for(int i = 1; ; i++){
        if (i > (1 << 23)){
            cout << -1 << '\n';
            return 0;
        }
        if (top == 0 and p[cur].a == 0){
            cout << i << '\n';
            return 0;
        }
        if (top > 0 and stk[top] == p[cur].a){
            top--;
            cur = p[cur].b;
        }
        else{
            stk[++top] = p[cur].c;
            cur = p[cur].d;
        }
    }

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1
HALT; PUSH 1 GOTO 1

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

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: 20ms
memory: 3604kb

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: 20ms
memory: 3552kb

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'