#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e6 + 5, mod = 20123;
struct Room {
bool f = false;
int x;
};
Room room[10005][105];
int n, m, s, cnt_f[10005];
void Input() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
int a, x;
scanf("%d %d", &a, &x);
if (a == 1) {
room[i][j].f = true;
++cnt_f[i];
}
room[i][j].x = x;
}
}
scanf("%d", &s);
++s;
}
int v[10005][105];
void Init() {
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
int x = room[i][j].x;
int nx = x % cnt_f[i];
if (nx == 0) {
nx = cnt_f[i];
}
int p = j, cnt = 0;
while (true) {
if (room[i][p].f) {
cnt++;
if (cnt == nx) {
break;
}
}
p = p % m + 1;
}
v[i][j] = p;
}
}
}
int sum, p;
void GO() {
p = s;
for (int i = 1; i <= n; ++i) {
sum += room[i][p].x;
p = v[i][p];
}
sum %= mod;
}
int main() {
Input();
Init();
GO();
printf("%d", sum % mod);
return 0;
}
Article
♾️ cpp 代码:
现在已有 39 次阅读,0 条评论,3 人点赞