# Codeforces Round #517 Div. 2/Div. 1

$n$天没更博了，因为被膜你赛的毒瘤题虐哭了。。。

## A

#include<bits/stdc++.h>
#define LL long long
#define RG register
#define R RG int
using namespace std;
int main(){
LL w,h,k,ans=0;
cin>>w>>h>>k;
while(k--){
ans+=2*(w+h-2);
w-=4;h-=4;
}
cout<<ans<<endl;
return 0;
}


## B

#include<bits/stdc++.h>
#define LL long long
#define RG register
#define R RG int
using namespace std;
const int N=100009;
int n,a[N],b[N],t[N];
bool check(){
for(R i=0;i<n-1;++i){
for(t[i+1]=0;t[i+1]<4;++t[i+1])
if((t[i]|t[i+1])==a[i]&&(t[i]&t[i+1])==b[i])break;
if(t[i+1]==4)return 0;
}
return 1;
}
int main(){
ios::sync_with_stdio(0);
cin>>n;
for(R i=0;i<n-1;++i)cin>>a[i];
for(R i=0;i<n-1;++i)cin>>b[i];
for(t[0]=0;t[0]<4;++t[0])
if(check()){
puts("YES");
for(R i=0;i<n;++i)printf("%d ",t[i]);
return puts(""),0;
}
puts("NO");
return 0;
}


## C

#include<bits/stdc++.h>
#define LL long long
#define RG register
#define R RG int
using namespace std;
bool f[70000];
int main(){
RG LL a,b,s,p=0;
cin>>a>>b;
s=(sqrt(8*(a+b)+1)-1)/2.0;
for(R i=s;i;--i)
if(a>=i)a-=i,f[i]=1,++p;
cout<<p<<endl;
for(R i=1;i<=s;++i)if( f[i])printf("%d ",i);puts("");
cout<<s-p<<endl;
for(R i=1;i<=s;++i)if(!f[i])printf("%d ",i);puts("");
return 0;
}


## D

#include<bits/stdc++.h>
#define LL long long
#define RG register
#define R RG int
using namespace std;
const int N=2009;
char s[N][N],ans[N];
int f[N][N],X[2][N],Y[2][N];
bool pr[N][N],vis[N][N];
inline void chkmn(R&x,R y){if(x>y)x=y;}
int main(){
R n,k;
RG char mn;
cin>>n>>k;
for(R i=1;i<=n;++i)cin>>(s[i]+1);
for(R i=1;i<=n;++i)
for(R j=1;j<=n;++j){
f[i][j]=(i==1&&j==1?0:3*N);
if(i!=1)chkmn(f[i][j],f[i-1][j]);
if(j!=1)chkmn(f[i][j],f[i][j-1]);
f[i][j]+=s[i][j]!='a';
if(f[i][j]<=k)s[i][j]='a';
}
R*x1=X[0],*x2=X[1],*y1=Y[0],*y2=Y[1],p1=1,p2=0,x,y;
x1[1]=y1[1]=1;
for(R i=1;i<=2*n;++i){
mn=127;
for(;p1;--p1){
x=x1[p1];y=y1[p1];
if(x<n&&!vis[x+1][y]&&mn>=s[x+1][y]){
if(mn>s[x+1][y])mn=s[x+1][y],p2=1;
else ++p2;
vis[x2[p2]=x+1][y2[p2]=y]=1;
}
if(y<n&&!vis[x][y+1]&&mn>=s[x][y+1]){
if(mn>s[x][y+1])mn=s[x][y+1],p2=1;
else ++p2;
vis[x2[p2]=x][y2[p2]=y+1]=pr[x][y+1]=1;
}
}
swap(x1,x2);swap(y1,y2);swap(p1,p2);
}
for(x=n,y=n;x!=1||y!=1;pr[x][y]?--y:--x)
ans[x+y-2]=s[x][y];
ans[0]=s[1][1];
puts(ans);
return 0;
}


## E

#include<bits/stdc++.h>
#define LL long long
#define RG register
#define R RG int
using namespace std;
const int N=1e5+9,M=99,Q=2099;
int a[N],ax[N],c[M],d[M],id1[M],id2[M],q[Q],dis[Q],pr[Q];
int main(){
R n,p=0,ans=0,x,y;
cin>>n;
for(R i=1;i<=n;++i)cin>>a[i];
for(R i=0;i<6;++i)
for(R j=1;i-2*j>=-6;++j){
c[++p]=i;d[p]=j;
x=1<<i;x|=(x>>j)|(x>>2*j);
if(!id1[x])id1[x]=p;
}
for(R i=1;i<=p;++i)
for(R j=1;j<=p;++j){
x=1<<c[i];x|=(x>>d[i])|(x>>2*d[i]);
y=1<<c[j];y|=(y>>d[j])|(y>>2*d[j]);
if(!id1[x^=y])id1[x]=i,id2[x]=j;
}
id1[0]=id2[0]=0;
for(R i=n-5;i>6;i-=6){
x=0;for(R j=i+5;j>=i;--j)(x<<=1)|=a[j];
ax[i]=x;
if(id1[x]){
R j=i+c[id1[x]],nd=d[id1[x]];
a[j-2*nd]^=1;a[j-nd]^=1;a[j]^=1;++ans;
}
if(id2[x]){
R j=i+c[id2[x]],nd=d[id2[x]];
a[j-2*nd]^=1;a[j-nd]^=1;a[j]^=1;++ans;
}
}
R S=1<<(p=min(n,11));
memset(dis,-1,4*S);
x=0;for(R j=p;j;--j)(x<<=1)|=a[j];
dis[q[0]=x]=0;
for(R h=0,t=0;h<=t;++h){
R x=q[h];if(!x)break;
for(R i=2;i<p;++i)
for(R j=i>>1;j;--j){
y=x^(1<<(i-2*j))^(1<<(i-j))^(1<<i);
if(!~dis[y])dis[q[++t]=y]=dis[pr[y]=x]+1;
}
}
if(!~dis[0])return puts("NO"),0;
printf("YES\n%d\n",ans+dis[0]);
for(x=0;pr[x];x=pr[x]){
R t=0;
for(y=x^pr[x];~y&1;y>>=1,++t);printf("%d ",++t);
for(y>>=1    ;~y&1;y>>=1,++t);printf("%d ",++t);
for(y>>=1    ;~y&1;y>>=1,++t);printf("%d\n",++t);
}
for(R i=n-5;i>6;i-=6){
x=ax[i];
if(id1[x]){
R j=i+c[id1[x]],nd=d[id1[x]];
printf("%d %d %d\n",j-2*nd,j-nd,j);
}
if(id2[x]){
R j=i+c[id2[x]],nd=d[id2[x]];
printf("%d %d %d\n",j-2*nd,j-nd,j);
}
}
return 0;
}


# Div1 E

posted @ 2018-10-23 11:58  Flash_Hu  阅读(309)  评论(1编辑  收藏  举报