-
Notifications
You must be signed in to change notification settings - Fork 0
/
수열 만들기.cc
75 lines (33 loc) · 1014 Bytes
/
수열 만들기.cc
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <vector>
using namespace std;
int main(){
int check[1001][1001]; vector<int> stack;
int N;
cin >> N;
cout << N * N + 1 << '\n';
stack.push_back(0);
while(!stack.empty()){
int tmp = stack.back();
stack.pop_back();
cout << tmp + 1 << ' ';
if(!check[tmp][0]){
stack.push_back(tmp);
check[tmp][0]=1;
}
else{
for(int i=1; i < N; i++){
if(!check[tmp][i]){
int x = tmp;
stack.push_back(x);
check[x][i]=1;
for(x = (x + (N - i)) % N; x != tmp; x = (x + (N - i)) % N){
stack.push_back(x);
check[x][i]=1;
}
break;
}
}
}
}
}