AtCoder Regular Contest 094 - Problem-Solving Report
Honestly, this is absolutely the trashiest ARC set I’ve ever done, bar none.
D - Worst Case
This problem is a bit like one I did on Codeforces before, but it seems it isn’t the same, so I got stuck on it for ages.
First consider a few special cases. Let’s first assume \(A < B\):
- \(A = B\): the answer is just \(2(A - 1)\), nothing much to say.
- \(A = B - 1\): here the answer is also \(2(A - 1)\), nothing much to say.
After that we consider the case \(A < B - 1\). First, their product in the end is \(A\times B\). We need to count exactly how many \((x, y), x \times y < A \times B\) there are. Actually, having thought this far, you can try to find a \(C\) such that \(C^2 < AB\). At this point there will generally be the situation \(A < C < B\). If \(C(C + 1) < AB\), then the answer is \(2C - 1\); otherwise it is \(2C - 2\).
Notice that \(C(C + 1)\) is actually a solution, so let’s first think about why the answer is \(2C - 2\). Consider constructing \((1, A + B - 1), (2, A + B), \dots, (A - 1, B + 1), (A + 1, 2C - A - 1), \dots, (C, C), \dots (2C, 1)\).
// ARC094B.cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll Q, n = 1e12, a, b;
int main()
{
scanf("%lld", &Q);
while (Q--)
{
scanf("%lld%lld", &a, &b);
if (a > b)
swap(a, b);
ll ans = 0;
if (a == b || a + 1 == b)
ans += 2LL * a - 2;
else
{
ll C = sqrt(1LL * a * b) - 1;
while ((C + 1) * (C + 1) < 1LL * a * b)
C++;
if (C * (C + 1) >= 1LL * a * b)
ans = 2LL * C - 2;
else
ans = 2LL * C - 1;
}
printf("%lld\n", ans);
}
return 0;
}
E - Tozan and Gezan
Tozan can just move however he pleases, and Gezan can’t hold him back in any effective way. The final situation will always be \(0, 0, 0, 0, \dots, b_i, 0, \dots\). So in the end the Candy count will definitely include all of the \(a_i\), except for the \(b_i\) in the middle. This \(b_i\) takes the minimum over the cases where \(a_i > b_i\), because only that case can show up in the final state.
// ARC094C.cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5 + 200;
typedef pair<int, int> pii;
int n, ai[MAX_N], bi[MAX_N];
priority_queue<pii> pq1;
multiset<pii> pq2;
int main()
{
scanf("%d", &n);
long long ans = 0, acc = 1LL << 30;
bool flag = true;
for (int i = 1; i <= n; i++)
{
scanf("%d%d", &ai[i], &bi[i]);
flag &= (ai[i] == bi[i]), ans += ai[i];
if (ai[i] > bi[i])
acc = min(acc, 1LL * bi[i]);
}
if (flag)
puts("0");
else
printf("%lld\n", ans - acc);
return 0;
}
F - Normalization
It’s this very problem that made the whole set so rotten (
I thought about it forever, went to look at a solution, and in the end it turned out to be an observation problem, with no proof whatsoever (a Four Color Theorem–style proof). I am so done.
// ARC094D.cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5 + 200, mod = 998244353;
int n, dp[MAX_N][3][3][2], str[MAX_N];
char org[MAX_N];
int main()
{
scanf("%s", org + 1), n = strlen(org + 1);
int oddity = 0, tot[3] = {0, 0, 0};
bool flag = true;
for (int i = 1; i <= n; i++)
str[i] = org[i] - 'a', oddity = (oddity + str[i]) % 3, tot[str[i]]++;
for (int i = 1; i < n; i++)
flag &= (str[i] != str[i + 1]);
if (tot[0] == n || tot[1] == n || tot[2] == n)
puts("1"), exit(0);
if (n <= 3)
{
map<string, bool> mp;
string org_str = org + 1;
mp[org_str] = true;
int delta = 0;
do
{
delta = 0;
for (auto x : mp)
for (int i = 0; i < n - 1; i++)
if (x.first[i] != x.first[i + 1])
{
string nxt = x.first;
nxt[i] = nxt[i + 1] = ('a' ^ 'b' ^ 'c') ^ (x.first[i] ^ x.first[i + 1]);
if (mp[nxt] == false)
mp[nxt] = true, delta++;
}
} while (delta);
printf("%lld\n", 1LL * mp.size());
}
else
{
int ans = (flag == true);
dp[1][0][0][0] = dp[1][1][1][0] = dp[1][2][2][0] = 1;
for (int i = 2; i <= n; i++)
for (int sum = 0; sum < 3; sum++)
for (int pre = 0; pre < 3; pre++)
for (int curt = 0; curt < 3; curt++)
if (pre == curt)
dp[i][(sum + curt) % 3][curt][1] = (0LL + dp[i][(sum + curt) % 3][curt][1] + dp[i - 1][sum][pre][0] + dp[i - 1][sum][pre][1]) % mod;
else
{
dp[i][(sum + curt) % 3][curt][0] = (0LL + dp[i][(sum + curt) % 3][curt][0] + dp[i - 1][sum][pre][0]) % mod;
dp[i][(sum + curt) % 3][curt][1] = (0LL + dp[i][(sum + curt) % 3][curt][1] + dp[i - 1][sum][pre][1]) % mod;
}
for (int i = 0; i < 3; i++)
ans = (0LL + ans + dp[n][oddity][i][1]) % mod;
printf("%d\n", ans);
}
return 0;
}