QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#758036#9551. The EmperorLogingWA 1ms6324kbC++142.4kb2024-11-17 15:15:522024-11-17 15:15:53

Judging History

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

  • [2024-11-17 15:15:53]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6324kb
  • [2024-11-17 15:15:52]
  • 提交

answer

#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<iostream>
#include<bitset>
#define P 998244353
using namespace std;
#define M 1055
string S;
struct node{
    int to,val;
};
node Push[M],Pop[M];
bool mark[M];
vector<string>A;
void Split(string S){
    string tmp="";
    A.clear();
    for(int i=0;i<(int)S.length();i++){
        if(S[i]==' '){if(tmp!=""){A.push_back(tmp);tmp="";}}
        else tmp+=S[i];
    }
    if(tmp!="")A.push_back(tmp);
}
int Change(string x){
    int res=0;
    for(int i=0;i<(int)x.length();i++){
        if(x[i]!=';')res=res*10+x[i]-'0';
    }
    return res;
}
struct pnode{
    int st,ed;
};
int dis[M][M];//dis to To[i][j]
int n;
int vis[M][M];
int To[M][M];
bool dfs(int now,int col){
	if(vis[now][col]==1)return false;
	if(vis[now][col]==2)return true;
	if(vis[now][col]==3)return true;
	vis[now][col]=1;
	if(!mark[now]&&col==Pop[now].val){
		To[now][col]=Pop[now].to;
		dis[now][col]=1;
		return true;
	}else if(mark[now]&&col==0){
		To[now][col]=0;
		dis[now][col]=1;
		return true;
	}else{
		if(now==0){vis[now][col]=3;return false;}
		if(dfs(Push[now].to,Push[now].val)&&dfs(To[Push[now].to][Push[now].val],col)){
			To[now][col]=To[To[Push[now].to][Push[now].val]][col];
			dis[now][col]=(1+dis[To[Push[now].to][Push[now].val]][col]+dis[Push[now].to][Push[now].val])%P;
			vis[now][col]=2;
			return true;
		}
	}
	vis[now][col]=3;
	return false;
}
int main(){
//    freopen("D.in","r",stdin);
    scanf("%d",&n);
//    printf("n=%d\n",n);
    getchar();
    for(int i=1;i<=n;i++){
        getline(cin,S);
//        cout<<"S="<<S<<endl;
        Split(S);
//        printf("i=%d\n",i);
//        for(int i=0;i<(int)A.size();i++)cout<<A[i]<<" ";
//        cout<<endl;
        if(S[0]=='P'){
            node nxt;
            nxt.val=Change(A[1]);
            nxt.to=Change(A[3]);
            Pop[i]=nxt;
//            printf("(pop)%d %d\n",nxt.val,nxt.to);

            nxt.val=Change(A[5]);
            nxt.to=Change(A[7]);
            Push[i]=nxt;
            
//            printf("(push)%d %d\n",nxt.val,nxt.to);
        }else{
            mark[i]=true;
            node nxt;
            nxt.val=Change(A[2]);
            nxt.to=Change(A[4]);
            Push[i]=nxt;
        }
    }
    if(dfs(1,0)){
    	printf("%d\n",dis[1][0]);
	}else puts("-1");
    
    

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5848kb

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: 1ms
memory: 5780kb

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

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: 1ms
memory: 5800kb

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:

-1

result:

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