求救!!3WA+7TLE
查看原帖
求救!!3WA+7TLE
904844
yuanzilin楼主2024/10/21 21:41
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int MOD = 20123;
int st[10005][105]; // 存储每层房间的楼梯信息
int in[10005][105]; // 存储指示牌上的数字
int n, m;


signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> st[i][j] >> in[i][j];
		}
	}
	int start;
	cin >> start;
	int tot = 0;
	// 从底层到顶层
	for (int l = 1; l <= n; l++) {
		int x = in[l][start]; // 当前房间的指示牌数字
		tot = (tot + x) % MOD;// 累加当前指示牌数字
		if (st[l][start]) {	// 如果当前房间有楼梯,直接上去
			// 如果有楼梯直接返回同样房间
			continue;
		}
		// 计算从当前房间开始逆时针选择第x个有楼梯的房间
		int count = 0;
		for (int set = 0; count < x; set++) {
			int next = (start - set + m) % m; // 逆时针移动
			if (st[l][next]) {
				count++;
			}
			if (count == x) {
				start = next; // 更新到下层的目标房间
				break;
			}
		}
	}
	cout << tot;
	return 0;
}

评测记录

帮助必关

2024/10/21 21:41
加载中...