結果
問題 | No.1410 A lot of Bit Operations |
ユーザー | convexineq |
提出日時 | 2021-02-27 08:06:30 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,276 bytes |
コンパイル時間 | 307 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 77,312 KB |
最終ジャッジ日時 | 2024-10-02 17:05:17 |
合計ジャッジ時間 | 9,233 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 94 ms
75,904 KB |
testcase_01 | AC | 179 ms
76,672 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 126 ms
76,544 KB |
testcase_08 | AC | 186 ms
76,404 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 130 ms
76,564 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 191 ms
76,544 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 129 ms
76,288 KB |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | AC | 235 ms
77,056 KB |
testcase_36 | AC | 209 ms
76,544 KB |
testcase_37 | WA | - |
testcase_38 | AC | 40 ms
52,864 KB |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | AC | 42 ms
53,376 KB |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | AC | 41 ms
53,376 KB |
testcase_45 | AC | 239 ms
76,800 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 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,1) for k in range(1,9)] if n==0: ans += lst[0] continue #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 a,b in zip(lst,lst[1:]): # print(b*12-a*32) ans += rec_nth_term(lst[:len(a)-1],a,n-1) print(ans%MOD)