Educational Codeforces Round 53 (Rated for Div. 2)

时间:2022-06-10 03:15:13

http://codeforces.com/contest/1073

A. Diverse Substring

 #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define minv 1e-6
#define inf 1e9
#define pi 3.1415926536
#define nl 2.7182818284
const ll mod=1e9+;//
const int maxn=1e3+; char s[maxn]; int main()
{
int n,i;
scanf("%d",&n);
scanf("%s",s);
for (i=;i<=n-;i++)
if (s[i]!=s[i+])
break;
if (i==n-)
printf("NO");
else
{
printf("YES\n");
printf("%c%c",s[i],s[i+]);
}
return ;
}

B. Vasya and Books

 #include <iostream>
#include <cstdio>
using namespace std;
const int maxn=2e5+; int f[maxn]; int main()
{
int n,a,v=,i;
scanf("%d",&n);
for (i=;i<=n;i++)
{
scanf("%d",&a);
f[a]=i;
}
for (i=;i<=n;i++)
{
scanf("%d",&a);
if (i!=)
printf(" ");
if (f[a]<v)
printf("");
else
printf("%d",f[a]-v);
v=max(f[a],v);
}
return ;
}

C. Vasya and Robot

奇偶,负数取模

 #include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=2e5+;
const ll inf=1e9; int px[maxn],py[maxn]; int main()
{
char c;
int n,x,y,ax,ay,i,l,r,m,re;
scanf("%d\n",&n);
for (i=;i<=n;i++)
{
scanf("%c",&c);
if (c=='U')
x=,y=;
else if (c=='D')
x=,y=-;
else if (c=='L')
x=-,y=;
else
x=,y=;
px[i]=px[i-]+x;
py[i]=py[i-]+y;
}
scanf("%d%d",&ax,&ay);
if (px[n]==ax && py[n]==ay)
{
printf("");
return ;
}
if (abs(ax+ay+n)%==)
{
printf("-1");
return ;
}
re=inf;
for (i=;i<=n;i++)
{
l=i;
r=n;
while (l<=r)
{
m=(l+r)>>;
///change [i,m] ; use [1,i-1] [m+1,n]
if (m-i+>=abs(px[i-]+px[n]-px[m]-ax)+abs(py[i-]+py[n]-py[m]-ay))
r=m-;
else
l=m+;
}
if (l!=n+)
re=min(re,l-i+);
}
if (re==inf)
re=-;
printf("%d",re);
return ;
}

D. Berland Fair

 #include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=2e5+; int nex[maxn],a[maxn]; int main()
{
int n,i,j,g;
ll m,tot=,num=;
scanf("%d%lld",&n,&m); for (i=;i<n;i++)
scanf("%d",&a[i]),tot+=a[i];
for (i=;i<n;i++)
nex[i]=(i+)%n;
g=n;
i=;
j=n-;
while (nex[i]!=i)
{
num+=m/tot*g;
m%=tot;
while (nex[i]!=i)
{
if (a[i]<=m)
{
m-=a[i];
num++;
j=i;
}
else
{
nex[j]=nex[i];
tot-=a[i];
g--;
}
i=nex[i];
if (m>=tot)
break;
}
}
num+=m/a[i];
cout<<num;
return ;
}
/*
1 100
1 3 1000
1 2 100
*/

E. Segment Sum

代码是错的,以待后续埋坑

 #include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=;
const double minv=1e-; ll sum=,shi[],k,f[][]; void work(ll a,int w,int g,int hav,ll num,int ori,int cond)
{
int s,gg,i,j,c;
if (a==)
return;
s=a/shi[w];
for (i=;i<=s;i++)
{
gg=g-(!((hav>>i) & ) && (!(i== && ori==)));
if (gg>=)
{
if (i<s)
{
/**
这一位选的是i,
除去这一位,还有w位,
从gg个数中选j个数作为需要添加的数(之前没出现过的),
每一位都有k-gg+j种选择
**/
f[][]=;
for (j=;j<=w;j++)
{
f[j][]=f[j-][]*(k-gg)%mod;
///already k-gg numbers
sum=(sum+f[j-][]* sum of k-gg numbers )%mod; for (c=;c<=min(gg,j);c++) sum=(sum+f[j-][c]* k-gg+c numbers + f[j-][c-]* any number(random average of gg numbers)) f[j][c]=(f[j-][c]*(k-gg+c)+f[j-][c-]*(-(k-gg+c-)))%mod;
}
for (c=;c<=min(gg,w);c++)
sum=(sum+f[w][c]*cond)%mod; ///geshu
// f[0][0]=1;
// for (j=1;j<=w;j++)
// {
// f[j][0]=f[j-1][0]*(k-gg)%mod;
// for (c=1;c<=min(gg,j);c++)
// f[j][c]=(f[j-1][c]*(k-gg+c)+f[j-1][c-1]*(10-(k-gg+c-1)))%mod;
// }
// for (c=0;c<=min(gg,w);c++)
// sum=(sum+f[w][c]*cond)%mod;
}
else
work(a%shi[w],w-,gg,hav|(<<i),ori&(i==),cond);
}
}
} int main()
{
ll l,r;
int i,w;
scanf("%lld%lld%d",&l,&r,&k);
shi[]=;
for (i=;i<=;i++)
shi[i]=shi[i-]*; w=log(r+minv)/log();
work(r,w,k,,,,);
if (l!=)
{
w=log(l-+minv)/log();///l=1???
work(l-,w,k,,,,-);
}
printf("%lld",(sum+mod)%mod);
return ;
}