A piece of water:
According to greedy thought to find is 2 of the K-square, and then high-precision calculation
Code:
#include <bits/stdc++.h>using namespacestd;Const intn=10005;intAns,n,a[n],b[n];structzz{intLen,a[n]; voidinit () {memset (A,0,sizeofa); Len=0; } voidWrite () { for(inti=len;i;i--) printf ("%d", A[i]);} ZZoperator*(ConstZZ B) {zz H;h.init (); H.len=len+b.len-1; for(intI=1; i<=len;i++) for(intj=1; j<=b.len;j++) H.a[i+j-1]+=a[i]*B.a[j], h.a[i+j]+=h.a[i+j-1]/Ten, h.a[i+j-1]%=Ten; if(H.a[len+b.len]) h.len++; returnh; }}x,y;voidKsmintk) {x.a[1]=x.len=y.len=1; y.a[1]=2; while(k) {if(k%2==1) x=x*y; Y=y*y; K/=2; }}intMain () {scanf ("%d",&N); for(intI=0; i<n;i++) scanf ("%d",&A[i]); for(intI=0; i<n;i++) scanf ("%d",&B[i]); for(intI=1; i<n;i++) for(intj=0; j<n;j++) if(a[i]==b[j]&&a[i-1]==b[j+1]) ans++; KSM (ANS); X.write (); return 0;}
51nod Algorithm Marathon 28-a