質問編集履歴

2

修正したコードを(修正)として追記

2019/07/28 11:55

投稿

H.K.
H.K.

スコア6

test CHANGED
File without changes
test CHANGED
@@ -110,6 +110,98 @@
110
110
 
111
111
 
112
112
 
113
+ (修正)
114
+
115
+ ```Python
116
+
117
+ import copy,sys
118
+
119
+ input=sys.stdin.readline
120
+
121
+ N,K=[int(x) for x in input().split()]
122
+
123
+ S=list(input())
124
+
125
+ ans=[]
126
+
127
+ cost=0
128
+
129
+ remaining=copy.deepcopy(S)
130
+
131
+ remaining.sort()
132
+
133
+
134
+
135
+ def check(fix,w,S):
136
+
137
+ res=0
138
+
139
+ s=copy.deepcopy(S)
140
+
141
+
142
+
143
+ for i in range(len(fix)):
144
+
145
+ if fix[i]!=s[i]:
146
+
147
+ res+=1
148
+
149
+ s=s[len(fix):]
150
+
151
+ seq=copy.deepcopy(w)
152
+
153
+ for wd in seq:
154
+
155
+ if wd in s:
156
+
157
+ s.remove(wd)
158
+
159
+ else:
160
+
161
+ res+=1
162
+
163
+ return res
164
+
165
+
166
+
167
+ for i in range(N):
168
+
169
+ k=''
170
+
171
+ seq=copy.deepcopy(remaining)
172
+
173
+ for ii,s in enumerate(seq):
174
+
175
+ t_sortedS=copy.deepcopy(remaining)
176
+
177
+ t_sortedS.remove(s)
178
+
179
+ c=check(ans+[s],t_sortedS,S)
180
+
181
+ if c>K:
182
+
183
+ continue
184
+
185
+ elif c<=K:
186
+
187
+ ans.append(s)
188
+
189
+ k=s
190
+
191
+ break
192
+
193
+
194
+
195
+ remaining.remove(k)
196
+
197
+
198
+
199
+ print(''.join(ans))
200
+
201
+ ```
202
+
203
+
204
+
113
205
  ### 試したこと
114
206
 
115
207
 

1

質問内のソースコードをMarkdownに修正

2019/07/28 11:55

投稿

H.K.
H.K.

スコア6

test CHANGED
File without changes
test CHANGED
@@ -29,6 +29,8 @@
29
29
  言語:Python3 (3.4.3)
30
30
 
31
31
 
32
+
33
+ ```Python
32
34
 
33
35
  import copy,sys
34
36
 
@@ -104,6 +106,8 @@
104
106
 
105
107
  print(''.join(ans))
106
108
 
109
+ ```
110
+
107
111
 
108
112
 
109
113
  ### 試したこと