QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#863492 | #9551. The Emperor | wangziji | WA | 69ms | 3712kb | C++26 | 788b | 2025-01-19 17:58:45 | 2025-01-19 17:58:46 |
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;
}
}
f[x]%=mod;
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+mod)%mod;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
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: 69ms
memory: 3456kb
input:
1 POP 1 GOTO 1; PUSH 1 GOTO 1
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3712kb
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:
150994941
result:
ok 1 number(s): "150994941"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
60 POP 1 GOTO 2; PUSH 1 GOTO 1 POP 51 GOTO 3; PUSH 51 GOTO 2 POP 2 GOTO 4; PUSH 2 GOTO 1 POP 52 GOTO 5; PUSH 52 GOTO 4 POP 3 GOTO 6; PUSH 3 GOTO 1 POP 53 GOTO 7; PUSH 53 GOTO 6 POP 4 GOTO 8; PUSH 4 GOTO 1 POP 54 GOTO 9; PUSH 54 GOTO 8 POP 5 GOTO 10; PUSH 5 GOTO 1 POP 55 GOTO 11; PUSH 55 GOTO 10 POP ...
output:
150994941
result:
ok 1 number(s): "150994941"
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 3712kb
input:
119 POP 1 GOTO 2; PUSH 1 GOTO 1 POP 2 GOTO 3; PUSH 2 GOTO 1 POP 3 GOTO 4; PUSH 3 GOTO 1 POP 259 GOTO 5; PUSH 259 GOTO 4 POP 4 GOTO 6; PUSH 4 GOTO 1 POP 5 GOTO 7; PUSH 5 GOTO 1 POP 6 GOTO 8; PUSH 6 GOTO 1 POP 7 GOTO 9; PUSH 7 GOTO 1 POP 8 GOTO 10; PUSH 8 GOTO 1 POP 264 GOTO 11; PUSH 264 GOTO 10 POP 9...
output:
473251504
result:
wrong answer 1st numbers differ - expected: '944833405', found: '473251504'