結果
問題 | No.2947 Sing a Song |
ユーザー | lif4635 |
提出日時 | 2024-10-25 21:53:28 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 100 ms / 2,000 ms |
コード長 | 2,953 bytes |
コンパイル時間 | 294 ms |
コンパイル使用メモリ | 82,224 KB |
実行使用メモリ | 79,372 KB |
最終ジャッジ日時 | 2024-10-25 21:53:43 |
合計ジャッジ時間 | 4,566 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
53,548 KB |
testcase_01 | AC | 37 ms
54,232 KB |
testcase_02 | AC | 38 ms
53,920 KB |
testcase_03 | AC | 45 ms
61,812 KB |
testcase_04 | AC | 48 ms
67,572 KB |
testcase_05 | AC | 38 ms
53,960 KB |
testcase_06 | AC | 45 ms
63,676 KB |
testcase_07 | AC | 47 ms
64,464 KB |
testcase_08 | AC | 49 ms
67,388 KB |
testcase_09 | AC | 47 ms
62,448 KB |
testcase_10 | AC | 46 ms
62,160 KB |
testcase_11 | AC | 39 ms
55,880 KB |
testcase_12 | AC | 50 ms
70,920 KB |
testcase_13 | AC | 53 ms
73,000 KB |
testcase_14 | AC | 39 ms
54,296 KB |
testcase_15 | AC | 50 ms
66,304 KB |
testcase_16 | AC | 47 ms
63,548 KB |
testcase_17 | AC | 54 ms
68,256 KB |
testcase_18 | AC | 65 ms
73,508 KB |
testcase_19 | AC | 79 ms
76,892 KB |
testcase_20 | AC | 71 ms
76,664 KB |
testcase_21 | AC | 60 ms
69,656 KB |
testcase_22 | AC | 67 ms
74,208 KB |
testcase_23 | AC | 77 ms
76,444 KB |
testcase_24 | AC | 78 ms
76,528 KB |
testcase_25 | AC | 85 ms
76,888 KB |
testcase_26 | AC | 81 ms
76,324 KB |
testcase_27 | AC | 100 ms
79,372 KB |
ソースコード
#int-input def II() -> int : return int(input()) def MI() -> int : return map(int, input().split()) class fenwick_tree(): n=1 data=[0 for i in range(n)] def __init__(self,N): self.n=N self.data=[0 for i in range(N)] def add(self,p,x): assert 0<=p<self.n,"0<=p<n,p={0},n={1}".format(p,self.n) p+=1 while(p<=self.n): self.data[p-1]+=x p+=p& -p def sum(self,l,r): assert (0<=l and l<=r and r<=self.n),"0<=l<=r<=n,l={0},r={1},n={2}".format(l,r,self.n) return self.sum0(r)-self.sum0(l) def sum0(self,r): s=0 while(r>0): s+=self.data[r-1] r-=r&-r return s class dsu(): n=1 parent_or_size=[-1 for i in range(n)] def __init__(self,N): self.n=N self.parent_or_size=[-1 for i in range(N)] def merge(self,a,b): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) assert 0<=b<self.n, "0<=b<n,b={0},n={1}".format(b,self.n) x=self.leader(a) y=self.leader(b) if x==y: return x if (-self.parent_or_size[x]<-self.parent_or_size[y]): x,y=y,x self.parent_or_size[x]+=self.parent_or_size[y] self.parent_or_size[y]=x return x def same(self,a,b): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) assert 0<=b<self.n, "0<=b<n,b={0},n={1}".format(b,self.n) return self.leader(a)==self.leader(b) def leader(self,a): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) if (self.parent_or_size[a]<0): return a self.parent_or_size[a]=self.leader(self.parent_or_size[a]) return self.parent_or_size[a] def size(self,a): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) return -self.parent_or_size[self.leader(a)] def groups(self): leader_buf=[0 for i in range(self.n)] group_size=[0 for i in range(self.n)] for i in range(self.n): leader_buf[i]=self.leader(i) group_size[leader_buf[i]]+=1 result=[[] for i in range(self.n)] for i in range(self.n): result[leader_buf[i]].append(i) result2=[] for i in range(self.n): if len(result[i])>0: result2.append(result[i]) return result2 n = II() s,t = input().split() a = list(MI()) ls,lt = len(s),len(t) def xgcd(a:int, b:int): #Euclid互除法 """ans = a*x0 + b*y0""" x0, y0, x1, y1 = 1, 0, 0, 1 while b != 0: q, a, b = a // b, b, a % b x0, x1 = x1, x0 - q * x1 y0, y1 = y1, y0 - q * y1 return a, x0, y0 g,x0,y0 = xgcd(ls,lt) ls //= g lt //= g for ai in a: ans = [] bi = ai//g #bi = ls*x0 + lt*y0 y1 = y0*bi x1 = x0*bi ct = y1%ls ans.extend([t]*ct) cs = (bi - ct*lt)//ls ans.extend([s]*cs) print(*ans)