AtCoder Beginner Contest 148
はい. AtCoder Beginner Contest 148 です
本当は ABC146,147 を先に書かないといけないんですけど,このままだと永遠にスタックされていきそうなので,とりあえず ABC148 について書きます.
ABCDの4完でした.結構簡単だったみたいで,パフォーマンス低かったです…
E が解けませんでした.解きたかった_(:3」∠)_
F も時間があってちゃんと考察したら解けそうな気がしています(気がしているだけ)
- A - Round One
- B - Strings with the Same Length
- C - Snack
- D - Brick Break
- E - Double Factorial /
- まとめ
- 参考
A - Round One
選択肢が であり,選択肢 が誤答だと分かっているようです.
合計が であることが分かっているので, を出力すれば良いです.
#include <iostream> #include <iomanip> #include <vector> #include <utility> #include <map> #include <algorithm> #include <queue> #include <cmath> #include <numeric> using namespace std; struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa; typedef long long int64; int main() { int a,b; cin >> a >> b; cout << 6 - a - b << endl; }
B - Strings with the Same Length
長さが同じなので,交互に出力するだけです.
#include <iostream> #include <iomanip> #include <vector> #include <utility> #include <map> #include <algorithm> #include <queue> #include <cmath> #include <numeric> using namespace std; struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa; typedef long long int64; int main() { int n; string s,t; cin >> n >> s >> t; for (int i=0; i<n; i++) cout << s[i] << t[i]; cout << endl; }
C - Snack
で割り切れる最小の数を出力すれば良いので,最小公倍数を求めます.
最小公倍数(LCM)は, ですね.
#include <iostream> #include <iomanip> #include <vector> #include <utility> #include <map> #include <algorithm> #include <queue> #include <cmath> #include <numeric> using namespace std; struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa; typedef long long int64; int64 gcd(int64 a,int64 b){return b?gcd(b,a%b):a;} int main() { int64 a,b; cin >> a >> b; int64 GCD = gcd(a,b); int64 ans = a*b/GCD; cout << ans << endl; }
D - Brick Break
順番に とならないといけないので,
が来るまでレンガを割り続ける, が来るまで…
とやっていけば良いです.
そして,1回も が出てこなければそういう列が作れません.
#include <iostream> #include <iomanip> #include <vector> #include <utility> #include <map> #include <algorithm> #include <queue> #include <cmath> #include <numeric> using namespace std; struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa; typedef long long int64; int main() { int64 n; cin >> n; vector<int64> a(n); for (int i=0; i<n; i++) cin >> a[i]; int64 ans = 0; bool flag = false; int64 i = 1; for (int j=0; j<n; j++) { if (a[j] != i) ans++; else i++,flag=true; } cout << (flag? ans : -1) << endl; }
E - Double Factorial /
考察不足でした.が何個あるか数えてたんですけど,
は大量にあるため, が何個あるか(入るか)数えるだけで良かったです.
(以下であることを避けるために最初だけで割ります)
#include <iostream> #include <iomanip> #include <vector> #include <utility> #include <map> #include <algorithm> #include <queue> #include <cmath> #include <numeric> using namespace std; struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa; typedef long long int64; int main() { int64 n; int64 ans = 0; cin >> n; if (n%2) { cout << 0 << endl; return 0; } ans += n /= 10; while(n != 0) { ans += n /= 5; } cout << ans << endl; return 0; }
まとめ
またレート下がりました_(:3」∠)_
E問題は「 の下桁に0はいくつ連続するか」という問題と本質的に同じ問題みたいです(↓参考).
中学受験とか高校受験にこんな問題出るんですか(無知).
こういう知識ないので,辛い_(:3」∠)_
参考
- AtCoder ABC 148 E - Double Factorial (500 点) - けんちょんの競プロ精進記録 http://drken1215.hatenablog.com/entry/2019/12/22/224100