QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#51617#4633. Coprime Matriceszzhang949#WA 2ms3660kbC++1.5kb2022-10-03 03:19:512022-10-03 03:19:54

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-03 03:19:54]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3660kb
  • [2022-10-03 03:19:51]
  • 提交

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