結果
問題 | No.1410 A lot of Bit Operations |
ユーザー | convexineq |
提出日時 | 2021-02-27 08:09:39 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,276 bytes |
コンパイル時間 | 343 ms |
コンパイル使用メモリ | 82,168 KB |
実行使用メモリ | 77,340 KB |
最終ジャッジ日時 | 2024-10-02 17:05:23 |
合計ジャッジ時間 | 6,342 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 66 ms
71,952 KB |
testcase_01 | AC | 104 ms
76,204 KB |
testcase_02 | AC | 110 ms
76,460 KB |
testcase_03 | AC | 107 ms
76,428 KB |
testcase_04 | AC | 106 ms
76,624 KB |
testcase_05 | AC | 64 ms
72,212 KB |
testcase_06 | AC | 100 ms
76,256 KB |
testcase_07 | AC | 85 ms
76,144 KB |
testcase_08 | AC | 106 ms
76,908 KB |
testcase_09 | AC | 107 ms
77,036 KB |
testcase_10 | AC | 112 ms
77,092 KB |
testcase_11 | AC | 88 ms
76,324 KB |
testcase_12 | AC | 87 ms
76,600 KB |
testcase_13 | AC | 107 ms
76,232 KB |
testcase_14 | AC | 105 ms
76,488 KB |
testcase_15 | AC | 107 ms
76,132 KB |
testcase_16 | AC | 113 ms
77,176 KB |
testcase_17 | AC | 92 ms
76,300 KB |
testcase_18 | AC | 113 ms
77,340 KB |
testcase_19 | AC | 107 ms
76,452 KB |
testcase_20 | AC | 112 ms
77,092 KB |
testcase_21 | AC | 104 ms
76,224 KB |
testcase_22 | AC | 107 ms
77,140 KB |
testcase_23 | AC | 110 ms
76,368 KB |
testcase_24 | AC | 107 ms
76,672 KB |
testcase_25 | AC | 111 ms
76,892 KB |
testcase_26 | AC | 112 ms
77,212 KB |
testcase_27 | AC | 114 ms
76,948 KB |
testcase_28 | AC | 111 ms
76,944 KB |
testcase_29 | AC | 108 ms
77,036 KB |
testcase_30 | AC | 92 ms
76,284 KB |
testcase_31 | AC | 102 ms
76,460 KB |
testcase_32 | AC | 117 ms
76,908 KB |
testcase_33 | AC | 112 ms
77,176 KB |
testcase_34 | AC | 111 ms
77,136 KB |
testcase_35 | AC | 118 ms
76,988 KB |
testcase_36 | AC | 114 ms
76,976 KB |
testcase_37 | AC | 88 ms
76,284 KB |
testcase_38 | AC | 38 ms
53,016 KB |
testcase_39 | AC | 63 ms
72,444 KB |
testcase_40 | AC | 65 ms
72,920 KB |
testcase_41 | AC | 39 ms
53,232 KB |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | AC | 40 ms
54,796 KB |
testcase_45 | AC | 115 ms
76,920 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,i) for k in range(1,7)] 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 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)