ABC 344
Table of Contents
https://atcoder.jp/contests/abc344
A. Spoiler
https://atcoder.jp/contests/abc344/tasks/abc344_a
B. Delimiter
https://atcoder.jp/contests/abc344/tasks/abc344_b
C. A+B+C
https://atcoder.jp/contests/abc344/tasks/abc344_c
D. String Bags
https://atcoder.jp/contests/abc344/tasks/abc344_d
2026/1/17 解説 AC
問題文を読み間違えていた。何度も袋の中の文字列を出していいのだと思っていたが、$i$ の小さいものから順に1つまでしか取り出せなかった。
void solve() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
string T;
cin >> T;
ll N;
cin >> N;
T = "_" + T;
vll A(N);
vector S(N, vector<string>());
rep(i, N) {
ll a;
cin >> a;
A[i] = a;
rep(j, a) {
string s;
cin >> s;
S[i].push_back(s);
}
}
int tsz = T.size();
vll dp(tsz, INF);
dp[0] = 0;
rep(i, N) {
vll dpn(tsz + 1, INF);
rep(j, A[i]) {
string s = S[i][j];
rep(k, tsz) {
if (dp[k] != INF) {
if (T.substr(k + 1, s.size()) == s)
chmin(dpn[k + s.size()], dp[k] + 1);
chmin(dpn[k], dp[k]);
}
}
}
swap(dp, dpn);
}
ll ans = dp[tsz - 1];
if (ans == INF) ans = -1;
cout << ans << endl;
}
E. Insert or Erase
https://atcoder.jp/contests/abc344/tasks/abc344_e
2026/1/17 自力 AC
単に linked list を実装すれば良い
void solve() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ll N;
cin >> N;
vll A(N);
rep(i, N) cin >> A[i];
ll head = A[0];
unordered_map<ll, ll> to, pr;
rep(i, N - 1) {
to[A[i]] = A[i + 1];
}
for (int i = N - 1; i > 0; i--) {
pr[A[i]] = A[i - 1];
}
int Q;
cin >> Q;
rep(i, Q) {
int t;
cin >> t;
if (t == 1) {
ll x, y;
cin >> x >> y;
ll l = x, r = to[x];
to[l] = y;
to[y] = r;
pr[y] = x;
pr[r] = y;
} else {
ll x;
cin >> x;
if (x == head) {
head = to[x];
}
ll l = pr[x], r = to[x];
if (l != 0)
to[l] = r;
if (r != 0)
pr[r] = l;
}
}
vll ans;
ll now = head;
do {
ans.push_back(now);
now = to[now];
} while (now != 0);
print(ans);
}
F. Earn to Advance
https://atcoder.jp/contests/abc344/tasks/abc344_f