Codeforces Round #804 (Div. 2)
A:
#include<cstdio>
#include<cstring>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<math.h>
using namespace std;
const int INF=0x3f3f3f3f;
inline int read()
{
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0',c=getchar();}
return x*f;
}
int main()
{
int T=read();
while(T--)
{
int n=read();
if(n&1)cout<<-1<<endl;
else printf("%d %d %d\n",0,0,n/2);
}
return 0;
}
B:
#include<cstdio>
#include<cstring>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<math.h>
using namespace std;
const int INF=0x3f3f3f3f;
inline int read()
{
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0',c=getchar();}
return x*f;
}
int ans[100][100];
int main()
{
int T=read();
while(T--)
{
int n=read(),m=read();
for(int i=1;i<=n;i+=2)
{
if((i-1)/2&1)ans[i][2]=1,ans[i+1][1]=1;
else ans[i][1]=1,ans[i+1][2]=1;
}
for(int i=1;i<=n;i+=2)
{
for(int j=3;j<=m;j+=2)
{
if(ans[i][j-2])ans[i][j+1]=1,ans[i+1][j]=1;
else ans[i][j]=1,ans[i+1][j+1]=1;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)printf("%d ",ans[i][j]);
printf("\n");
}
}
return 0;
}
C:
#include<cstdio>
#include<cstring>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<math.h>
#define ll long long
using namespace std;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
inline int read()
{
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0',c=getchar();}
return x*f;
}
const int N=1e5+10;
int a[N],id[N];
ll ans;
int main()
{
int T=read();
while(T--)
{
int n=read();
ans=1;
for(int i=1;i<=n;i++)a[i]=read(),id[a[i]]=i;
int l=id[0],r=id[0];
for(int i=1;i<=n-1;i++)
{
if(id[i]<l||id[i]>r)
{
if(id[i]<l)l=id[i];
else r=id[i];
}
else ans=ans*(r-l+1-i)%mod;
}
printf("%lld\n",max(ans,1ll));
}
return 0;
}
D:
#include<cstdio>
#include<cstring>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<math.h>
using namespace std;
const int INF=0x3f3f3f3f;
inline int read()
{
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0',c=getchar();}
return x*f;
}
const int N=5010;
int a[N],b[N];
int f[N];
int main()
{
int T=read();
while(T--)
{
int n=read();
for(int i=1;i<=n;i++)a[i]=read();
a[0]=a[n+1]=0;
f[0]=0;
for(int i=1;i<=n+1;i++)
{
int v=-INF;
memset(b,0,sizeof(b));
int mx=0;
for(int j=i-1;j>=0;j--)
{
if(j+1<i)
{
b[a[j+1]]++;
mx=max(mx,b[a[j+1]]);
}
if(mx*2<=i-j-1&&(i^j)&1&&(a[i]==a[j]||!a[i]||!a[j]))v=max(v,f[j]+1);
}
f[i]=v;
}
printf("%d\n",f[n+1]-1);
}
return 0;
}