π§© AtCoder Beginner Contest 407
May 24, 2025About 2 min
π§© AtCoder Beginner Contest 407
# Info & Summary
- Date:
2025-05-24
- Completion Status: A β / B β / C β / D β / E β / F β / G β
- Problem Type:
Problem | Type(s) | Data Structure / Algo | π₯ Key Insight / Mark |
---|---|---|---|
C | Simulation | Math | βπ§ π₯ |
D | bitmask, DP | Bitmask DP | βπ§ π₯ |
E | Constructive | Constructive | π |
F | Math | π | |
G | Graph | π |
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 - Approximation

#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
double A, B;
cin >> A >> B;
int ans = (A * 2 + B) / (2 * B);
cout << ans << endl;
return 0;
}
π B - P(X or Y)

#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int X, Y;
cin >> X >> Y;
double ans = 0.0;
for (int i = 1; i <= 6; i++)
{
for (int j = 1; j <= 6; j++)
{
if (i + j >= X || abs(i - j) >= Y)
{
ans += (1.0 / 36.0);
}
}
}
cout << fixed << setprecision(15) << ans << endl;
return 0;
}
π C - Security 2

Tips
For each , after pressing button A
for the -th time before pressing it next time, suppose that button B
is pressed () times
Then, the -th character of ends up being if and only if
For , we obviously know , so we consider
By applying the equation for the -th character, we obtain:
Subtracting this from equation above, we obtain:
Such an integer with is uniquely determined as:
Hence, the answer is the sum of over , plus
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
string S;
cin >> S;
long long ans = S.size();
for (int i = S.size() - 1; i >= 0; i--)
{
// S_j
int v = S[i] - '0';
// S_{j + 1}
int u = ((i < S.size() - 1) ? S[i + 1] - '0' : 0);
ans += (10 + v - u) % 10;
}
cout << ans << endl;
return 0;
}
π D - Domino Covering XOR

#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int H, W;
cin >> H >> W;
// Flatten the H Γ W grid into a 1D vector grid of size H * W
vector<long long> grid(H * W);
for (int i = 0; i < H * W; i++)
{
cin >> grid[i];
}
long long ans = 0;
// p: current cell index in 1D (from 0 to H*W-1)
// mark: a bitmask (integer) that tracks which cells are already covered by a domino
// cur: current XOR of uncovered cells
auto dfs = [&](auto &&self, int p, int mask, long long cur) -> void
{
// If we have processed all positions, update the global max answer
if (p == H * W)
{
ans = max(ans, cur);
return;
}
// If current cell is already covered, skip it
if (mask & (1 << p))
{
self(self, p + 1, mask, cur);
return;
}
// Option 1: Choose to leave cell p uncovered
self(self, p + 1, mask, cur ^ grid[p]);
// Option 2: Try placing a horizontal domino
if ((p % W) < W - 1 && !(mask & (1 << (p + 1))))
{
int temp = (1 << p) | (1 << (p + 1));
self(self, p + 1, mask | temp, cur);
}
// Option 3: Try placing a vertical domino
if ((p + W) < H * W && !(mask & (1 << (p + W))))
{
int temp = (1 << p) | (1 << (p + W));
self(self, p + 1, mask | temp, cur);
}
};
dfs(dfs, 0, 0, 0);
cout << ans << endl;
return 0;
}
π E - Most Valuable Parentheses

Warning
Hard Problems to Tackle Later
// TODO
π F - Sums of Sliding Window Maximum

Warning
Hard Problems to Tackle Later
// TODO
π G - Domino Covering SUM

Warning
Hard Problems to Tackle Later
// TODO