Another test, this time the title was feeling much more difficult, lied to a lot of points, even rk13
A look at the first question can not be done, then look at the second question
The second question did not start thinking, then I spotted k <= 1,
Obviously k = 0 only when all the numbers required to gcd,
k = 1, then each enumeration tree, adding 1 to it, and then seek gcd, takes a maximum value gcd
Then look at the third question, k <= 4, 10% of data and samples already told you k = 2 and k = 3 Answers,
Only then the remaining k = 0 or k = 1 or k = 4;
k = 0 is 0, k = 1 is 1, k = 4, then less data, dfs violent run out.
So I think violence ran more points, so with the violence following the code:
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #define ll long long 6 #define re register 7 using namespace std; 8 const ll mod=1e9+7; 9 ll tot,ans=0,son[10005][3]; 10 bool vis[10005]; 11 ll to[10005],nxt[10005],pre[10005],cnt; 12 inline void add(re ll u,re ll v){ 13 cnt++,to[cnt]=v,nxt[cnt]=pre[u],pre[u]=cnt; 14 } 15 inline void build(re ll k,re ll l,re ll r){ 16 if(l==r) return ; 17 if((k<<1)>tot) return ; 18 son[k][1]=k<<1; 19 son[k][2]=k<<1|1; 20 ll mid=(l+r)>>1; 21 build(k<<1,l,mid); 22 build(k<<1|1,mid+1,r); 23 } 24 inline void DFS(re ll x,re ll now){ 25 for(re ll i=1;i<=2;i++){ 26 if(son[now][i]==0) continue; 27 add(x,son[now][i]),add(son[now][i],x); 28 DFS(x,son[now][i]); 29 } 30 } 31 inline void dfs(re ll x){ 32 ans++; 33 vis[x]=1; 34 for(re ll i=pre[x];i;i=nxt[i]){ 35 if(!vis[to[i]]) 36 dfs(to[i]); 37 } 38 vis[x]=0; 39 } 40 signed main(){ 41 //freopen("data.out","w",stdout); 42 for(re ll i=1;i<=10;i++){ 43 cnt=0; 44 memset(pre,0,sizeof(pre)); 45 tot=(1<<i)-1; 46 build(1,1,tot); 47 for(re ll j=1;j<=tot;j++){ 48 DFS(j,j); 49 } 50 ans=0; 51 for(re ll j=1;j<=tot;j++){ 52 dfs(j); 53 ans=((ans>=mod)?(ans-mod):ans); 54 } 55 cout<<"ans"<<i<<"="<<ans<<endl; 56 } 57 return 0; 58 }
But it is far to the edge, two hours only ran five points, then no way would the Nianshang Qu
And then look at the second question
Ever more like half, then punched a half, several molding sample passed, and the complexity is similar, to pay up
Finally, the first question had to cout << 0 << endl; but there are still 20 points!
20 + 40 + 10 = 70, I really hit the jackpot
Attachment: binary code for 40 minutes (in fact, this question does not have the decision-monotonic, two points are wrong)
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #define MAXN 105 5 #define ll long long 6 #define re register 7 using namespace std; 8 ll n,k,a[MAXN],gcd,r=0,l=1,mid,ans=0,max_day,max_a; 9 ll b[MAXN]; 10 bool is_stop[MAXN]; 11 inline ll GCD(ll a,ll b){ 12 return b==0?a:GCD(b,a%b); 13 } 14 inline ll judge(ll x){ 15 memset(b,0,sizeof(b)); 16 memset(is_stop,0,sizeof(is_stop)); 17 ll res=0; 18 for(re ll i=x;i<=max_day;i+=x){ 19 for(re ll j=1;j<=n;j++){ 20 if(is_stop[j]) continue; 21 b[j]+=x; 22 if(b[j]>=a[j]){ 23 res+=(b[j]-a[j]); 24 is_stop[j]=1; 25 } 26 } 27 } 28 return res; 29 } 30 inline ll max(ll a,ll b){return a>b?a:b;} 31 signed main(){ 32 scanf("%lld%lld",&n,&k); 33 if(k==0){ 34 for(re ll i=1;i<=n;i++){ 35 scanf("%lld",&a[i]); 36 if(a[i]==1){ 37 cout<<1<<endl; 38 return 0; 39 } 40 if(i==1) gcd=a[i]; 41 else gcd=GCD(gcd,a[i]); 42 } 43 printf("%lld\n",gcd); 44 return 0; 45 } 46 if(k==1){ 47 for(re ll i=1;i<=n;i++){ 48 scanf("%lld",&a[i]); 49 if(i==1) gcd=a[i]; 50 else gcd=GCD(gcd,a[i]); 51 } 52 for(re ll i=1;i<=n;i++){ 53 a[i]++; 54 ll temp=a[1]; 55 for(re ll j=2;j<=n;j++){ 56 temp=GCD(temp,a[j]); 57 } 58 a[i]--; 59 gcd=max(gcd,temp); 60 } 61 printf("%lld\n",gcd); 62 return 0; 63 } 64 for(re ll i=1;i<=n;i++){ 65 scanf("%lld",&a[i]); 66 r=max(r,a[i]); 67 } 68 max_a=r; 69 r+=k; 70 while(l<=r){ 71 mid=(l+r)>>1; 72 if(max_a%mid==0) max_day=max_a; 73 else max_day=(max_a/mid+1)*mid; 74 if(judge(mid)<=k){ 75 ans=max(ans,mid),l=mid+1; 76 }else r=mid-1; 77 } 78 printf("%lld\n",ans); 79 return 0; 80 }