AtCoderで入茶を目指して勉強しています。
勉強を継続するために投稿を始めました。
もともとアカウントを作成していましたが、今年の4月から本格的に勉強を始めました。
一応自分用に解法を書いていますが雑です、自分で読み返して困ったら修正します。
私のアカウント
解いた問題
本日解いた問題
本日はAtCoder Beginner Contest 363
に参加した。今回のコンテストではC問題まで解くことができ、さらにD問題に取り組むことができた。また、初めて緑パフォーマンスを出せた。
A - Piling Up
#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
using vec = vector<ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
ll n;
cin >> n;
if(n < 100) cout << 100 - n << endl;
else if(100 <= n && n < 200) cout << 200 - n << endl;
else if(200 <= n && n < 300) cout << 300 - n << endl;
}
解法
100未満、100以上200未満、200以上300未満の場合に分けて処理することで結果が求まる。
B - Japanese Cursed Doll
#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
using vec = vector<ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
ll n, t, p;
cin >> n >> t >> p;
vec l(n);
rep(i, n) cin >> l[i];
ll res = 0;
while(1){
ll cnt = 0;
for(int i = 0; i < n; i++){
if(l[i] >= t) cnt++;
l[i]++;
}
if(cnt >= p) break;
res++;
}
cout << res << endl;
}
解法
1日ごとに髪の毛の長さがT
以上の人数と日数をカウントして、人数がP
以上になったときにループを抜ける。その際の日数を出力する。
C - Avoid K Palindrome 2
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
ll n, k;
cin >> n >> k;
string s;
cin >> s;
ll cnt = 0;
ll res = 0;
sort(s.begin(), s.end());
do {
for(int i = 0; i <= n-k; i++){
bool jud = true;
for(int j = 0; j < k; j++){
if(s[i+j] != s[i+k-1-j]) jud = false;
}
if(jud) {
cnt++;
break;
}
}
res++;
} while (next_permutation(s.begin(), s.end()));
cout << res - cnt << endl;
}
解法
この問題では文字列S
を並び替えてえられる文字列を順列全探索で求める。並び替えた文字列に対して、長さK
の部分文字列が回文かどうかを判定して、回文の場合をカウントしておく。その後、並び替えたすべての文字列の数から回文を含む数を引くことで結果が求まる。