QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#771989 | #9551. The Emperor | Chen_jr | WA | 0ms | 3896kb | C++14 | 1.3kb | 2024-11-22 16:31:56 | 2024-11-22 16:31:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 2047;
const int mod = 98244353;
struct node{
int top, go1, push, go2;
}d[maxn];
int n;
char s[maxn], c;
bool vis[maxn];
int rem[maxn][2];
int sta[maxn]; bool in[maxn];
void dfs(int x){
if(rem[x][0] == -1){
printf("-1\n");
exit(0);
}
int tmp = d[x].go2, res = 1;
rem[x][0] = -1;
while(d[tmp].top != d[x].push){
if(!rem[tmp][0])dfs(tmp);
if(rem[tmp][0] == -1){
printf("-1\n");
exit(0);
}
res = (res + rem[tmp][1]) % mod;
tmp = d[rem[tmp][0]].go1;
}
rem[x][0] = tmp;
rem[x][1] = res + 1;
// printf("rem:::: %d %d %d\n",x, rem[x][0], rem[x][1]);
return;
}
int solve(){
int now = 1, ans = 1;
while(d[now].go1 != -1){
if(vis[now])return -1;
vis[now] = true;
if(!rem[now][0])dfs(now);
ans = (ans + rem[now][1]) % mod;
now = d[rem[now][0]].go1;
// printf("%d %d\n",now, ans);
}
return ans;
}
int main(){
scanf("%d",&n);
for(int i = 1; i <= n; ++i){
scanf(" %c",&c);
if(c == 'P'){
scanf("OP %d GOTO %d; PUSH %d GOTO %d",&d[i].top, &d[i].go1, &d[i].push, &d[i].go2);
}else{
scanf("ALT; PUSH %d GOTO %d",&d[i].push, &d[i].go2);
d[i].go1 = -1; d[i].top = -1;
}
}
printf("%d\n",solve());
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3804kb
input:
1 HALT; PUSH 1 GOTO 1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3896kb
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: 3828kb
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: 3832kb
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:
84352234
result:
wrong answer 1st numbers differ - expected: '150994941', found: '84352234'