Codeforces Round 966 (Div. 3) Solutions
A. Primary Task
Approach
The string is invalid in the following cases:
Length ≤ 2.
Does not start with "10".
The substring after "10" converts to an integer less than 2, or has leading zeros.
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
void solve() {
string s;
cin >> s;
if ...
Posted on Tue, 12 May 2026 16:38:35 +0000 by Janjan
The Inclusion-Exclusion Principle: Applications in Competitive Programming
The Inclusion-Exclusion Principle
The Inclusion-Exclusion Principle is a fundamental concept in combinatorics that provides a method for calculating the size of the union of multiple sets. It addresses the problem of avoiding overcounting elements that belong to multiple sets by systematically accounting for intersections.
Codeforces 547C: Mi ...
Posted on Tue, 12 May 2026 15:12:06 +0000 by aouriques
Preliminary solutions for AtCoder Beginner Contest 064
Problem A: Check multiples of 4
Given three digits a, b, c (most significant first), form the three-digit number n = 100*a + 10*b + c. Determine whether n is divisible by 4.
int a, b, c; cin >> a >> b >> c;
int n = a * 100 + b * 10 + c;
cout << (n % 4 == 0 ? "YES" : "NO") << "\n";
Pro ...
Posted on Mon, 11 May 2026 07:02:20 +0000 by lostsoul111455
CCPC Qinhuangdao Contest: Problem Solutions and Code
Problem A. Is Your School the Kingdom of Construction I
Approach
The official solution provides a clear construction method. We need to generate exactly k coordinate pairs (x, y) where both coordinates are between 1 and n.
First, we construct a base set of edges forming a connected structure. Then, if additional pairs are needed, we fill in the ...
Posted on Sun, 10 May 2026 20:13:05 +0000 by ragefu
Codeforces Round 4 Challenges
Codeforces Round 4 Challenges
A-String Construction Challenge
Output several 'you' strings and fill the rest with arbitrary characters
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,m;
cin ...
Posted on Sun, 10 May 2026 20:01:07 +0000 by signs
Probability Calculation Strategy for Dice and Coin Scenarios
Problem Overview
This problem involves calculating the winning probability in a game defined by two random processes: an N-sided die and a fair coin. The objective is to reach a specific threshold K starting from a value generated by the die roll.
Game Mechanics
Initialization: Roll an N-sided die. The outcome serves as the initial score, rang ...
Posted on Sun, 10 May 2026 18:48:19 +0000 by Roggan
Implementing Balanced Trees: Rotational vs Non-rotational Treaps
P6136 Enhanced Balanced Tree Template
After struggling with rotational Treaps, I've concluded they're overly complex. FHQ Treaps offer a much cleaner implementation, with roughly half the code size.
Rotational Treap Implementation
Structure and data definitions:
const int INF=1e18;
struct TreeNode {
int left, right;
int value, priority; ...
Posted on Sun, 10 May 2026 18:15:42 +0000 by spaceknop
Solutions for ACGO Contest #13 Problems
T1 - Meteor Shower Era
Approach
Follow a direct simulation logic:
Determine the first year the observer sees a meteor: (E + B) % 50.
If this age exceeds the lifespan L, output 0.
Otherwise, calculate the remaining years L - first_year and divide by the cycle length 50, adding 1 for the first sighting.
C++ Implementation
#include <bits/stdc ...
Posted on Sun, 10 May 2026 10:38:42 +0000 by zzman
Competitive Programming Problem Solutions: Basic Algorithms and Data Structures
Problem 1: Character Output
Output each character of the string "I Love GPLT" on a separate line.
#include <iostream>
using namespace std;
int main() {
string msg = "I Love GPLT";
for (char c : msg) {
cout << c << '\n';
}
return 0;
}
Problem 2: Standard Weight Calculation
Given a ...
Posted on Sat, 09 May 2026 19:24:39 +0000 by AndyEarley
Implementing Prim's Algorithm for Minimum Spanning Trees with Road Construction Problem Solution
Prim's Algorithm for Minimum Spanning Trees
Prim's algorithm utilizes a distance array where dist[j] represents the shortest distance from node j to the current connected component. The process begins by selecting an arbitrary starting node and initializing distances to all other nodes.
Algorithm Steps:
Initialize all distances to infinity exc ...
Posted on Sat, 09 May 2026 19:21:43 +0000 by paulieo10