QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#51617 | #4633. Coprime Matrices | zzhang949# | WA | 2ms | 3660kb | C++ | 1.5kb | 2022-10-03 03:19:51 | 2022-10-03 03:19:54 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n, m, r, c, w;
const int N = 305;
int ans[N][N];
void debug() {
// print ans
cout << "ans" << endl;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++)
cout << ans[i][j] << " ";
cout << endl;
}
}
int p(int x) {
if ((m % 2 == 1) && (x == m)) return x - 1;
if (x % 2 == 1) return x + 1;
else return x - 1;
}
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> m >> r >> c >> w;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++)
ans[i][j] = (i - 1) * m + j;
}
int wr = (w - 1) / m + 1;
int wc = (w - 1) % m + 1;
if (m % 2 == 0) {
int c2 = p(c);
int wc2 = p(wc);
swap(ans[r][min(c, c2)], ans[wr][min(wc, wc2)]);
swap(ans[r][max(c, c2)], ans[wr][max(wc, wc2)]);
} else { // m % 2 == 1
if (c >= m - 2 && wc >= m - 2) {
swap(ans[r][m - 2], ans[wr][m - 2]);
swap(ans[r][m - 1], ans[wr][m - 1]);
swap(ans[r][m], ans[wr][m]);
} else {
int c2 = p(c);
int wc2 = p(wc);
swap(ans[r][min(c, c2)], ans[wr][max(wc, wc2)]);
swap(ans[r][max(c, c2)], ans[wr][min(wc, wc2)]);
}
}
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++)
if (ans[i][j] == w) {
swap(ans[i][j], ans[r][c]);
}
}
cout << "Yes" << endl;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cout << ans[i][j];
if (j != m) cout << " ";
}
if (i != n) cout << endl;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3564kb
input:
3 3 2 1 3
output:
Yes 4 5 6 3 2 1 7 8 9
result:
ok OK, Accepted.
Test #2:
score: 0
Accepted
time: 1ms
memory: 3660kb
input:
1 1 1 1 1
output:
Yes 1
result:
ok OK, Accepted.
Test #3:
score: -100
Wrong Answer
time: 2ms
memory: 3532kb
input:
8 3 4 2 9
output:
Yes 1 2 3 4 5 6 10 11 12 7 9 8 13 14 15 16 17 18 19 20 21 22 23 24
result:
wrong answer Co-prime Unsatisfied