QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#755075#9551. The Emperorucup-team4508#WA 2ms10064kbC++141.3kb2024-11-16 16:24:292024-11-16 16:24:30

Judging History

你现在查看的是最新测评结果

  • [2024-11-16 16:24:30]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:10064kb
  • [2024-11-16 16:24:29]
  • 提交

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];
bool flag1[1505][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]++;
		  }
		for(i=1;i<=n;i++)
		  if(flag[i]==false){
		  	while(a[to[i]]!=x[i] && flag[to[i]]==true){
		  		if(flag1[i][to[i]]==true){
		  			stat[i]=true;break;
				}
		  		flag1[i][to[i]]=true,dp[i]+=dp[to[i]],to[i]=b[num[to[i]]],dp[i]%=mod;
			}
		  }
	}
	LL now=1,ans=0;
	if(a[1]==0){
		printf("1");
		return 0;
	}
	if(flag[1]==false){
		printf("-1");
		return 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: 1ms
memory: 9920kb

input:

1
HALT; PUSH 1 GOTO 1

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 2ms
memory: 10064kb

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: 9984kb

input:

1
POP 1 GOTO 1; PUSH 1 GOTO 1

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 7964kb

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: -100
Wrong Answer
time: 0ms
memory: 10004kb

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:

1149239294

result:

wrong answer 1st numbers differ - expected: '150994941', found: '1149239294'