結果
問題 | No.1410 A lot of Bit Operations |
ユーザー | convexineq |
提出日時 | 2021-02-27 08:11:57 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,252 bytes |
コンパイル時間 | 348 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 77,312 KB |
最終ジャッジ日時 | 2024-10-02 17:05:30 |
合計ジャッジ時間 | 6,132 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 75 ms
71,680 KB |
testcase_01 | AC | 116 ms
76,668 KB |
testcase_02 | AC | 114 ms
76,572 KB |
testcase_03 | AC | 116 ms
76,424 KB |
testcase_04 | AC | 120 ms
76,380 KB |
testcase_05 | AC | 68 ms
71,060 KB |
testcase_06 | AC | 106 ms
76,184 KB |
testcase_07 | AC | 89 ms
76,324 KB |
testcase_08 | AC | 113 ms
76,416 KB |
testcase_09 | AC | 116 ms
76,800 KB |
testcase_10 | AC | 117 ms
76,964 KB |
testcase_11 | AC | 98 ms
76,052 KB |
testcase_12 | AC | 94 ms
76,056 KB |
testcase_13 | AC | 113 ms
76,432 KB |
testcase_14 | AC | 107 ms
76,388 KB |
testcase_15 | AC | 111 ms
76,672 KB |
testcase_16 | AC | 117 ms
77,312 KB |
testcase_17 | AC | 95 ms
76,124 KB |
testcase_18 | AC | 117 ms
76,644 KB |
testcase_19 | AC | 112 ms
76,496 KB |
testcase_20 | AC | 116 ms
76,928 KB |
testcase_21 | AC | 108 ms
76,552 KB |
testcase_22 | AC | 111 ms
76,784 KB |
testcase_23 | AC | 111 ms
76,544 KB |
testcase_24 | AC | 112 ms
76,328 KB |
testcase_25 | AC | 118 ms
77,028 KB |
testcase_26 | AC | 116 ms
77,048 KB |
testcase_27 | AC | 118 ms
77,008 KB |
testcase_28 | AC | 112 ms
76,800 KB |
testcase_29 | AC | 116 ms
76,840 KB |
testcase_30 | AC | 100 ms
76,424 KB |
testcase_31 | AC | 109 ms
76,360 KB |
testcase_32 | AC | 122 ms
77,164 KB |
testcase_33 | AC | 119 ms
77,012 KB |
testcase_34 | AC | 114 ms
77,132 KB |
testcase_35 | AC | 118 ms
76,808 KB |
testcase_36 | AC | 115 ms
76,832 KB |
testcase_37 | AC | 90 ms
76,544 KB |
testcase_38 | AC | 39 ms
53,072 KB |
testcase_39 | AC | 66 ms
70,528 KB |
testcase_40 | AC | 65 ms
70,912 KB |
testcase_41 | AC | 41 ms
52,760 KB |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | AC | 40 ms
53,376 KB |
testcase_45 | AC | 118 ms
76,752 KB |
ソースコード
def extgcd(x,y): if y==0: return 1,0 r0,r1,s0,s1 = x,y,1,0 while r1 != 0: r0,r1, s0,s1 = r1,r0%r1, s1,s0-r0//r1*s1 return s0,(r0-s0*x)//y def modinv(a,MOD): x,y = extgcd(a,MOD) return x%MOD def divmod_poly(f,g,MOD): #MODは素数とする assert g != [] and g != [0] ainv = modinv(g[-1],MOD) df,dg = len(f),len(g) if df < dg: return [0], f[:] gg = [gi*ainv%MOD for gi in g] r = f[:] q = [0]*(df-dg+1) for i in range(df-dg,-1,-1): q[i] = c = r[-1] if c: for j in range(dg-1,-1,-1): r[j+i] -= c*gg[j] r[j+i] %= MOD r.pop() for i in range(df-dg+1): # g を monic にする q[i] = q[i]*ainv%MOD while r and r[-1]==0: r.pop() if not r: r = [0] return q,r def mul_poly(f,g,MOD): df,dg = len(f),len(g) res = [0]*(df+dg-1) for i in range(df): for j in range(dg): res[i+j] += f[i]*g[j] res[i+j] %= MOD return res def sub_poly(f,g,MOD): df,dg = len(f),len(g) m = max(df,dg) res = f[:]+[0]*(m-df) for i in range(m): if i < dg: res[i] -= g[i] if res[i] < 0: res[i] += MOD return res def bm(x,MOD): assert len(x)%2==0 L = len(x)//2 x.reverse() while x and x[-1]==0: x.pop() if not x: return [0] # all zero の場合 r0,r1,s0,s1 = x,[0]*(2*L-1)+[1],[1],[0] while len(s1) <= L and r1 != [0]: q,r = divmod_poly(r0,r1,MOD) #print(r0,r1,q,r) #assert mul_poly(q,r1,MOD)==sub_poly(r0,r,MOD) r0,r1 = r1,r s0,s1 = s1, sub_poly(s0,mul_poly(q,s1,MOD),MOD) #print(q,r0,r1,s0,s1) while s0 and s0[-1]==0: s0.pop() ainv = modinv(s0[-1],MOD) return [si*ainv%MOD for si in s0] def f(n,op,I): ans = 0 for p in range(1<<n): for q in range(1<<n): L = 0 for i in range(n): L |= op(p>>i&1,q>>i&1,I)<<i R = (1<<n)-1-L assert L >= 0 and R >= 0 #print(L,R,1<<n) ans += max(L,R) - min(L,R) + 1 return ans%MOD def fps_nth_term(f,g,N): assert g[0] != 0 while N: h = g[:] for i in range(1,len(g),2): h[i] = -h[i] f = polymul(f,h)[N%2:N+1:2] g = polymul(g,h)[:N+1:2] N //= 2 return f[0]*pow(g[0],MOD-2,MOD)%MOD # a[0],...,a[L-2] とL-1次特性多項式 g が与えられているL項間漸化式の第N項 def rec_nth_term(a,g,N): L = len(g) assert len(a) == L-1 f = polymul(a,g)[:L-1] return fps_nth_term(f,g,N) MOD = 10**9+7 def polymul(x,y):return mul_poly(x,y,MOD) n = int(input()) k = input() ans = 0 for i in range(8): if k[i] == "-": continue if n==0: continue def op(x,y,i): if x==0 and y==0: return i>>0&1 if x==0 and y: return i>>1&1 if x and y==0: return i>>2&1 return 0 lst = [f(k,op,i) for k in range(1,7)] #print(lst) a = bm(lst[:],MOD)[::-1] #for i in range(10): # x = rec_nth_term(lst[:len(a)-1],a,i) # print(lst,a,x) #for i,j in zip(lst,lst[1:]): # print(i*12-j*32) ans += rec_nth_term(lst[:len(a)-1],a,n-1) print(ans%MOD)