Translation Notice
This article was machine-translated using DeepSeek-R1.
- Original Version: Authored in Chinese by myself
- Accuracy Advisory: Potential discrepancies may exist between translations
- Precedence: The Chinese text shall prevail in case of ambiguity
- Feedback: Technical suggestions regarding translation quality are welcomed
Foreword
- This is my first time writing solutions for 7 problems (A~G) in an ABC contest. If there are any shortcomings or areas needing improvement, please feel free to provide feedback. Your support is greatly appreciated!
A - ASCII code
Problem Statement
Given a positive integer , output the character whose ASCII code is .
Input Format
Output Format
Print the character corresponding to ASCII code .
Analysis
Note a
corresponds to 97, b
to 98, …, z
to 122. Beginner conversion examples:
- C
1 2
int n = 97; putchar(n); /* Output: a */
putchar
automatically converts to character.printf("%c", n)
works similarly. - C++
Direct
1 2
int n = 97; cout << char(n) << endl; // Output: a
cout << n
outputs97
, requireschar
conversion. - Python
Requires
1 2
n = 97 print(chr(n)) # Output: a
chr
conversion. - Java
Casting required.
1 2 3
int n = 97; char c = (char) n; System.out.print(c);
- JavaScript
Uses
1 2 3
var n = 97; var c = String.fromCharCode(n); console.log(c); // Output: a
String.fromCharCode
.
Need more examples?
Code
Straightforward Python (AC in 25s):
|
|
B - Takahashi’s Failure
Problem Statement
Takahashi’s house has foods. The -th food has deliciousness .
He dislikes foods: .
Takahashi will randomly select a food with maximum deliciousness and eat it.
Is it possible for him to eat a disliked food?
Input Format
Output Format
Print Yes
if possible, No
otherwise.
Analysis
Check if any disliked food has maximum deliciousness. See code.
Code
Note convert to 0-indexed for :
|
|
C - Slot Strategy
Problem Statement
Refer to AtCoder.
Input Format
Output Format
Print the answer.
Analysis
Let be the count of . Compute cost for each target digit. See code.
Code
|
|
D - Distinct Trio
Problem Statement
Given integer sequence , count triples where:
Input Format
Output Format
Print the count.
Analysis
Approach:
- Total triples minus invalid ones.
- For each in :
- Subtract for pairs (x,x,y)
- Subtract for triples (x,x,x)
Time:
Code
|
|
E - Road Reduction
Problem Statement
Given undirected graph with nodes and edges. Find a spanning tree minimizing the sum of distances from node 1 to all others.
Input Format
Output Format
Print indices of edges in the tree.
Analysis
Optimal tree preserves shortest paths from node 1. Use Dijkstra’s algorithm and track edges.
Code
- Priority queue (182ms):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#include <cstdio> #include <queue> #define maxn 200005 #define INF 9223372036854775807LL using namespace std; using LL = long long; using pli = pair<LL, int>; struct Edge { int v, id; LL d; inline Edge(int u, int l, int i): v(u), d(l), id(i) {} }; vector<Edge> G[maxn]; LL dis[maxn]; int ans[maxn]; int main() { int n, m; scanf("%d%d", &n, &m); for(int i=1; i<=m; i++) { int a, b, c; scanf("%d%d%d", &a, &b, &c); G[--a].emplace_back(--b, c, i); G[b].emplace_back(a, c, i); } priority_queue<pli, vector<pli>, greater<pli>> q; for(int i=1; i<n; i++) dis[i] = INF; q.emplace(0LL, 0); while(!q.empty()) { auto [d, v] = q.top(); q.pop(); if(dis[v] == d) for(const Edge& e: G[v]) { LL nd = d + e.d; if(nd < dis[e.v]) q.emplace(dis[e.v] = nd, e.v), ans[e.v] = e.id; } } for(int i=1; i<n; i++) printf("%d ", ans[i]); return 0; }
- Set (202ms):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#include <cstdio> #include <vector> #include <set> #define maxn 200005 #define INF 9223372036854775807LL using namespace std; using LL = long long; using pli = pair<LL, int>; struct Edge { int v, id; LL d; inline Edge(int u, int l, int i): v(u), d(l), id(i) {} }; vector<Edge> G[maxn]; LL dis[maxn]; int ans[maxn]; int main() { int n, m; scanf("%d%d", &n, &m); for(int i=1; i<=m; i++) { int a, b, c; scanf("%d%d%d", &a, &b, &c); G[--a].emplace_back(--b, c, i); G[b].emplace_back(a, c, i); } set<pli> s; // <distance, vertex> for(int i=1; i<n; i++) dis[i] = INF; s.emplace(0LL, 0); while(!s.empty()) { auto [d, v] = *s.begin(); s.erase(s.begin()); for(const Edge& e: G[v]) { LL nd = d + e.d; if(nd < dis[e.v]) { if(dis[e.v] < INF) s.erase(pli(dis[e.v], e.v)); s.emplace(dis[e.v] = nd, e.v); ans[e.v] = e.id; } } } for(int i=1; i<n; i++) printf("%d ", ans[i]); return 0; }
F - Bread
Problem Statement
Given initial loaf of length , split into parts including all elements of array . Each split of costs . Find minimum total cost.
Input Format
Output Format
Print the minimal cost.
Analysis
Merge all elements (plus remaining if needed) using a min-heap. Always merge smallest two elements.
Code
|
|
G - Pre-Order
Problem Statement
Count valid rooted trees with given pre-order traversal , where children are visited in ascending order. Modulo 998244353.
is permutation.
Input Format
Output Format
Print the count modulo 998244353.
Analysis
Let be the count for subarray . Transition:
- if
Code
- Version 1 (59ms):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#include <cstdio> #define MOD 998244353 #define maxn 505 using namespace std; using LL = long long; int p[maxn], dp[maxn][maxn]; int main() { int n; scanf("%d", &n); for(int i=0; i<n; i++) scanf("%d", p + i); for(int l=n; l>0; l--) { dp[l][l] = 1; for(int r=l+1; r<=n; r++) { dp[l][r] = dp[l + 1][r]; for(int k=l+1; k<r; k++) if(p[l] < p[k] && (dp[l][r] += LL(dp[l + 1][k]) * dp[k][r] % MOD) >= MOD) dp[l][r] -= MOD; } } printf("%d\n", dp[1][n]); return 0; }
- Version 2 (66ms):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#include <cstdio> #define MOD 998244353 #define maxn 505 using namespace std; using LL = long long; int p[maxn], dp[maxn][maxn]; int main() { int n; scanf("%d", &n); for(int i=0; i<n; i++) scanf("%d", p + i); for(int i=1; i<=n; i++) dp[i][i] = 1; for(int d=1; d<=n; d++) for(int l=1, r=d+1; r<=n; l++, r++) { dp[l][r] = dp[l + 1][r]; for(int k=l+1; k<r; k++) if(p[l] < p[k] && (dp[l][r] += LL(dp[l + 1][k]) * dp[k][r] % MOD) >= MOD) dp[l][r] -= MOD; } printf("%d\n", dp[1][n]); return 0; }