Fading Coder

One Final Commit for the Last Sprint

Problems and Solutions from AtCoder Beginner Contest 053

A int N; std::cin >> N; std::cout << (N < 1200 ? "ABC" : "ARC") << "\n"; B Problem: Snuke wants to take a substring from ( s ) that starts with 'A' and ends with 'Z'. Given ( s ), find the length of the longest such substring. It is guaranteed that...

AtCoder Beginner Contest 009 Solutions

Problem A: Minimum Carry Operations Given n boxes where each trip can carry at most 2 boxes, the minimum number of trips required is ⌈n / 2⌉, which equals (n + 1) // 2 using integer division. Problem B: Second Largest Unique Value Given n integers with at least two distinct values, find the second l...

AtCoder ABC342 Problem A-D Solutions

Problem A A slightly trickier warm-up problem. #include <bits/stdc++.h> using namespace std; int main() { string str; cin >> str; unordered_map<char, int> charCount; for (char c : str) { charCount[c]++; } for (int idx = 0; idx < str.size(); idx++) { if (charCount[str[idx]] == 1)...

Solution to AtCoder Beginner Contest 446

D - Max Straight This problem can be solved efficient using a hash map. Initially, I overcomplicated it by thinking about sorting and finding the longest increasing subsequence. However, a simple approach using a map workss perfectly. #include <bits/stdc++.h> using namespace std; int main() {...

Computational Solutions for AtCoder Beginner Contest 006

Divisibility and Digit Extraction The objective is to determine if a given integer $N$ is either divisible by 3 or contains the digit '3'. A direct approach involves checking the modulo and then iteratively extracting digits. The time complexity for this is $O(\log_{10} N)$. bool is_lucky(long long...

AtCoder Beginner Contest 050 Problem Solutions

The input consists of an arithmetic expression in the form a + b or a - b. Parse the expression and output the computed result. int main() { int operand1, operand2; char operation; std::cin >> operand1 >> operation >> operand2; if (operation == '+') { std::cout << operand1 +...

Efficient Solutions for AtCoder Beginner Contest 353 Problems

Problem A: Building Height Comparison Given an array of building heights, find the first building taller than the first one. #include <cstdio> const int MAX_SIZE = 105; int heights[MAX_SIZE]; int main() { int n; scanf("%d", &n); int result = -1; for (int i = 1; i <= n; i++) {...

Algorithmic Solutions for AtCoder Beginner Contest 342

Problem A: Locating the Singleton Character Concept: Given a string containing exactly two distinct lowercase letters, identify the 1-based index of the letter that appears precisely once. Approach: Maintain frequency counters or index lists for each character. Since only two characters exist in the...

Solving AtCoder Beginner Contest 058 Problems

A — Checking a Beautiful Arrangement Three pillars stand equally spaced in a line. Their heights are (a), (b), (c) from left to right. The arrangement is beautiful if (b - a = c - b). Determine whether it qualifies. #include <iostream> int main() { int h1, h2, h3; std::cin >> h1 >>...

Solutions for Select Problems from AtCoder Beginner Contest 420

A - What month is it? A straightforward problem. The solution is to output ((x + y - 1) \mod 12 + 1). B - Most Mniority This problem can be solved with a brute-force approach. First, for each vote, count the number of votes for each option. Then, iterate through all participants and increment a coun...