比赛题解 【Educational Codeforces Round 9】
A. Grandma Laura and Apples
模拟即可
#include<cstdio>
#include<iostream>
typedef long long ll;
const int MAXN = 40 + 5;
using namespace std;
char s[MAXN][10];
int main(void)
{
int n,p;
scanf("%d%d",&n,&p);
for(int i=1; i<=n; ++i) scanf("%s",s[i]+1);
ll ans=0, now=0;
for(int i=n; i>=1; --i)
{
if(s[i][5])
{
ans+=now*p + p/2;
now=now*2+1;
}
else
{
ans+=now*p;
now<<=1ll;
}
}
cout<<ans;
return 0;
}
B. Alice, Bob, Two Teams
分别处理A和B的前缀和,枚举翻转位置,计算答案
#include<cstdio>
#include<iostream>
typedef long long ll;
const int MAXN = 5e5 + 5;
using namespace std;
char s[MAXN];
ll p[MAXN];
ll a[MAXN],b[MAXN];
int main(void)
{
int n;
scanf("%d",&n);
for(int i=1; i<=n; ++i) cin>>p[i];
scanf("%s",s+1);
for(int i=1; i<=n; ++i)
{
a[i]=a[i-1];
b[i]=b[i-1];
if(s[i]=='A') a[i]+=p[i];
else b[i]+=p[i];
}
ll ans=max(a[n],b[n]);
for(int i=1; i<=n; ++i)
{
ans = max(ans, a[n]-a[i] + b[i]);
ans = max(ans, b[n]-b[i] + a[i]);
}
cout<<ans;
return 0;
}
C. The Smallest String Concatenation
考虑枚举lcm,然后计算序列长度。
用
复杂度是
#include<cstdio>
#include<algorithm>
const int MAXN = 1e6 + 5;
const int MAXM = 1e6 + 5;
using namespace std;
int a[MAXN],b[MAXN],cnt[MAXM],t[MAXM];
int main(void)
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=1; i<=n; ++i)
scanf("%d",&a[i]), b[i]=a[i];
for(int i=1; i<=n; ++i)
if(a[i]<=m) ++cnt[a[i]];
sort(b+1,b+n+1);
int p = unique(b+1,b+n+1)-b-1;
for(int i=1; i<=p && b[i]<=m; ++i)
{
int x=b[i];
for(int j=x; j<=m; j+=x)
{
t[j]+=cnt[x];
}
}
int ans=t[1], maxt=1;
for(int i=2; i<=m; ++i)
if(t[i]>ans)
{
ans=t[i];
maxt=i;
}
printf("%d %d\n",maxt,ans);
for(int i=1; i<=n; ++i)
if(maxt%a[i]==0) printf("%d ",i);
return 0;
}