QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#769233 | #9551. The Emperor | Suhy# | WA | 1ms | 5936kb | C++17 | 2.4kb | 2024-11-21 16:39:54 | 2024-11-21 16:39:58 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
int read()
{
int x = 0, flag = 0;
char c = 0;
while(c < '0' || '9' < c)
c = getchar(), flag |= c == '-';
while('0' <= c && c <= '9')
x = x * 10 + c - '0', c = getchar();
return flag ? -x : x;
}
const int maxn=2000;
struct node{
int op,x,v1,y,v2;
};
bool T[maxn][maxn];
string str;
node G[maxn];
int n;
pair<int,int> f[maxn][maxn];
bool flag=false;
pair<int,int> dfs(int top,int m){
// cout<<top<<" "<<m<<endl;
if(T[top][m]||flag){
flag=true;
return {-1,-1};
}
if(f[top][m].first) return f[top][m];
T[top][m]=1;
if(G[m].op==1){
// cout<<"!"<<endl;
if(G[m].x==top){
return f[top][m]={1,m};
}else{
int ret=m;
pair<int,int>tmp=dfs(G[m].y,G[m].v2);
(f[top][ret].first=1+tmp.first)%=mod;
tmp=dfs(top,G[tmp.second].v1);
(f[top][ret].first+=tmp.first)%=mod;
f[top][ret].second=tmp.second;
// while(G[m].x!=top){
// pair<int,int>tmp=dfs(G[m].y,G[m].v2);
// (f[top][ret].first+=tmp.first);
// m=G[tmp.second].v2;
// }
return f[top][ret];
// return (f[top][m]=1+dfs(G[m].y,G[m].v2))%=mod;
}
}else{
// cout<<"?";
if(top==0) return f[top][m]={1,m};
else{
int ret=m;
pair<int,int>tmp=dfs(G[m].x,G[m].v1);
(f[top][ret].first=1+tmp.first)%=mod;
tmp=dfs(top,G[tmp.second].v1);
(f[top][ret].first+=tmp.first)%=mod;
f[top][ret].second=tmp.second;
return f[top][ret];
// return (f[top][m]=1+dfs(G[m].x,G[m].v1))%=mod;
}
}
T[top][m]=0;
// cout<<"OUT"<<top<<" "<<m<<endl;
}
signed main()
{
n=read();
for(int i=1;i<=n;i++){
cin>>str;
if(str=="POP"){
int a=read();
int b=read();
int c=read();
int d=read();
G[i]=((node){1,a,b,c,d});
}else{
int a=read();
int b=read();
// cout<<a<<" "<<b<<endl;
G[i]=((node){2,a,b});
}
}
f[0][1]=dfs(0,1);
if(flag){
printf("-1\n");
}else{
printf("%d",f[0][1].first%mod);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5876kb
input:
1 HALT; PUSH 1 GOTO 1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5892kb
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: 5808kb
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: 5936kb
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'