做了好几遍的题目
但是好像一直没通过(
代码如下:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn = 1e4 + 5;
const ll maxm = 105;
const ll mod = 20123;
ll m, n;
ll d[maxn][maxm];
ll e[maxn][maxm];
ll f[maxm];
int main() {
scanf("%lld%lld", &n, &m);
for (ll i = 0; i < n; ++i) {
f[i] = 0;
for (ll j = 0; j < m; ++j) {
scanf("%lld%lld", &d[i][j], &e[i][j]);
if (d[i][j] == 1) {
++f[i];
}
}
}
ll s, ans = 0;
scanf("%lld", &s);
for (ll i = 0, j; i < n; ++i) {
ans += e[i][s];
ans %= mod;
e[i][s] %= f[i];
if (e[i][s] == 0) {
e[i][s] = f[i];
}
j = s;
if (d[i][s] == 1) {
e[i][s]--;
}
while (e[i][s] > 0) {
if (++j == m) {
j = 0;
}
if (d[i][j] == 1) {
--e[i][s];
}
}
s = j;
}
printf("%lld\n", ans % mod);
return 0;
}