This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define ll long long
#define F first
#define S second
#define pb push_back
#define md ((b + e) >> 1)
#define lc (ind << 1)
#define rc (lc | 1)
const ll N = 1e6+ 10;
const ll lg = 15;
const ll oo = 1e9 + 10;
const ll mod = 1e9 + 7;
vector < pair <int, int> > solve(int n, int m){
vector < pair <int, int> > ret = {};
if (n <= 3){
vector <int> A = {}, B = {};
for (int i = 0; i < n; i ++){
A.pb(i);
B.pb(m + i);
}
do {
bool ok = 1;
for (int i = 0; i < n; i ++){
ok &= ((A[i] & B[i]) == A[i]);
}
if (ok){
break;
}
} while (next_permutation(B.begin(), B.end()));
for (int i = 0; i < n; i ++){
ret.pb({A[i], B[i]});
}
return ret;
}
vector < pair <int, int> > o = {}, e = {};
if (n & 1){
if (m & 1){
o = solve((n - 2) / 2 + 1, m / 2);
e = solve((n - 1) / 2 + 1, (m + 2) / 2);
}
else {
o = solve((n - 2) / 2 + 1, (m + 1) / 2);
e = solve((n - 1) / 2 + 1, m / 2);
}
}
else {
if (m & 1){
o = solve((n - 1) / 2 + 1, m / 2);
e = solve((n - 2) / 2 + 1, (m + 1) / 2);
}
else {
o = solve((n - 1) / 2 + 1, (m + 1) / 2);
e = solve((n - 2) / 2 + 1, m / 2);
}
}
for (auto it : o){
ret.pb({it.F * 2 + 1, it.S * 2 + 1});
}
for (auto it : e){
ret.pb({it.F * 2, it.S * 2});
}
return ret;
}
int n, m;
vector < pair <int, int> > ans;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> m;
ans = solve(n, m);
for (auto it : ans){
cout << it.F << ' ' << it.S << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |