AtCoder Beginner Contest 095
今回はABC095の参加記です。結果はA, B, Cの3完で緑パフォでした。
使用言語: C++
A - Something on It
Sにoがいくつあるか数えるだけ。for文を使う方法しか思いつかなかった。
mainの後の2行は入出力の実行速度を向上させるためのもので、競プロではこれを書くか、cin/coutの代わりにscanf/printfを使うのがよいらしい。
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i, n) for(int i=0; i<n; ++i) int main(){ ios::sync_with_stdio(false); cin.tie(0); string s; cin>>s; int ans=0; REP(i, 3){ if(s[i]=='o') ++ans; } cout<<700+ans*100<<'\n'; return 0; }
B - Bitter Alchemy
N種類のドーナツを作った後、N種類のうち最もお菓子の素を消費しないドーナツを作れるだけ作れば個数は最大となる。
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i, n) for(int i=0; i<n; ++i) int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, x; int m; cin>>n>>x; int a=1100; int b=0; REP(i, n){ cin>>m; a=min(a, m); b+=m; } cout<<n+(x-b)/a<<'\n'; return 0; }
C - Half and Half
- のときABピザを買う必要はないので、AピザとBピザについてそれぞれ考えればよい。
- それ以外のとき
- の場合ABピザを枚買った後、Bピザ 枚とABピザ 枚の安い方を買う。
- の場合も同様
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i, n) for(int i=0; i<n; ++i) int main(){ ios::sync_with_stdio(false); cin.tie(0); int a, b, c, x, y; cin>>a>>b>>c>>x>>y; int m; x>y ? m=a : m=b; int ans; if(a+b<=c*2) ans=a*x+b*y; else ans=c*min(x, y)*2+min(m, c*2)*abs(x-y); cout<<ans<<'\n'; return 0; }
D - Static Sushi
- 時計回りに歩いてから反時計回りに歩く
- 反時計回りに歩いてから時計回りに歩く
を全探索すれば部分点はもらえると思ったのだが、実装が間に合わなかった。解法を思いついてから1時間くらいあったのに……。D問題を通せば水色が見えてくるので頑張りたいところだがこれが実力か。
コンテスト終了後にtwitterを眺めていて累積和を知った。こんな便利なものがあったのか~
次回
次回のコンテストは予定表通りなら前回太陽を生やしたAGCです。A問題くらいは解きたいと思っています