AC
2025-10-28 21:07:47
发布于:北京
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, x, y;
long long k;
cin >> n >> m >> x >> y >> k;
vector<vector<long long>> a(n, vector<long long>(m));
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> a[i][j];
auto calc = [&](bool east) -> long long {
long long total = 0;
int curx = x - 1, cury = y - 1;
vector<long long> vals;
if (east) {
for (int j = 0; j < m; j++)
vals.push_back(a[curx][j]);
} else {
for (int i = 0; i < n; i++)
vals.push_back(a[i][cury]);
}
long long cycle_sum = accumulate(vals.begin(), vals.end(), 0LL);
long long ans = 0, sum = 0;
int pos = (east ? cury : curx);
int len = (east ? m : n);
if (cycle_sum > 0) {
long long full_cycles = max(0LL, (k - 1) / cycle_sum);
sum += full_cycles * cycle_sum;
ans += full_cycles * len;
}
while (sum < k) {
pos = (pos + 1) % len;
sum += vals[pos];
ans++;
}
return ans;
};
cout << calc(true) << " " << calc(false) << "\n";
return 0;
}

这里空空如也







有帮助,赞一个