π§© AtCoder Beginner Contest 388
January 11, 2025About 2 min
π§© AtCoder Beginner Contest 388
# Info & Summary
- Date:
2025-01-11
- Completion Status: A β / B β / C β / D β / E β / F β / G β
- Problem Type:
Problem | Type(s) | Data Structure / Algo | π₯ Key Insight / Mark |
---|---|---|---|
D | Simulation | Range Update/Prefix Sum | βπ§ π₯ |
E | Simulation | Math | π§ |
F | Matrix | Matrix | π |
G | Range Minimum Query (RMQ) | RMQ/Two-pointer/Binary Search | π |
Details
Emoji | Label | Meaning |
---|---|---|
β | Important | Problem is strategically useful or has reusable patterns |
π₯ | Must master | Classic problem or technique that appears often and is worth mastering |
β οΈ | Reattempt | You attempted but failed; worth reviewing and solving again |
π§ | New to me | Introduced a new idea, technique, or pattern you hadnβt seen before |
π οΈ | Template | You built or improved a code template from solving this problem |
π | Too hard now | Beyond current ability to understand/solve; revisit after more practice |
π A - ?UPC

#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s;
cin >> s;
cout << s[0] << "UPC" << endl;
return 0;
}
π B - Heavy Snake

#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, D;
cin >> N >> D;
vector<int> T(N), L(N);
for (int i = 0; i < N; i++)
{
cin >> T[i] >> L[i];
}
for (int d = 1; d <= D; d++)
{
int ans = 0;
for (int i = 0; i < N; i++)
{
int cur = (L[i] + d) * T[i];
ans = max(ans, cur);
}
cout << ans << endl;
}
return 0;
}
π C - Various Kagamimochi

#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++)
{
cin >> A[i];
}
long long ans = 0;
for (auto a : A)
{
ans += upper_bound(A.begin(), A.end(), a / 2) - A.begin();
}
cout << ans << endl;
return 0;
}
π D - Coming of Age Celebration

Tips
By focusing not on receiving but on giving stones, we can find the correct answer by interpreting the problem as follows:
- Alien has stones and will become an adult years later
- Alien gives each of aliens a stone(if he has one) in this order when he becomes an adult
- How many stones will they finally have?
Let sequence of length be the total number of stones that alien will recive
Suppose that alien will give aliens after becoming an adult. Here, we want to add to for each , but naively doing so costs a total time complexity of . Instead we use the cumulative sum trick to optimize it
Let sequence of length be the differential sequence of , initially filled with :
- For each , do the following:
- if , let be . This determines the number of stones when alien becomes an adult, yielding
- Add to and to
This procedure can be done in a total of time
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++)
{
cin >> A[i];
}
vector<int> C(N), D(N + 1);
for (int i = 0; i < N; i++)
{
if (i != 0)
{
C[i] = C[i - 1] + D[i];
A[i] += C[i];
}
int cnt = min(N - i - 1, A[i]);
A[i] -= cnt;
D[i + 1] += 1;
D[min(N, i + cnt + 1)] -= 1;
}
for (int i = 0; i < N; i++)
{
cout << A[i] << " \n"[i == N - 1];
}
return 0;
}
π E - Simultaneous Kagamimochi

#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
deque<int> q;
for (int i = 0; i < N / 2; i++)
{
int a;
cin >> a;
q.push_back(a);
}
long long ans = 0;
for (int i = N / 2; i < N; i++)
{
int a;
cin >> a;
if (q.front() * 2 <= a)
{
ans++;
q.pop_front();
}
}
cout << ans << endl;
return 0;
}
π F - Dangerous Sugoroku

Warning
Hard Problems to Tackle Later
// TODO
π G - Simultaneous Kagamimochi 2

Warning
Hard Problems to Tackle Later
// TODO