Skip to content

Commit 98df1ca

Browse files
committed
AtCoder & CodeForces solutions.
1 parent fc3350b commit 98df1ca

28 files changed

+1055
-1
lines changed

AtCoder/A_2_UP_3_DOWN.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define endl '\n'
4+
5+
using namespace std;
6+
7+
int main() {
8+
int X, Y;
9+
cin >> X >> Y;
10+
if ((Y > X && Y <= X + 2) || (Y < X && Y >= X - 3)) {
11+
cout << "Yes" << endl;
12+
} else {
13+
cout << "No" << endl;
14+
}
15+
return 0;
16+
}

AtCoder/A_Arithmetic_Progression.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define endl '\n'
4+
5+
using namespace std;
6+
7+
int main() {
8+
int A, B, D;
9+
cin >> A >> B >> D;
10+
while (A <= B) {
11+
cout << A << " ";
12+
A += D;
13+
}
14+
cout << endl;
15+
return 0;
16+
}

AtCoder/A_Capitalized.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define endl '\n'
4+
5+
using namespace std;
6+
7+
int main() {
8+
string S;
9+
cin >> S;
10+
bool ok = true;
11+
for (int i = 0; i < S.size(); i++) {
12+
if (i == 0) ok &= (S[i] >= 'A' && S[i] <= 'Z');
13+
else ok &= (S[i] >= 'a' && S[i] <= 'z');
14+
}
15+
cout << (ok ? "Yes" : "No") << endl;
16+
return 0;
17+
}

AtCoder/A_Scoreboard.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define endl '\n'
4+
5+
using namespace std;
6+
7+
int main() {
8+
int N;
9+
cin >> N;
10+
ll A = 0, B = 0;
11+
for (int i = 0; i < N; i++) {
12+
int x, y;
13+
cin >> x >> y;
14+
A += x;
15+
B += y;
16+
}
17+
if (A == B) {
18+
cout << "Draw" << endl;
19+
} else if (A > B) {
20+
cout << "Takahashi" << endl;
21+
} else {
22+
cout << "Aoki" << endl;
23+
}
24+
return 0;
25+
}

AtCoder/B_326_like_Numbers.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define endl '\n'
4+
5+
using namespace std;
6+
7+
int main() {
8+
int N;
9+
cin >> N;
10+
for (int i = N;; i++) {
11+
int d1 = i / 100;
12+
int d2 = i / 10 % 10;
13+
if ((i % 10) == d1 * d2) {
14+
cout << i << endl;
15+
return 0;
16+
}
17+
}
18+
return 0;
19+
}

AtCoder/B_Append.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define endl '\n'
4+
5+
using namespace std;
6+
7+
int main() {
8+
int Q;
9+
cin >> Q;
10+
vector<int> A;
11+
for (int i = 0; i < Q; i++) {
12+
int t, x;
13+
cin >> t >> x;
14+
if (t == 1) {
15+
A.push_back(x);
16+
} else {
17+
cout << A[A.size() - x] << endl;
18+
}
19+
}
20+
return 0;
21+
}

AtCoder/B_Extended_ABC.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define endl '\n'
4+
5+
using namespace std;
6+
7+
int main() {
8+
string S;
9+
cin >> S;
10+
char expect = 'A';
11+
bool ok = true;
12+
for (int i = 0; i < S.size(); i++) {
13+
ok &= (S[i] >= expect);
14+
expect = max(expect, S[i]);
15+
}
16+
cout << (ok ? "Yes" : "No") << endl;
17+
return 0;
18+
}

AtCoder/B_Frequency.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define endl '\n'
4+
5+
using namespace std;
6+
7+
int main() {
8+
vector<int> frq(26);
9+
string S;
10+
cin >> S;
11+
for (int i = 0; i < S.size(); i++) frq[S[i] - 'a']++;
12+
int f = 0;
13+
for (int i = 0; i < 26; i++) {
14+
if (frq[i] > frq[f]) {
15+
f = i;
16+
}
17+
}
18+
cout << (char)('a' + f) << endl;
19+
return 0;
20+
}

AtCoder/C_Divide_and_Divide.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define endl '\n'
4+
5+
using namespace std;
6+
7+
int main() {
8+
ll X;
9+
cin >> X;
10+
map<ll, ll> mp;
11+
mp[X] = 1;
12+
ll cost = 0;
13+
while (!mp.empty()) {
14+
map<ll, ll> new_mp;
15+
for (auto [v, frq]: mp) {
16+
cost += v * frq;
17+
ll nv1 = v / 2;
18+
ll nv2 = (v + 1) / 2;
19+
if (nv1 > 1) new_mp[nv1] += frq;
20+
if (nv2 > 1) new_mp[nv2] += frq;
21+
}
22+
mp.swap(new_mp);
23+
}
24+
cout << cost << endl;
25+
return 0;
26+
}

