You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
const int N = 10010, M = 110, mod = 20123;
|
|
|
|
|
|
|
|
|
|
int n, m, k;
|
|
|
|
|
int a[N][M], b[N];
|
|
|
|
|
int num[N][M];
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
scanf("%d%d", &n, &m);
|
|
|
|
|
|
|
|
|
|
int res = 0;
|
|
|
|
|
for (int i = 0; i < n; i++)
|
|
|
|
|
for (int j = 0; j < m; j++) {
|
|
|
|
|
scanf("%d%d", &a[i][j], &num[i][j]);
|
|
|
|
|
b[i] += a[i][j]; // 本层的有楼梯房间数量
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scanf("%d", &k); // 第一层入口
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
|
int t = num[i][k]; // 显示的数字
|
|
|
|
|
res = (res + t) % mod; // 加上后取模,根据题意累加答案
|
|
|
|
|
t %= b[i]; // 数字模每行的房间数量
|
|
|
|
|
if (!t) t = b[i]; // 如果模为零,则走b[i]步
|
|
|
|
|
|
|
|
|
|
// 走t步后,是哪个房间号?
|
|
|
|
|
int sum = 0;
|
|
|
|
|
while (sum < t) { // 走完求得的距离
|
|
|
|
|
sum += a[i][k]; // 当有楼梯时才算一步(题目描述的是第x个有楼梯的房间,所以有楼梯才算一次移动)
|
|
|
|
|
if (sum == t) break; // 走完,当前的k就是停留的房间号
|
|
|
|
|
k++; // 下一个房间
|
|
|
|
|
if (k == m) k = 0; // 不能越界,回到0号房间
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 输出答案
|
|
|
|
|
printf("%d\n", res);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|