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>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const ll MOD = (ll)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;
priority_queue<int, vector<int>, greater<int>> pq;
unordered_map<int, int> um;
char visit[1000001];
char ans[1000001];
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 20; i >= 0; i--) {
um.clear();
int mask = (1 << i) - 1;
for (int j = m; j < n + m; j++)
if (!visit[j]) um[j & mask] = j;
for (int j = 0; j < n; j++)
if (!visit[j] && um.find(j & mask) != um.end()) {
ans[j] = um[j & mask];
visit[um[j & mask]] = 1;
visit[j] = 1;
um.erase(j & mask);
}
}
for (int i = 0; i < n; i++)
printf("%d %d\n", i, ans[i]);
}
Compilation message (stderr)
sob.cpp: In function 'int main()':
sob.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~~
# | 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... |