-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathd.cpp
More file actions
60 lines (57 loc) · 1.03 KB
/
d.cpp
File metadata and controls
60 lines (57 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <bits/stdc++.h>
#define endl '\n'
#define eat cin
#define moo cout
#define int long long
using namespace std;
int N, K;
vector<pair<int, int>> E;
bool vis[200000];
int32_t main(){
eat.tie(0) -> sync_with_stdio(0);
eat >> N >> K;
if(N % 2 == 0){
moo << -1 << endl;
return 0;
}
vis[0] = vis[K] = 1;
int A = 0, B = K;
auto adv = [&A, &B](){
A++, B++;
if(A == N) A = 0;
if(B == N) B = 0;
};
while(true){
adv();
vis[A] = vis[B] = 1;
E.push_back({0, A});
E.push_back({K, B});
if(A == K || B == 0){
break;
}
}
while(true){
adv();
if(!vis[A] && !vis[B]){
E.push_back({0, A});
E.push_back({K, B});
vis[A] = vis[B] = 1;
}
if(A == 0) break;
}
int fs = 0;
for(; fs < N; fs++){
if(!vis[fs]) break;
}
for(; fs < N && !vis[fs] && !vis[fs+1]; fs += 2){
int x = fs, y = fs+1;
int z = x-K;
if(z < 0) z += N;
E.push_back({y, z});
E.push_back({x, (y+K) % N});
}
moo << E.size()/2 << endl;
for(int i = 0; i < (int)E.size(); i += 2){
moo << E[i].first << ' ' << E[i].second << endl;
}
}