質問編集履歴
2
ACしたのでその結果を記載
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,7 +34,7 @@
|
|
34
34
|
|
35
35
|
|
36
36
|
|
37
|
-
###いただいたコメントを受けて
|
37
|
+
###いただいたコメントを受けて①
|
38
38
|
|
39
39
|
|
40
40
|
|
@@ -97,3 +97,171 @@
|
|
97
97
|
Process finished with exit code 0
|
98
98
|
|
99
99
|
```
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
###いただいた回答を受けて②
|
104
|
+
|
105
|
+
dkato0077さんのcollections.Counterをループの外から呼び出して、すこし修正を加えたらACになりました。([こんな回答](https://yukicoder.me/submissions/239430)になりました)
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
```
|
110
|
+
|
111
|
+
from collections import Counter
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
n = int(input())
|
116
|
+
|
117
|
+
kamo = sorted([int(i) for i in input().split()], reverse=True)
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
isDuplicate = False
|
122
|
+
|
123
|
+
distance_list = []
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
#ここを追記しました
|
128
|
+
|
129
|
+
counter = Counter(kamo)
|
130
|
+
|
131
|
+
if (set([len(Counter(kamo))]) - {1}) == set():
|
132
|
+
|
133
|
+
isDuplicate = True
|
134
|
+
|
135
|
+
#追記ここまで
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
for i in range(len(kamo) - 1):
|
140
|
+
|
141
|
+
#ここをコメントアウトしました
|
142
|
+
|
143
|
+
#if kamo.count(kamo[i]) != 1:
|
144
|
+
|
145
|
+
# isDuplicate = True
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
distance = 0
|
150
|
+
|
151
|
+
distance = kamo[i] - kamo[i + 1]
|
152
|
+
|
153
|
+
distance_list.append(distance)
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
if not isDuplicate and (len(set(distance_list)) == 1):
|
158
|
+
|
159
|
+
print("YES")
|
160
|
+
|
161
|
+
else:
|
162
|
+
|
163
|
+
print("NO")
|
164
|
+
|
165
|
+
```
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
上記で試したLTEになった[このテスト](https://yukicoder.me/problems/no/406/test#system_test1.txt)を再度実行したら結果が以下のようになりました。30倍くらい速い結果となりました。
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
```
|
176
|
+
|
177
|
+
NO
|
178
|
+
|
179
|
+
90886 function calls (90874 primitive calls) in 5.793 seconds
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
Ordered by: standard name
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
ncalls tottime percall cumtime percall filename:lineno(function)
|
188
|
+
|
189
|
+
1 0.032 0.032 5.793 5.793 406.py:1(<module>)
|
190
|
+
|
191
|
+
1 0.019 0.019 0.019 0.019 406.py:4(<listcomp>)
|
192
|
+
|
193
|
+
1 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:989(_handle_fromlist)
|
194
|
+
|
195
|
+
2 0.000 0.000 0.029 0.015 __init__.py:519(__init__)
|
196
|
+
|
197
|
+
2 0.000 0.000 0.029 0.015 __init__.py:588(update)
|
198
|
+
|
199
|
+
7 0.000 0.000 0.000 0.000 _collections_abc.py:392(__subclasshook__)
|
200
|
+
|
201
|
+
7 0.000 0.000 0.000 0.000 _weakrefset.py:16(__init__)
|
202
|
+
|
203
|
+
7 0.000 0.000 0.000 0.000 _weakrefset.py:20(__enter__)
|
204
|
+
|
205
|
+
7 0.000 0.000 0.000 0.000 _weakrefset.py:26(__exit__)
|
206
|
+
|
207
|
+
7 0.000 0.000 0.000 0.000 _weakrefset.py:36(__init__)
|
208
|
+
|
209
|
+
7 0.000 0.000 0.000 0.000 _weakrefset.py:52(_commit_removals)
|
210
|
+
|
211
|
+
9 0.000 0.000 0.000 0.000 _weakrefset.py:58(__iter__)
|
212
|
+
|
213
|
+
10 0.000 0.000 0.000 0.000 _weakrefset.py:70(__contains__)
|
214
|
+
|
215
|
+
7 0.000 0.000 0.000 0.000 _weakrefset.py:81(add)
|
216
|
+
|
217
|
+
2 0.000 0.000 0.000 0.000 abc.py:178(__instancecheck__)
|
218
|
+
|
219
|
+
7/1 0.000 0.000 0.000 0.000 abc.py:194(__subclasscheck__)
|
220
|
+
|
221
|
+
99 0.000 0.000 0.001 0.000 codecs.py:318(decode)
|
222
|
+
|
223
|
+
99 0.000 0.000 0.000 0.000 codecs.py:330(getstate)
|
224
|
+
|
225
|
+
99 0.001 0.000 0.001 0.000 {built-in method _codecs.utf_8_decode}
|
226
|
+
|
227
|
+
2 0.029 0.014 0.029 0.014 {built-in method _collections._count_elements}
|
228
|
+
|
229
|
+
1 0.000 0.000 5.793 5.793 {built-in method builtins.exec}
|
230
|
+
|
231
|
+
7 0.000 0.000 0.000 0.000 {built-in method builtins.getattr}
|
232
|
+
|
233
|
+
2 0.000 0.000 0.000 0.000 {built-in method builtins.hasattr}
|
234
|
+
|
235
|
+
2 5.672 2.836 5.673 2.836 {built-in method builtins.input}
|
236
|
+
|
237
|
+
2 0.000 0.000 0.000 0.000 {built-in method builtins.isinstance}
|
238
|
+
|
239
|
+
8/2 0.000 0.000 0.000 0.000 {built-in method builtins.issubclass}
|
240
|
+
|
241
|
+
7 0.000 0.000 0.000 0.000 {built-in method builtins.len}
|
242
|
+
|
243
|
+
1 0.000 0.000 0.000 0.000 {built-in method builtins.print}
|
244
|
+
|
245
|
+
1 0.031 0.031 0.031 0.031 {built-in method builtins.sorted}
|
246
|
+
|
247
|
+
7 0.000 0.000 0.000 0.000 {method '__subclasses__' of 'type' objects}
|
248
|
+
|
249
|
+
14 0.000 0.000 0.000 0.000 {method 'add' of 'set' objects}
|
250
|
+
|
251
|
+
90442 0.005 0.000 0.005 0.000 {method 'append' of 'list' objects}
|
252
|
+
|
253
|
+
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
|
254
|
+
|
255
|
+
7 0.000 0.000 0.000 0.000 {method 'remove' of 'set' objects}
|
256
|
+
|
257
|
+
1 0.004 0.004 0.004 0.004 {method 'split' of 'str' objects}
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
Process finished with exit code 0
|
266
|
+
|
267
|
+
```
|
1
回答の結果を反映しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -31,3 +31,69 @@
|
|
31
31
|
windows 10
|
32
32
|
|
33
33
|
pycharm
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
###いただいたコメントを受けて
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
LTEになった[このテスト](https://yukicoder.me/problems/no/406/test#system_test1.txt)を試した結果が以下のようになりました。
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
```
|
50
|
+
|
51
|
+
NO
|
52
|
+
|
53
|
+
181191 function calls in 162.567 seconds
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
Ordered by: standard name
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
ncalls tottime percall cumtime percall filename:lineno(function)
|
62
|
+
|
63
|
+
1 0.226 0.226 162.567 162.567 406.py:1(<module>)
|
64
|
+
|
65
|
+
1 0.020 0.020 0.020 0.020 406.py:2(<listcomp>)
|
66
|
+
|
67
|
+
99 0.000 0.000 0.001 0.000 codecs.py:318(decode)
|
68
|
+
|
69
|
+
99 0.000 0.000 0.000 0.000 codecs.py:330(getstate)
|
70
|
+
|
71
|
+
99 0.001 0.000 0.001 0.000 {built-in method _codecs.utf_8_decode}
|
72
|
+
|
73
|
+
1 0.000 0.000 162.567 162.567 {built-in method builtins.exec}
|
74
|
+
|
75
|
+
2 1.433 0.717 1.434 0.717 {built-in method builtins.input}
|
76
|
+
|
77
|
+
1 0.000 0.000 0.000 0.000 {built-in method builtins.len}
|
78
|
+
|
79
|
+
1 0.000 0.000 0.000 0.000 {built-in method builtins.print}
|
80
|
+
|
81
|
+
1 0.042 0.042 0.042 0.042 {built-in method builtins.sorted}
|
82
|
+
|
83
|
+
90442 0.014 0.000 0.014 0.000 {method 'append' of 'list' objects}
|
84
|
+
|
85
|
+
90442 160.824 0.002 160.824 0.002 {method 'count' of 'list' objects}
|
86
|
+
|
87
|
+
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
|
88
|
+
|
89
|
+
1 0.007 0.007 0.007 0.007 {method 'split' of 'str' objects}
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
Process finished with exit code 0
|
98
|
+
|
99
|
+
```
|