QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#51616#4633. Coprime Matriceszzhang949#WA 3ms3540kbC++201.5kb2022-10-03 03:12:072022-10-03 03:12:09

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:12:09]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3540kb
  • [2022-10-03 03:12:07]
  • 提交

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;
}

详细

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