# AtCoder Beginner Contest 160

A - Coffee

#include <bits/stdc++.h>
#define ll long long
using namespace std;
char s[10];
int main() {
//freopen("in.txt","r",stdin);
scanf("%s",s);
if(s[2]==s[3]&&s[4]==s[5]) printf("Yes\n");
else printf("No\n");
return 0;
}
A.cpp

B - Golden Coins

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
//freopen("in.txt","r",stdin);
ll x;
scanf("%lld",&x);
printf("%lld\n",x/500*1000+(x%500)/5*5);
return 0;
}
B.cpp

C - Traveling Salesman around Lake

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+5;
int a[N<<1];
int main() {
//freopen("in.txt","r",stdin);
int k,n;
scanf("%d%d",&k,&n);
for(int i=0;i<n;i++) {
scanf("%d",&a[i]);
a[i+n]=a[i]+k;
}
int ans=1e9;
for(int i=0;i<n;i++) {
ans=min(ans,a[i+n-1]-a[i]);
}
printf("%d\n",ans);
return 0;
}
C.cpp

D - Line++

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e3+5;
int a[N];
int main() {
//freopen("in.txt","r",stdin);
int n,x,y;
scanf("%d%d%d",&n,&x,&y);
for(int i=1;i<=n;i++) {
for(int j=i+1;j<=n;j++) {
int t=min(j-i,abs(i-x)+abs(j-y)+1);
a[t]++;
}
}
for(int i=1;i<n;i++) {
printf("%d\n",a[i]);
}
return 0;
}
D.cpp

E - Red and Green Apples

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5;
struct P {
int val,id;
bool operator <(const P &t)const {
if(val!=t.val) return val>t.val;
return id<t.id;
}
}p[N*3];
int main() {
//freopen("in.txt","r",stdin);
int x,y,a,b,c;
scanf("%d%d%d%d%d",&x,&y,&a,&b,&c);
for(int i=0,d;i<a;i++) {
scanf("%d",&d),p[i]={d,1};
}
for(int i=0,d;i<b;i++) {
scanf("%d",&d),p[i+a]={d,2};
}
for(int i=0,d;i<c;i++) {
scanf("%d",&d),p[i+a+b]={d,0};
}
a=a+b+c;
sort(p,p+a);
ll ans=0;
int t=0;
for(int i=0;i<a;i++) {
if(p[i].id==1) {
if(x) x--,ans+=p[i].val;
}
else if(p[i].id==2) {
if(y) y--,ans+=p[i].val;
}
else {
t++,ans+=p[i].val;
}
if(t==x+y) break;
}
printf("%lld\n",ans);
return 0;
}
E.cpp

F - Distributing Integers

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+5;
const int MD=1e9+7;
vector<int> G[N];
int f[N],ans[N];
int n,a,b;
int quick_pow(int x,int y) {
int ans=1;
while(y) {
if(y&1) ans=1LL*ans*x%MD;
y>>=1;
x=1LL*x*x%MD;
}
return ans;
}
void dfs(int u,int fa) {
for(auto v:G[u]) {
if(v==fa) continue;
dfs(v,u);
f[u]+=f[v];
}
f[u]++;
}
void cal(int u,int fa) {
for(auto v:G[u]) {
if(v==fa) continue;
ans[v]=1LL*ans[u]*quick_pow(f[v],MD-2)%MD*(n-f[v])%MD;
cal(v,u);
}
}
int main() {
//freopen("in.txt","r",stdin);
scanf("%d",&n);
for(int i=1;i<n;i++) {
scanf("%d%d",&a,&b);
G[a].push_back(b);
G[b].push_back(a);
}
dfs(1,-1);
ans[1]=1;
for(int i=1;i<=n;i++) {
ans[1]=1LL*ans[1]*f[i]%MD;
}
cal(1,-1);
int t=1;
for(int i=1;i<=n;i++) t=1LL*t*i%MD;
for(int i=1;i<=n;i++) {
printf("%d\n",1LL*t*quick_pow(ans[i],MD-2)%MD);
}
return 0;
}
F.cpp

AtCoder Beginner Contest 160

(0)
(0)