测试107:AK
这场AK了。
总结见纪念总结。
#include<bits/stdc++.h> #define F(i,a,b) for(int i=a;i<=b;++i) #define LL long long #define pf(a) printf("%d ",a) #define phn puts("") using namespace std; int read(); int n,K; #define N 4002 char a[N]; int main(){ freopen("swap.in","r",stdin);freopen("swap.out","w",stdout); n=read();K=read(); scanf("%s",a+1); a[0]=a[n+1]=0; int ans=0; for(int i=1,l,r,w,c,pl,pr;i<=n;){ l=r=i;w=0;c=0; while(r<n&&a[r+1]==a[i])++r; w=r-l+1;pl=l-1;pr=r+1; while(pl>0&&a[pl]!=a[i])--pl; while(pr<=n&&a[pr]!=a[i])++pr; // pf(i);phn;/** */ while(c<K){ if(pl==0&&pr==n+1)break; if(pl>0&&(pr==n+1||pr-r>l-pl)){ if(c+l-pl-1<=K){ c+=l-pl-1; --l;++w; // pf(pl);pf(c);pf(w);phn;/** */ --pl;while(pl>0&&a[pl]!=a[i])--pl; } else break; } else if(pr<=n&&(pl==0||pr-r<=l-pl)){ if(c+pr-r-1<=K){ c+=pr-r-1; ++r;++w; // pf(pr);pf(c);pf(w);phn;/** */ ++pr;while(pr<=n&&a[pr]!=a[i])++pr; } else break; } } // phn;/** */ ans=max(ans,w); while(a[i+1]==a[i])++i; ++i; } printf("%d\n",ans); } int read(){ int s=0,f=0;char ch=getchar(); while(!isdigit(ch))f=ch=='-',ch=getchar(); while(isdigit(ch))s=s*10+(ch^48),ch=getchar(); return f?-s:s; } /* g++ swap.cpp ./a.out */
#include<bits/stdc++.h> #define F(i,a,b) for(int i=a;i<=b;++i) #define LL long long #define pf(a) printf("%d ",a) #define phn puts("") using namespace std; int read(); #define N 300010 int n; int prm[2005],tot; char vis[2005]; const int mod=137313; struct Hash{ int to[N],fir[N],val[N],head[mod],cnt; int &operator[](int x){ int t=x%mod; for(int i=head[t];i;i=fir[i])if(to[i]==x)return val[i]; to[++cnt]=x;fir[cnt]=head[t]; return val[head[t]=cnt]=0; } }q; void Paris(){ for(int i=2,maxn=1e3;i<=maxn;++i){ if(!vis[i]){ prm[++tot]=i; } for(int j=1;j<=tot&&i*prm[j]<=maxn;++j){ vis[i*prm[j]]=1; if(i%prm[j]==0)break; } } // pf(tot);phn; } int main(){ freopen("square.in","r",stdin);freopen("square.out","w",stdout); Paris(); n=read(); LL ans=0; for(int i=1,x,A;i<=n;++i){ x=read();A=1; for(int j=1,M;j<=tot&&prm[j]<=x;++j){ M=prm[j]*prm[j]; while(x%M==0)x/=M; if(x%prm[j]==0){ A*=prm[j];x/=prm[j]; } } if(x>1){ int w=sqrt(x); if(w*w==x)x=1; else A*=x; } ans+=(++q[A])-1; } printf("%lld\n",ans); } int read(){ int s=0,f=0;char ch=getchar(); while(!isdigit(ch))f=ch=='-',ch=getchar(); while(isdigit(ch))s=s*10+(ch^48),ch=getchar(); return f?-s:s; } /* g++ d2.cpp ./a.out g++ square.cpp time ./a.out 5 1 2 3 4 12 */
#include<bits/stdc++.h> #define F(i,a,b) for(int i=a;i<=b;++i) #define LL long long #define pf(a) printf("%d ",a) #define phn puts("") using namespace std; int read(); #define lxt 1110 #define N 1110 struct nd{ int a[102]; }s[N]; const int mod=1e9+7; int D,n;//维,点。 int jc[10000010]; LL inv[101110]; LL qpow(LL x,int k){LL s=1;for(;k;k>>=1,x=x*x%mod)if(k&1)s=s*x%mod;return s;} LL f[N]; #define M 250010 int to[M],fir[M],head[N],cnt,du[N]; void add(int x,int y){to[++cnt]=y;fir[cnt]=head[x];head[x]=cnt;} void Paris(){ #define LXT 58 jc[0]=inv[0]=1; const int ED=1e7, maxn=1e5; F(i,1,ED)jc[i]=1ll*jc[i-1]*i%mod; inv[maxn]=qpow(jc[maxn],mod-2); for(int i=maxn;i>0;--i)inv[i-1]=inv[i]*i%mod; } queue<int>q; LL cal(int las,int x){ int sum=0,w=0; LL ans=1; F(j,1,D){ w=s[x].a[j]-s[las].a[j]; ans=ans*inv[w]%mod;sum+=w; } ans=ans*jc[sum]%mod; return ans; } signed main(){ freopen("net.in","r",stdin);freopen("net.out","w",stdout); D=read();n=read();//变量名。 Paris(); F(j,1,D){ s[0].a[j]=0; s[n+1].a[j]=read(); } F(i,1,n){ F(j,1,D){ s[i].a[j]=read(); } } ++n; F(i,1,n){ F(k,1,n)if(i^k){ int p=1;//i<=k,i->k F(j,1,D){ if(s[i].a[j]>s[k].a[j]){p=0;break;} } if(p){ add(i,k);++du[k]; } } } F(i,1,n){ f[i]=cal(0,i); if(!du[i]){ q.push(i); } } int u; while(!q.empty()){ u=q.front();q.pop(); for(int i=head[u],v;i;i=fir[i]){ v=to[i]; f[v]=(f[v]-f[u]*cal(u,v))%mod; --du[v]; if(du[v]==0){ q.push(v); } } } f[n]=(f[n]%mod+mod)%mod; printf("%lld\n",f[n]); } int read(){ int s=0,f=0;char ch=getchar(); while(!isdigit(ch))f=ch=='-',ch=getchar(); while(isdigit(ch))s=s*10+(ch^48),ch=getchar(); return f?-s:s; } /* g++ net.cpp time ./a.out 3 2 3 3 4 1 3 2 0 1 2 */
于11月9号。
Informatik verbindet dich und mich.
信息将你我连结。