题解见:http://ecustacm.cn/contest/11/announcements
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
int a[maxn],ans; char c[maxn];
int main()
{
int T,N,A,B,C,D,Ca=;
scanf("%d",&T);
while(T--){
scanf("%s",c+); N=strlen(c+);
A=B=C=D=;
rep(i,,N){
if(c[i]=='') A++;
if(c[i]=='') B++;
if(i<N&&c[i]==''&&c[i+]=='') C++;
if(i<N&&c[i]==''&&c[i+]=='') D++;
}
printf("Case %d: %d %d %d %d\n",++Ca,A,B,C,D);
}
return ;
}
B
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
char c[maxn];
int main()
{
int T,A,B,C,D,Ca=;
scanf("%d",&T);
while(T--){
scanf("%d%d%d%d",&A,&B,&C,&D);
printf("Case %d: ",++Ca);
if(A<C||A<D||B<C||B<D||abs(C-D)>) { puts("-1"); continue;}
if(B==){
rep(i,,A) putchar(''); puts("");
}
else if(A==){
rep(i,,B) putchar(''); puts("");
}
else if(C==D){
int ta=C+,tb=D;
if(A<ta||B<tb){
ta=C,tb=C+;
if(A<ta||B<tb){ puts("-1"); continue;}
putchar('');
rep(i,,C){
putchar('');
if(i==){
rep(j,,A-ta) putchar('');
}
if(i==C){
rep(j,,B-tb) putchar('');
}
putchar('');
}
puts("");
}
else {
rep(i,,A-ta) putchar('');
rep(i,,C) putchar(''),putchar('');
rep(i,,B-tb) putchar('');
putchar('');
puts("");
}
}
else if(C==D+){
int ta=C,tb=C;
if(A<ta||B<tb){ puts("-1"); continue;}
rep(i,,A-ta) putchar('');
rep(i,,C) putchar(''),putchar('');
rep(i,,B-tb) putchar('');
puts("");
}
else if(D==C+){
int ta=D,tb=D;
if(A<ta||B<tb){ puts("-1"); continue;}
//cout<<D<<" "<<A-ta<<" "<<B-tb<<endl;
rep(i,,D){
putchar('');
if(i==) {
rep(j,,A-ta) putchar('');
}
if(i==D) {
rep(j,,B-tb) putchar('');
}
putchar('');
}
puts("");
}
}
return ;
}
C
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
char c[maxn];
struct SAM
{
int ch[maxn][],fa[maxn],maxlen[maxn],cnt,last;
void init()
{
cnt=; last=; memset(ch[],,sizeof(ch[]));
}
void add(int x)
{
int np=++cnt,p=last;
last=np; maxlen[cnt]=maxlen[p]+;
memset(ch[np],,sizeof(ch[np]));
while(p&&!ch[p][x])ch[p][x]=np,p=fa[p];
if(!p) fa[np]=;
else {
int q=ch[p][x];
if(maxlen[q]==maxlen[p]+) fa[np]=q;
else {
int nq=++cnt; maxlen[nq]=maxlen[p]+;
memcpy(ch[nq],ch[q],sizeof(ch[q]));
fa[nq]=fa[q], fa[q]=fa[np]=nq;
while(p&&ch[p][x]==q) ch[p][x]=nq,p=fa[p];
}
}
}
}S;
int q[maxn],pos[maxn],pre[maxn],head;
int fcy,tail,ans[maxn];
int main()
{
int T,N,Ca=;
scanf("%d",&T);
while(T--){
scanf("%d%s",&N,c+);
S.init();
rep(i,,N) S.add(c[i]==''?:);
head=tail=;
q[++head]=; pos[head]=; pre[head]=;
while(tail<head){
int u=q[++tail];
q[++head]=S.ch[u][]; pos[head]=; pre[head]=tail;
if(!S.ch[u][]) {
fcy=head;
break;
}
q[++head]=S.ch[u][]; pos[head]=; pre[head]=tail;
if(!S.ch[u][]) {
fcy=head;
break;
}
}
int tot=;
while(fcy>){
ans[++tot]=pos[fcy];
fcy=pre[fcy];
}
printf("Case %d: %d\n",++Ca,tot);
for(int i=tot;i>=;i--)
putchar(ans[i]?'':'');
puts("");
}
return ;
}
D
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
int main()
{
int T,N,M,Ca=,ans;
scanf("%d",&T);
while(T--){
scanf("%d%d",&N,&M);
ans=max(N,M);
ans=max(ans,(N*M+)/);
if(N>M) swap(N,M);
if(N==) {
int res=M/*;
if(M%==) res+=;
if(M%>=) res+=;
ans=max(ans,res);
}
printf("Case %d: %d\n",++Ca,ans);
}
return ;
}
E
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
bitset<maxn>A,B;
int main()
{
int N,L,R,x,ans; A[]=;
scanf("%d",&N);
rep(i,,N){
scanf("%d%d",&L,&R);
B.reset();
rep(j,L,R){
x=j*j;
B|=(A<<x);
}
A=B;
}
ans=A.count();
printf("%d\n",ans);
return ;
}
F
#include<bits/stdc++.h>
#define rep(i,w,v) for(int i=w;i<=v;i++)
using namespace std;
const int maxn=;
const int maxm=;
int N,M,K,ans,a[maxn][maxn];
int Laxt[maxn],Next[maxm],To[maxm],cnt;
int linke[maxn],vis[maxn];
void add(int u,int v)
{
Next[++cnt]=Laxt[u]; Laxt[u]=cnt;To[cnt]=v;
}
bool find(int u)
{
for(int i=Laxt[u];i;i=Next[i]){
int v=To[i];if(vis[v]) continue;
vis[v]=;
if(!linke[v]||find(linke[v])){
linke[v]=u;
return true;
}
}
return false;
}
bool check(int Mid)
{
int res=; cnt=;
memset(Laxt,,sizeof(Laxt));
memset(linke,,sizeof(linke));
rep(i,,N) rep(j,,M)
if(a[i][j]<=Mid) add(i,j);
rep(i,,N){
memset(vis,,sizeof(vis));
if(find(i)) res++;
}
return res>=K;
}
int main()
{
scanf("%d%d%d",&N,&M,&K); K=N+-K;
rep(i,,N) rep(j,,M) scanf("%d",&a[i][j]);
int L=,R=;
while(L<=R){
int Mid=(L+R)>>;
if(check(Mid)) ans=Mid,R=Mid-;
else L=Mid+;
}
printf("%d\n",ans);
return ;
}