#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
using namespace std;
const int N = 1000100;
int kol = 0, n, m, nm[N], ans[N], val;
bool mrk[N];
bool cmp(int x, int y){
return (val & x) < (val & y);
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("in.txt","r",stdin);
cin >> n >> m;
kol = 0;
while ((1 << kol) < n) kol++;
for (int it = 0; it < n; it++)
nm[it] = m + it;
int mem = n, id = 0;
val = (1 << kol) - 1;
sort(nm, nm + n, cmp);
while (id < n) {
for (int i = (nm[id] & val); ; i = ((i - 1) & (nm[id] & val))){
if (mrk[i] || i >= n) continue;
mrk[i] = 1;
ans[i] = nm[id];
id++;
break;
}
}
for (int i = n - 1; i >= 0; i--) {
assert((ans[i] & i) == i);
cout << i << " " << ans[i] << '\n';
}
return 0;
}
Compilation message
sob.cpp: In function 'int main()':
sob.cpp:27:9: warning: unused variable 'mem' [-Wunused-variable]
int mem = n, id = 0;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
64 ms |
6264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
65 ms |
6264 KB |
Output is correct |
7 |
Correct |
60 ms |
3192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
64 ms |
6264 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
65 ms |
6264 KB |
Output is correct |
11 |
Correct |
60 ms |
3192 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
37 ms |
1536 KB |
Output is correct |
20 |
Correct |
166 ms |
4856 KB |
Output is correct |
21 |
Correct |
7 ms |
512 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
600 ms |
6776 KB |
Output is correct |
24 |
Correct |
149 ms |
11768 KB |
Output is correct |
25 |
Correct |
141 ms |
11512 KB |
Output is correct |