QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#51616 | #4633. Coprime Matrices | zzhang949# | WA | 3ms | 3540kb | C++20 | 1.5kb | 2022-10-03 03:12:07 | 2022-10-03 03:12:09 |
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] << " ";
}
cout << endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 3540kb
input:
3 3 2 1 3
output:
Yes 4 5 6 3 2 1 7 8 9
result:
wrong output format Expected EOLN