AtCoder/C_Leftover_Recipes.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define endl '\n'
4+
5+
using namespace std;
6+
7+
int main() {
8+
int N;
9+
cin >> N;
10+
vector<ll> Q(N), A(N), B(N);
11+
for (int i = 0; i < N; i++) cin >> Q[i];
12+
for (int i = 0; i < N; i++) cin >> A[i];
13+
for (int i = 0; i < N; i++) cin >> B[i];
14+
int ans = 0;
15+
for (ll a = 0; a < (ll)(1e6 + 100); a++) {
16+
bool failed = false;
17+
for (int i = 0; i < N; i++) {
18+
if (a * A[i] > Q[i]) {
19+
failed = true;
20+
break;
21+
}
22+
}
23+
if (failed) break;
24+
int mx = INT_MAX;
25+
for (int i = 0; i < N; i++) {
26+
int b_left = Q[i] - a * A[i];
27+
if (B[i] == 0) continue;
28+
if (b_left <= 0) mx = 0;
29+
else mx = min(mx, (int)(b_left / B[i]));
30+
}
31+
ans = max(ans, mx + (int)a);
32+
}
33+
cout << ans << endl;
34+
return 0;
35+
}

AtCoder/C_Lining_Up_2.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define endl '\n'
4+
5+
using namespace std;
6+
7+
int main() {
8+
int N;
9+
cin >> N;
10+
vector<int> A(N);
11+
for (int i = 0; i < N; i++) cin >> A[i];
12+
vector<int> rev(N);
13+
for (int i = 0; i < N; i++) {
14+
if (A[i] != -1) {
15+
rev[A[i]-1] = i;
16+
}
17+
}
18+
vector<int> ans;
19+
for (int i = 0; i < N; i++) {
20+
if (A[i] == -1) {
21+
for (int k = 0, ind = i; k < N; k++, ind = rev[ind]) {
22+
ans.push_back(ind + 1);
23+
}
24+
break;
25+
}
26+
}
27+
for (auto el: ans) cout << el << " ";
28+
cout << endl;
29+
return 0;
30+
}

AtCoder/C_Peak.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define endl '\n'
4+
5+
using namespace std;
6+
7+
int main() {
8+
int N, M;
9+
cin >> N >> M;
10+
vector<int> A(N);
11+
for (int i = 0; i < N; i++) cin >> A[i];
12+
sort(A.begin(), A.end());
13+
int p = 0;
14+
int ans = 0;
15+
for (int i = 0; i < N; i++) {
16+
while (p < A.size() && A[p] - A[i] < M) {
17+
p++;
18+
}
19+
20+
ans = max(ans, p - i);
21+
}
22+
cout << ans << endl;
23+
return 0;
24+
}

AtCoder/C_Target_Practice.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define endl '\n'
4+
5+
using namespace std;
6+
7+
void testCase() {
8+
vector<string> A(10);
9+
for (int i = 0; i < 10; i++) cin >> A[i];
10+
int ans = 0;
11+
for (int i = 0; i < 10; i++) {
12+
for (int j = 0; j < 10; j++) {
13+
if (A[i][j] == 'X') {
14+
ans += (min({
15+
i, j, 9-i, 9-j
16+
})) + 1;
17+
}
18+
}
19+
}
20+
cout << ans << endl;
21+
}
22+
23+
int main() {
24+
int t;
25+
cin >> t;
26+
27+
while (t--) {
28+
testCase();
29+
}
30+
31+
cout << flush;
32+
return 0;
33+
}

AtCoder/D_Cheating_Gomoku_Narabe.cpp

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define endl '\n'
4+
5+
using namespace std;
6+
7+
vector<string> rotate(const vector<string>& matrix, int x, int y) {
8+
vector<string> result(x, string(y, '.'));
9+
10+
int newColumn, newRow = 0;
11+
for (int oldColumn = x - 1; oldColumn >= 0; oldColumn--) {
12+
newColumn = 0;
13+
for (int oldRow = 0; oldRow < y; oldRow++) {
14+
result[newRow][newColumn] = matrix[oldRow][oldColumn];
15+
newColumn++;
16+
}
17+
newRow++;
18+
}
19+
20+
return result;
21+
}
22+
23+
int main() {
24+
int N, M, K;
25+
cin >> N >> M >> K;
26+
vector<string> A(N);
27+
for (int i = 0; i < N; i++) cin >> A[i];
28+
int ans = INT_MAX;
29+
for (int rep: { 0, 1 }) {
30+
if (K <= M) {
31+
for (int i = 0; i < N; i++) {
32+
int count = 0;
33+
int xs = 0;
34+
for (int j = 0; j < K; j++) {
35+
count += (A[i][j] == 'o');
36+
xs += (A[i][j] == 'x');
37+
}
38+
if (xs == 0) ans = min(ans, K - count);
39+
for (int jj = K; jj < M; jj++) {
40+
count -= (A[i][jj-K] == 'o');
41+
xs -= (A[i][jj-K] == 'x');
42+
count += (A[i][jj] == 'o');
43+
xs += (A[i][jj] == 'x');
44+
if (xs == 0) ans = min(ans, K - count);
45+
}
46+
}
47+
48+
if (rep == 1) {
49+
break;
50+
}
51+
}
52+
53+
A = rotate(A, M, N);
54+
swap(M, N);
55+
}
56+
cout << (ans == INT_MAX ? -1 : ans) << endl;
57+
return 0;
58+
}

0 commit comments

Comments
 (0)