QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#754952 | #9551. The Emperor | ucup-team4508# | WA | 1ms | 5960kb | C++14 | 1.0kb | 2024-11-16 16:08:14 | 2024-11-16 16:08:14 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL n,i,j,k,m;
LL stat[1000005],x[100005],y[100005];
LL a[100005],b[100005],to[100005];
LL num[1505],dp[1505];
bool flag[1505];
bool vis[1505];
string s1,s2,s3,s4,s;
const LL mod=998244353;
int main(){
scanf("%lld",&n);
for(i=1;i<=n;i++){
s="";
cin>>s;
if(s=="POP"){
scanf(" %lld GOTO %lld; PUSH %lld GOTO %lld",&a[i],&b[i],&x[i],&y[i]);
}
else{
scanf(" PUSH %lld GOTO %lld",&x[i],&y[i]);
}
}
for(i=1;i<=n;i++){
to[i]=y[i],dp[i]=1;
}
for(j=1;j<=n;j++){
for(i=1;i<=n;i++)
if(flag[i]==false && a[to[i]]==x[i]){
flag[i]=true,num[i]=to[i];dp[i]++;break;
}
for(i=1;i<=n;i++)
if(flag[to[i]]==true){
dp[i]+=dp[to[i]];to[i]=b[num[to[i]]];dp[i]%=mod;
}
}
LL now=1,ans=0;
while(1){
if(vis[now]==true){
printf("-1");
return 0;
}
if(a[now]>0) vis[now]=true,ans+=dp[now],now=b[num[now]];
else{
printf("%lld",ans+1);
return 0;
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5960kb
input:
1 HALT; PUSH 1 GOTO 1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5912kb
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: 1ms
memory: 5912kb
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: 1ms
memory: 5956kb
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:
2
result:
wrong answer 1st numbers differ - expected: '150994941', found: '2'