結果
問題 | No.1650 Moving Coins |
ユーザー | harurun |
提出日時 | 2021-08-20 22:14:23 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 625 ms / 2,000 ms |
コード長 | 2,242 bytes |
コンパイル時間 | 179 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 100,424 KB |
最終ジャッジ日時 | 2024-04-22 04:53:36 |
合計ジャッジ時間 | 9,870 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
11,136 KB |
testcase_01 | AC | 31 ms
11,008 KB |
testcase_02 | AC | 30 ms
11,008 KB |
testcase_03 | AC | 32 ms
12,160 KB |
testcase_04 | AC | 32 ms
11,876 KB |
testcase_05 | AC | 32 ms
12,032 KB |
testcase_06 | AC | 33 ms
12,160 KB |
testcase_07 | AC | 32 ms
12,032 KB |
testcase_08 | AC | 250 ms
44,376 KB |
testcase_09 | AC | 237 ms
41,728 KB |
testcase_10 | AC | 256 ms
45,560 KB |
testcase_11 | AC | 260 ms
46,252 KB |
testcase_12 | AC | 163 ms
30,912 KB |
testcase_13 | AC | 167 ms
31,696 KB |
testcase_14 | AC | 231 ms
41,728 KB |
testcase_15 | AC | 141 ms
28,092 KB |
testcase_16 | AC | 294 ms
51,156 KB |
testcase_17 | AC | 296 ms
51,876 KB |
testcase_18 | AC | 317 ms
55,224 KB |
testcase_19 | AC | 425 ms
75,208 KB |
testcase_20 | AC | 427 ms
75,212 KB |
testcase_21 | AC | 420 ms
75,060 KB |
testcase_22 | AC | 625 ms
100,168 KB |
testcase_23 | AC | 625 ms
100,424 KB |
testcase_24 | AC | 34 ms
12,508 KB |
testcase_25 | AC | 32 ms
12,112 KB |
testcase_26 | AC | 231 ms
50,124 KB |
ソースコード
class INPUT: def __init__(self): self._l=open(0).read().split() self._length=len(self._l) self._index=0 return def stream(self,k=1,f=int,f2=False): assert(-1<k) if self._length==self._index or self._length-self._index<k: raise Exception("There is no input!") elif f!=str: if k==0: ret=list(map(f,self._l[self._index:])) self._index=self._length return ret if k==1 and not f2: ret=f(self._l[self._index]) self._index+=1 return ret if k==1 and f2: ret=[f(self._l[self._index])] self._index+=1 return ret ret=[] for _ in [0]*k: ret.append(f(self._l[self._index])) self._index+=1 return ret else: if k==0: ret=list(self._l[self._index:]) self._index=self._length return ret if k==1 and not f2: ret=self._l[self._index] self._index+=1 return ret if k==1 and f2: ret=[self._l[self._index]] self._index+=1 return ret ret=[] for _ in [0]*k: ret.append(self._l[self._index]) self._index+=1 return ret pin=INPUT().stream #pin(number[default:1],f[default:int],f2[default:False]) #if number==0 -> return left all #listを変数で受け取るとき、必ずlistをTrueにすること。 def main(): N=pin(1) A=pin(N,int,1) B=pin(N,int,1) ans=0 ansl=[] C=[] # [L*R*] の区間でわける tmp=[[],[]] fl=-1 for i in range(N): ans+=abs(A[i]-B[i]) if A[i]==B[i]: if (tmp[0] or tmp[1]): C.append(tmp) tmp=[[],[]] elif A[i]<B[i]: # R if fl==-1: fl=0 elif fl==0: pass else: fl=0 tmp[1].append(i) else: # L if fl==-1: fl=1 elif fl==1: pass else: fl=1 C.append(tmp) tmp=[[],[]] tmp[0].append(i) if tmp[0] or tmp[1]: C.append(tmp) #print(C) for L,R in C: for i in L: ansl.append((f"{i+1} L\n"*(A[i]-B[i])).rstrip("\n")) for i in R[::-1]: ansl.append((f"{i+1} R\n"*(B[i]-A[i])).rstrip("\n")) print(ans) if ansl: print(*ansl,sep="\n") return main()