QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#171237 | #7178. Bishops | ucup-team061# | WA | 0ms | 3408kb | C++20 | 2.1kb | 2023-09-09 16:39:50 | 2023-09-09 16:39:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 5, inf = 0x3fffffff, mod = 998244353;
const long long INF = 0x3fffffffffffffff;
vector<array<int, 3>> ans;
void cal(int x, int y, int n, int m, int op)
{
if(min(n, m)<=0)return;
if(m==n){
for(int i = 1; i <= n; i++){
ans.push_back({i+x, m+y, op});
}
for(int i = 2; i < n; i++){
ans.push_back({i+x, m+y, op});
}
return;
}
if(n!=m && min(n, m)%2==1 && max(n, m)%min(n, m)==0) {
int mn = min(n, m);
if(n==mn){
int p = 1;
while(true){
for(int i = 1; i <= mn; i++)ans.push_back({i+x, p+y, op});
p += mn;
if(p+mn>m){
for(int i = 2; i < mn; i++){
ans.push_back({i+x, p-1+y, op});
}
for(int i = 1; i <= mn; i+=2){
ans.push_back({i+x, m-1+y, op});
ans.push_back({i+x, m+y, op});
}
break;
}
}
}
else{
cal(y, x, m, n, op^1);
}
return;
}
if(n>m){
for(int i = 1; i <= m; i++){
ans.push_back({1+x, i+y, op});
}
cal(x+m, y, n-m, m, op);
}
else cal(y, x, m, n, op^1);
}
int main() {
#ifdef stdjudge
freopen("/home/stdforces/code/contest/in.txt", "r", stdin);
// freopen("/home/stdforces/code/contest/out.txt", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
if(n == 1){
cout << m << '\n';
for(int i = 1; i <= m; i++) cout << "1 " << i << '\n';
return 0;
}
if(m == 1){
cout << n << '\n';
for(int i = 1; i <= n; i++) cout << i << " 1" << '\n';
return 0;
}
cal(0, 0, n, m, 0);
cout << ans.size() << '\n';
for(auto [x, y, op]:ans){
if(op)swap(x, y);
cout << x << ' ' << y << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3408kb
input:
2 5
output:
7 1 1 2 1 1 3 2 3 1 5 1 5 2 5
result:
wrong answer Sum diagonals are not distinct