回答編集履歴
2
修正
test
CHANGED
@@ -1,3 +1,131 @@
|
|
1
|
+
もしかしたらもっと速い実装あるかもしれませんが…
|
2
|
+
|
3
|
+
生成規則をもとに素直に実装していけばよいです。
|
4
|
+
|
5
|
+
以下のように累積的に求めていけばよいです。
|
6
|
+
|
7
|
+
```Python
|
8
|
+
|
9
|
+
n = 3
|
10
|
+
|
11
|
+
ret_list = [[0]]
|
12
|
+
|
13
|
+
for i in range(1,n):
|
14
|
+
|
15
|
+
new_list = []
|
16
|
+
|
17
|
+
for one in ret_list:
|
18
|
+
|
19
|
+
# ひとつ手前の要素の値に-1,+0,+1した要素を追加
|
20
|
+
|
21
|
+
new_list.append( one + [one[i-1]-1])
|
22
|
+
|
23
|
+
new_list.append( one + [one[i-1]])
|
24
|
+
|
25
|
+
new_list.append( one + [one[i-1]+1])
|
26
|
+
|
27
|
+
ret_list = new_list
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
print(*ret_list, sep='\n')
|
32
|
+
|
33
|
+
"""
|
34
|
+
|
35
|
+
n=2
|
36
|
+
|
37
|
+
[0, -1]
|
38
|
+
|
39
|
+
[0, 0]
|
40
|
+
|
41
|
+
[0, 1]
|
42
|
+
|
43
|
+
n=3
|
44
|
+
|
45
|
+
[0, -1, -2]
|
46
|
+
|
47
|
+
[0, -1, -1]
|
48
|
+
|
49
|
+
[0, -1, 0]
|
50
|
+
|
51
|
+
[0, 0, -1]
|
52
|
+
|
53
|
+
[0, 0, 0]
|
54
|
+
|
55
|
+
[0, 0, 1]
|
56
|
+
|
57
|
+
[0, 1, 0]
|
58
|
+
|
59
|
+
[0, 1, 1]
|
60
|
+
|
61
|
+
[0, 1, 2]
|
62
|
+
|
63
|
+
n=4
|
64
|
+
|
65
|
+
[0, -1, -2, -3]
|
66
|
+
|
67
|
+
[0, -1, -2, -2]
|
68
|
+
|
69
|
+
[0, -1, -2, -1]
|
70
|
+
|
71
|
+
[0, -1, -1, -2]
|
72
|
+
|
73
|
+
[0, -1, -1, -1]
|
74
|
+
|
75
|
+
[0, -1, -1, 0]
|
76
|
+
|
77
|
+
[0, -1, 0, -1]
|
78
|
+
|
79
|
+
[0, -1, 0, 0]
|
80
|
+
|
81
|
+
[0, -1, 0, 1]
|
82
|
+
|
83
|
+
[0, 0, -1, -2]
|
84
|
+
|
85
|
+
[0, 0, -1, -1]
|
86
|
+
|
87
|
+
[0, 0, -1, 0]
|
88
|
+
|
89
|
+
[0, 0, 0, -1]
|
90
|
+
|
91
|
+
[0, 0, 0, 0]
|
92
|
+
|
93
|
+
[0, 0, 0, 1]
|
94
|
+
|
95
|
+
[0, 0, 1, 0]
|
96
|
+
|
97
|
+
[0, 0, 1, 1]
|
98
|
+
|
99
|
+
[0, 0, 1, 2]
|
100
|
+
|
101
|
+
[0, 1, 0, -1]
|
102
|
+
|
103
|
+
[0, 1, 0, 0]
|
104
|
+
|
105
|
+
[0, 1, 0, 1]
|
106
|
+
|
107
|
+
[0, 1, 1, 0]
|
108
|
+
|
109
|
+
[0, 1, 1, 1]
|
110
|
+
|
111
|
+
[0, 1, 1, 2]
|
112
|
+
|
113
|
+
[0, 1, 2, 1]
|
114
|
+
|
115
|
+
[0, 1, 2, 2]
|
116
|
+
|
117
|
+
[0, 1, 2, 3]
|
118
|
+
|
119
|
+
"""
|
120
|
+
|
121
|
+
```
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
# 以前の回答
|
126
|
+
|
127
|
+
|
128
|
+
|
1
129
|
`i`の場合の取りえる数値は`-i`~`+i`と表せるので以下でよいかと思います。
|
2
130
|
|
3
131
|
```Python
|
1
修正
test
CHANGED
@@ -23,3 +23,5 @@
|
|
23
23
|
[-4, -3, -2, -1, 0, 1, 2, 3, 4]
|
24
24
|
|
25
25
|
"""
|
26
|
+
|
27
|
+
```
|