QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#789928#9551. The EmperorInkyoTL 1ms7924kbC++201.2kb2024-11-27 22:52:042024-11-27 22:52:08

Judging History

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

  • [2024-11-27 22:52:08]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:7924kb
  • [2024-11-27 22:52:04]
  • 提交

answer

#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3f
#define vi vector <int>
#define vvi vector <vi>
#define endl '\n'
#define ll long long
using namespace std;

constexpr int mod = 998244353, N = 1030, M = 2e5 + 5;

int n;
int A[N], X[N], B[N], Y[N];
ll cnt[N][N], to[N][N];
bool vis[N][N];

void dfs(int p, int e)
{
	if(!p) return;
	if(vis[p][e]){
		printf("-1\n");
		exit(0);
	}
	vis[p][e] = true;
	if(A[p] == e){
		cnt[p][e] = 1;
		to[p][e] = X[p];
	}
	else{
		dfs(Y[p], B[p]);
		dfs(to[Y[p]][B[p]], e);
		cnt[p][e] = (cnt[Y[p]][B[p]] + cnt[to[Y[p]][B[p]]][e] + 1) % mod;
		to[p][e] = to[to[Y[p]][B[p]]][e];
	}
	vis[p][e] = false;
	return;
}

void solve()
{
	scanf("%d", &n);
	char str[20];
	for(int i = 1; i <= n; i ++){
		scanf("%s", str);
		if(string(str) == "HALT;"){
			A[i] = B[i] = 0;
			scanf(" PUSH %d GOTO %d", &B[i], &Y[i]);
		}
		else{
			scanf(" %d GOTO %d; PUSH %d GOTO %d", &A[i], &X[i], &B[i], &Y[i]);
		}
	}
	
	dfs(1, 0);
	printf("%d\n", cnt[1][0]);
}

int main()
{
//	ios::sync_with_stdio(false);
//	cin.tie(0); //cout.tie(0);
	
	int t = 1;
	//cin >> t; 
	while(t --) solve();
	
	return 0;
}

詳細信息

Test #1:

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

input:

1
HALT; PUSH 1 GOTO 1

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 1ms
memory: 7876kb

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

input:

1
POP 1 GOTO 1; PUSH 1 GOTO 1

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

score: -100
Time Limit Exceeded

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:


result: