QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#760897#9551. The EmperorStarrykillerWA 1ms3784kbC++231.5kb2024-11-18 20:01:572024-11-18 20:01:58

Judging History

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

  • [2024-11-18 20:01:58]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3784kb
  • [2024-11-18 20:01:57]
  • 提交

answer

// Homura Akemi a.k.a. Starrykiller (/user/235125)
// I love Madoka Kaname forever!
#include <bits/stdc++.h>

using namespace std;

#ifndef __glibcxx_nonmember_container_access 
#define size(_Cont) _Cont.size()
#endif

constexpr int MAXN=2e3+10;

struct node {
    int t, a, b, c, d;
} op[MAXN]; int n;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n;
    for (int i=1; i<=n; ++i) {
        string s; cin>>s;
        if (s=="POP") {
            op[i].t=1;
            cin>>op[i].a;
            cin>>s;
            cin>>op[i].b;
            cin>>s; 
            cin>>s;
            cin>>op[i].c;
            cin>>s;
            cin>>op[i].d;
        } else {
            op[i].t=2;
            cin>>s;
            cin>>op[i].a; cin>>s; 
            cin>>op[i].b;
        }
    }
    int cur=1; int cnt=0;
    bool flag=false;
    vector<int> stk;
    while (1) {
        int nxt=0;
        cnt++;
        if (op[cur].t==2) {
            if (!size(stk)) break;
            if (flag) {
                cnt=-1; break;
            }
            stk.push_back(op[cur].a);
            nxt=op[cur].b;
        } else {
            if (size(stk) && stk.back()==op[cur].a) {
                stk.pop_back();
                nxt=op[cur].b;
            } else {
                if (flag) {
                    cnt=-1; break;
                }
                stk.push_back(op[cur].c); nxt=op[cur].d;
            }
        }
        flag=nxt<=cur; cur=nxt;
    }
    cout<<cnt<<'\n';
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3572kb

input:

1
HALT; PUSH 1 GOTO 1

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

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: 3500kb

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: 3784kb

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'