QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#863491 | #9551. The Emperor | wangziji | WA | 68ms | 3712kb | C++26 | 765b | 2025-01-19 17:58:00 | 2025-01-19 17:58:13 |
Judging History
answer
#include <bits/stdc++.h>
#define mod 998244353
#define int long long
using namespace std;
int A[10005],B[10005],C[10005],D[10005],f[10005],g[10005],n,cnt;
pair<int,int> dfs(int x)
{
if(g[x]) return {f[x],g[x]};
int rtn=1;
int nw=D[x];
while(1)
{
if(++cnt>=3e7)
{
cout << -1;
exit(0);
}
if(A[nw]==C[x])
{
nw=B[nw],++rtn;
break;
}
else
{
pair<int,int> nx=dfs(nw);
rtn+=nx.first,nw=nx.second;
}
}
return {f[x]=rtn,g[x]=nw};
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for(int i=1;i<=n;i++)
{
string s;
cin >> s;
if(s!="HALT;")
cin >> A[i] >> s >> B[i] >> s;
cin >> s >> C[i] >> s >> D[i];
}
D[0]=1;
cout << dfs(0).first-1;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3712kb
input:
1 HALT; PUSH 1 GOTO 1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3712kb
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: 68ms
memory: 3584kb
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: 3584kb
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:
2147483647
result:
wrong answer 1st numbers differ - expected: '150994941', found: '2147483647'