AtCoder422の感想と自分が解いたところまでの解説を書いていきます
(今回は全部pythonでも書きます)
AtCoder Beginner Contest 422
1.感想
A問題:
簡単(1分以内で解けた)
B問題:
簡単だったが範囲外アクセスをしてREを出してしまった
(最近B問題は簡単なところでミスしている気がする)
C問題:
プログラムを書くまでが大変
公式的なものを見つけたら簡単だった
2.結果
3.解説
A問題 Stage Clear
C++での実装
#include <bits/stdc++.h>
using namespace std;
int main(){
string S;
cin >> S;
if (S[2] == '8'){
S[2] = '1';
S[0]++;
}
else{
S[2]++;
}
cout << S << endl;
return 0;
}
pythonでの実装
S = list(input())
if S[2] == '8':
S[0] = str(int(S[0])+1)
S[2] = '1'
else:
S[2] = str(int(S[2])+1)
print(f"{S[0]}{S[1]}{S[2]}")
B問題 Looped Rope
C++での実装
#include <bits/stdc++.h>
using namespace std;
int main(){
int H, W, sub;
cin >> H >> W;
string S[H];
for (string &i : S) cin >> i;
for (int i = 0; i < H; i++){
for (int j = 0; j < W; j++){
if (S[i][j] != '#') continue;
sub = 0;
if (i != 0 && S[i-1][j] == '#') sub++;
if (i != H-1 && S[i+1][j] == '#') sub++;
if (j != 0 && S[i][j-1] == '#') sub++;
if (j != W-1 && S[i][j+1] == '#') sub++;
if (sub == 0 || sub == 1 || sub == 3){
puts("No");
return 0;
}
}
}
puts("Yes");
return 0;
}
pythonでの実装
H, W = map(int, input().split())
S = [list(input()) for i in range(H)]
ans = True
for i in range(H):
for j in range(W):
if S[i][j] != '#':
continue
count = 0
if i != 0 and S[i-1][j] == '#':
count += 1
if i != H-1 and S[i+1][j] == '#':
count += 1
if j != 0 and S[i][j-1] == '#':
count += 1
if j != W-1 and S[i][j+1] == '#':
count += 1
if count == 0 or count == 1 or count == 3:
ans = False
break
print("Yes" if ans else "No")
C問題 AtCoder AAC Contest
C++での実装
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
int T;
cin >> T;
for (int i = 0; i < T; i++){
ll A, B, C;
cin >> A >> B >> C;
ll ans = min({A, C, (A+B+C)/3});
cout << ans << endl;
}
return 0;
}
pythonでの実装
T = int(input())
for i in range(T):
A, B, C = map(int, input().split())
print(min(A, C, (A+B+C)//3))