Dataset Viewer
Auto-converted to Parquet Duplicate
problem_id
stringlengths
4
4
problem_description
stringlengths
5
7.37k
c_code
stringlengths
87
16.5k
rust_code
stringlengths
101
4.89k
difficulty
stringclasses
3 values
0001
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi is going to set a <var>3</var>-character password.</p> <p>How many possible passwords are there if each of its characters must be a digit between <var>1</var> and <var>N</var> (inclusive)?</p>...
int solution() { int N = 0; scanf("%d", &N); printf("%d\n", N * N * N); return 0; }
fn solution() { let mut input = String::new(); io::stdin() .read_line(&mut input) .expect("failed to get input"); let input: u32 = input.trim().parse().expect("failed to parse to u32"); println!("{}", input * input * input); }
medium
0002
You are given four integers $$$a$$$, $$$b$$$, $$$x$$$ and $$$y$$$. Initially, $$$a \ge x$$$ and $$$b \ge y$$$. You can do the following operation no more than $$$n$$$ times: Choose either $$$a$$$ or $$$b$$$ and decrease it by one. However, as a result of this operation, value of $$$a$$$ cannot become less than $$$x$$$...
int solution() { unsigned long long int a; unsigned long long int b; unsigned long long int x; unsigned long long int y; unsigned long long int n; unsigned long long int t; unsigned counter0 = 0; scanf("%llu", &t); unsigned long long int arr[t]; while (counter0 < t) { scanf("%llu%llu%llu%llu%llu...
fn solution() { let t: usize = { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); buf.trim_end().parse().unwrap() }; let mut ans = Vec::with_capacity(t); for _ in 0..t { let (a, b, x, y, n): (i64, i64, i64, i64, i64) = { let mut buf...
easy
0003
You are given an array $$$a$$$ consisting of $$$n$$$ integer numbers.Let instability of the array be the following value: $$$\max\limits_{i = 1}^{n} a_i - \min\limits_{i = 1}^{n} a_i$$$.You have to remove exactly one element from this array to minimize instability of the resulting $$$(n-1)$$$-elements array. Your task ...
int solution(void) { int n = 0; scanf("%d\n", &n); if (n == 2) { printf("0\n"); return 0; } int arr[n]; for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); } int min1 = 1e9; int min2 = 1e9; int max1 = -1; int max2 = -1; for (int j = 0; j < n; j++) { if (min1 > arr[j]) { ...
fn solution() { let mut buf = String::new(); stdin().read_to_string(&mut buf).unwrap(); let mut tok = buf.split_whitespace(); let mut get = || tok.next().unwrap(); let n = get!(usize); if n == 2 { println!("0"); return; } let mut xs = vec![]; for _ in 0..n { ...
medium
0004
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi is competing in a sumo tournament. The tournament lasts for <var>15</var> days, during which he performs in one match per day. If he wins <var>8</var> or more matches, he can also participate ...
int solution(void) { int cnt = 15; int s = 0; char i; char *mes = "YES"; while (1) { scanf("%c", &i); if (i == '\n') { break; } if (i == 'o') { s++; } cnt--; } if (cnt + s < 8) { mes = "NO"; } printf("%s\n", mes); }
fn solution() { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); let chars: Vec<char> = buf.trim().chars().collect(); let mut lose_cnt = 0; for c in chars.iter() { if *c == 'x' { lose_cnt += 1; } } println!("{}", if lose_cnt >= 8 { "NO...
medium
0005
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Ringo is giving a present to Snuke.</p> <p>Ringo has found out that Snuke loves <em>yakiniku</em> (a Japanese term meaning grilled meat. <em>yaki</em>: grilled, <em>niku</em>: meat). He supposes that Sn...
int solution(void) { char po[114]; scanf("%s", po); if (strlen(po) >= 4 && po[0] == 'Y' && po[1] == 'A' && po[2] == 'K' && po[3] == 'I') { printf("Yes"); } else { printf("No"); } return 0; }
fn solution() { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); if s.chars().take(4).collect::<String>() == "YAKI" { println!("Yes"); } else { println!("No"); } }
medium
0006
You are given an array $$$a[0 \dots n-1]$$$ of $$$n$$$ integers. This array is called a "valley" if there exists exactly one subarray $$$a[l \dots r]$$$ such that: $$$0 \le l \le r \le n-1$$$, $$$a_l = a_{l+1} = a_{l+2} = \dots = a_r$$$, $$$l = 0$$$ or $$$a_{l-1} &gt; a_{l}$$$, $$$r = n-1$$$ or $$$a_r &lt; a_{r+1}$...
int solution() { int s; scanf("%d", &s); while (s--) { int n; scanf("%d", &n); int a[200001]; int i = 0; int h = 0; for (i = 0; i < n; i++) { scanf("%d", &a[i]); if (h != 2 && i != 0 && a[i] > a[i - 1]) { h = 1; } if (h == 1 && a[i] < a[i - 1]) { h =...
fn solution() { let (stdin, stdout) = (io::stdin(), io::stdout()); let mut scan = Scanner::new(stdin.lock()); let mut out = io::BufWriter::new(stdout.lock()); let t = scan.token::<usize>(); for _k in 0..t { let n = scan.token::<usize>(); let mut A = vec![]; for _i in 0..n ...
medium
0007
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Hearing that energy drinks increase rating in those sites, Takahashi decides to buy up <var>M</var> cans of energy drinks.</p> <p>There are <var>N</var> stores that sell energy drinks. In the <var>i</va...
int solution(void) { long long int n; long long int m; long long int i; long long int kei = 0; long long int a[100000]; long long int b[100000]; scanf("%lld %lld", &n, &m); for (i = 0; i < n; i++) { scanf("%lld %lld", &a[i], &b[i]); } int j; int increment; int temp; int temp_b; incremen...
fn solution() { let mut nm = String::new(); stdin().read_line(&mut nm).unwrap(); let nm: Vec<usize> = nm.split_whitespace().flat_map(str::parse).collect(); let (n, m) = (nm[0], nm[1]); let mut stores: Vec<(usize, usize)> = (0..n) .map(|_| { let mut a = String::new(); ...
hard
0008
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has bee...
int solution() { int t; scanf("%d", &t); int n; int i; int j; int b; int max; int a[102]; for (; t > 0; t--) { scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &a[i]); } max = 0; for (i = 0; i < n; i++) { if (a[i] > a[max]) { max = i; } } a[m...
fn solution() { let t: usize = { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); buf.trim_end().parse().unwrap() }; for _ in 0..t { let _n: usize = { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(...
easy
0009
Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg...
int solution() { long n; long m = 1000000000; long k; long long t = 0; int c = 0; scanf("%ld %ld", &n, &k); long a[n]; long r[n]; for (long i = 0; i < n; i++) { scanf("%ld", &a[i]); if (a[i] < m) { m = a[i]; } } for (long i = 0; i < n; i++) { r[i] = a[i] - m; if (r[i] % k...
fn solution() { let mut line = String::new(); io::stdin().read_line(&mut line).expect("read error"); let tmp: Vec<&str> = line.split_whitespace().collect(); let _n = tmp[0].parse::<i32>().expect("parse error"); let k = tmp[1].parse::<i32>().expect("parse error"); let mut line2 = String::new(...
easy
0010
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>For an integer <var>N</var>, we will choose a permutation <var>\{P_1, P_2, ..., P_N\}</var> of <var>\{1, 2, ..., N\}</var>.</p> <p>Then, for each <var>i=1,2,...,N</var>, let <var>M_i</var> be the remain...
int solution() { long long n = 0; long long result = 0; scanf("%lld", &n); result = n * (n - 1) / 2; printf("%lld", result); return 0; }
fn solution() { let stdin = io::stdin(); let mut input = String::new(); stdin.lock().read_line(&mut input).expect("read line!"); let input: String = input; let n: u64 = input.trim().parse().unwrap(); println!("{}", (n * (n - 1)) / 2); }
easy
0011
Okabe and Super Hacker Daru are stacking and removing boxes. There are n boxes numbered from 1 to n. Initially there are no boxes on the stack.Okabe, being a control freak, gives Daru 2n commands: n of which are to add a box to the top of the stack, and n of which are to remove a box from the top of the stack and throw...
int solution(void) { int n = 0; int num = 0; int cnt = 0; int top = -1; int target = 1; char cmd[20] = { 0, }; int stack[300001] = { 0, }; scanf("%d", &n); n *= 2; while (n--) { scanf("%s", cmd); if (cmd[0] == 'a') { scanf("%d", &num); stack[++top] = num; } ...
fn solution() { let mut n = String::new(); stdin().read_line(&mut n).unwrap(); let n = n.trim().parse::<u32>().unwrap(); let mut stack: Vec<u32> = Vec::with_capacity(n as usize); let mut ans = 0; let mut counter = 1; for _ in 0..(2 * n) { let mut input = String::new(); stdi...
hard
0012
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> apple trees in a row. People say that one of them will bear golden apples.</p> <p>We want to deploy some number of inspectors so that each of these trees will be inspected.</p> <p...
int solution() { int N = 0; int D = 0; int c = 0; scanf("%d %d", &N, &D); while (N > 0) { N = N - (2 * D + 1); c++; } printf("%d\n", c); return 0; }
fn solution() { let mut nd = String::new(); stdin().read_line(&mut nd).unwrap(); let nd: Vec<usize> = nd.split_whitespace().flat_map(str::parse).collect(); let (n, d) = (nd[0], nd[1]); println!( "{}", (n / (2 * d + 1)) + if n % (2 * d + 1) > 0 { 1 } else { 0 } ); }
medium
0013
<H1>Naive String Search</H1> <p> Find places where a string <var>P</var> is found within a text <var>T</var>. Print all indices of <var>T</var> where <var>P</var> found. The indices of <var>T</var> start with 0. </p> <H2>Input</H2> <p> In the first line, a text <var>T</var> is given. In the second line, a s...
int solution(void) { char t[1000]; char p[1000]; int n; int m; scanf("%s", t); scanf("%s", p); for (n = 0; t[n] != '\0'; n++) { ; } for (m = 0; p[m] != '\0'; m++) { ; } int i = 0; int j = 0; while (i <= n - m) { while (j < m && t[i + j] == p[j]) { j++; } if (j == m)...
fn solution() { let mut read = String::new(); std::io::stdin().read_line(&mut read).expect(""); let mut s = read.clone(); s = s.trim().to_string(); read = String::new(); std::io::stdin().read_line(&mut read).expect(""); let f = read.trim(); if f.len() > s.len() { std::process::ex...
medium
0014
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi has <var>N</var> balls. Initially, an integer <var>A_i</var> is written on the <var>i</var>-th ball.</p> <p>He would like to rewrite the integer on some balls so that there are at most <var>K<...
int solution() { int N; int K; int i; int tmp; int count = 0; int ans = 0; scanf("%d %d", &N, &K); int A[N + 1]; int d[N + 1]; for (i = 0; i <= N; i++) { A[i] = 0; d[i] = 0; } for (i = 0; i < N; i++) { scanf("%d", &tmp); A[tmp]++; } for (i = 0; i <= N; i++) { d[A[i]]++...
fn solution() { let stdin = io::stdin(); let mut stdin = stdin.lock(); stdin.read_until(b' ', &mut Vec::new()).unwrap(); let mut k = String::new(); stdin.read_line(&mut k).unwrap(); let k: usize = k.trim_end().parse().unwrap(); let mut amt: Vec<u32> = stdin .split(b' ') .map...
hard
0015
Moamen has an array of $$$n$$$ distinct integers. He wants to sort that array in non-decreasing order by doing the following operations in order exactly once: Split the array into exactly $$$k$$$ non-empty subarrays such that each element belongs to exactly one subarray. Reorder these subarrays arbitrary. Merge the ...
int solution() { int t; scanf("%d", &t); while (t--) { int n; int k; int c = 0; int i; int j; scanf("%d %d", &n, &k); long ara[n]; long p; for (i = 0; i < n; i++) { scanf("%ld", &ara[i]); } for (i = 0; i < n; i++) { if (ara[i] < p || i == 0) { c++; ...
fn solution() -> Result<(), Box<dyn Error>> { let stdin = io::stdin(); let mut lines = stdin.lock().lines(); let t: i32 = lines.next().unwrap()?.parse()?; for _ in 0..t { let (_, mut k): (i32, i32) = { let line = lines.next().unwrap()?; let mut lines = line.split(" ").ma...
medium
0016
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You...
int solution() { int n = 0; int a[100]; int s = 0; int max = 0; int i = 0; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &a[i]); } for (i = 0; i < n; i++) { if (max < a[i]) { max = a[i]; } } for (i = 0; i < n; i++) { s += max - a[i]; } printf("%d", s); return ...
fn solution() { io::stdin().read_line(&mut String::new()).unwrap(); let mut welfare_input = String::new(); io::stdin().read_line(&mut welfare_input).unwrap(); let mut max_welfare = 0; let mut total_welfare = 0; let mut population = 0; for welfare in welfare_input.split_whitespace().map(|x...
medium
0017
International Women's Day is coming soon! Polycarp is preparing for the holiday.There are $$$n$$$ candy boxes in the shop for sale. The $$$i$$$-th box contains $$$d_i$$$ candies.Polycarp wants to prepare the maximum number of gifts for $$$k$$$ girls. Each gift will consist of exactly two boxes. The girls should be able...
int solution() { int n; int k; int res = 0; int res2 = 0; scanf("%d %d", &n, &k); int d; int mods[101]; for (int i = 0; i < 101; i++) { mods[i] = 0; } for (int i = 0; i < n; i++) { scanf("%d", &d); if (d % k == 0) { res++; } else { mods[d % k]++; } } for (int i =...
fn solution() { let stdin = std::io::stdin(); let mut l1 = String::new(); let mut l2 = String::new(); stdin.read_line(&mut l1).unwrap(); stdin.read_line(&mut l2).unwrap(); let v1: Vec<i32> = l1.split_whitespace().map(|x| x.parse().unwrap()).collect(); let d: Vec<i32> = l2.split_whitespace()....
medium
0018
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>A company has <var>N</var> members, who are assigned ID numbers <var>1, ..., N</var>.</p> <p>Every member, except the member numbered <var>1</var>, has exactly one immediate boss with a smaller ID numbe...
int solution() { int n = 0; int m = 0; scanf("%d", &n); int t[200005] = {0}; for (int i = 0; i < n - 1; i++) { scanf("%d", &m); t[m - 1]++; } for (int i = 0; i < n; i++) { printf("%d\n", t[i]); } }
fn solution() { let mut buf = String::new(); std::io::stdin().read_to_string(&mut buf).unwrap(); let mut iter = buf.split_whitespace(); let n: usize = iter.next().unwrap().parse().unwrap(); let a: Vec<usize> = (0..n - 1) .map(|_| iter.next().unwrap().parse().unwrap()) .collect(); ...
medium
0019
NIT, the cleaver, is new in town! Thousands of people line up to orz him. To keep his orzers entertained, NIT decided to let them solve the following problem related to $$$\operatorname{or} z$$$. Can you solve this problem too?You are given a 1-indexed array of $$$n$$$ integers, $$$a$$$, and an integer $$$z$$$. You can...
int solution() { int t; scanf("%d", &t); while (t--) { int n; int z; scanf("%d %d", &n, &z); int a[n + 10]; int p[(2 * n) + 10]; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); p[i] = z | a[i]; } int max = p[0]; for (int i = 0; i < n; i++) { if (max < p[i]) ...
fn solution() { input! { name = cf, t: usize } for _ in 0..t { input! { use cf, n: usize, z: u32, a: [u32; n] } let ans = a.iter().map(|a| z | a).max().unwrap(); println!("{}", ans); } }
medium
0020
CQXYM is counting permutations length of $$$2n$$$.A permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a per...
int solution() { int test; scanf("%d", &test); while (test--) { int num; scanf("%d", &num); long long int fact = 1; for (int i = 3; i <= 2 * num; i++) { fact = (fact * i) % 1000000007; } printf("%lld\n", fact); } return 0; }
fn solution() { let mut t = String::new(); std::io::stdin().read_line(&mut t).expect(""); let t: i32 = t.trim().parse().expect(""); for _x in 0..t { let mut n = String::new(); std::io::stdin().read_line(&mut n).expect(""); let n: u128 = n.trim().parse().expect(""); let m...
easy
0021
Zookeeper is playing a game. In this game, Zookeeper must use bombs to bomb a string that consists of letters 'A' and 'B'. He can use bombs to bomb a substring which is either "AB" or "BB". When he bombs such a substring, the substring gets deleted from the string and the remaining parts of the string get concatenated....
int solution() { int T; scanf("%d", &T); for (int C = 0; C < T; C++) { char s[200005]; scanf("%s", s); int n = 0; while (s[n] != '\0') { n++; } char buf[n]; int bi = 0; for (int i = 0; i < n; i++) { buf[bi] = s[i]; bi++; if (bi >= 2 && buf[bi - 2] == 'A' &...
fn solution() { let mut str = String::new(); let _ = stdin().read_line(&mut str).unwrap(); let test: i32 = str.trim().parse().unwrap(); for _ in 0..test { str.clear(); let _ = stdin().read_line(&mut str).unwrap(); let s: Vec<char> = str.trim().chars().collect(); let mut d...
medium
0022
You are given a range of positive integers from $$$l$$$ to $$$r$$$.Find such a pair of integers $$$(x, y)$$$ that $$$l \le x, y \le r$$$, $$$x \ne y$$$ and $$$x$$$ divides $$$y$$$.If there are multiple answers, print any of them.You are also asked to answer $$$T$$$ independent queries.
int solution() { int a; int b; scanf("%d", &a); while (a--) { scanf("%d %*d", &b); printf("%d %d\n", b, 2 * b); } return 0; }
fn solution() { let mut tt = String::new(); stdin().read_line(&mut tt).ok(); let t: u32 = tt.trim().parse().unwrap(); for _i in 0..t { let mut lrs = String::new(); stdin().read_line(&mut lrs).ok(); let lr: Vec<u32> = lrs.split_whitespace().map(|x| x.parse().unwrap()).collect(); ...
hard
0023
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement. UCDHP stores some secret information about meteors as an n × m table with integers in its cells. The order of meteors in t...
int solution() { int i; int j; int swaptmp; int n; int m; int k; char s[2]; int p[1005][1005]; int indexx[1005]; int indexy[1005]; scanf("%d%d%d", &n, &m, &k); for (i = 0; i < n; i++) { indexx[i] = i; } for (i = 0; i < m; i++) { indexy[i] = i; } for (i = 0; i < n; i++) { for ...
fn solution() { let stdin = io::stdin(); let stdout = io::stdout(); let stdin_lock = stdin.lock(); let mut lines = stdin_lock.lines(); let mut stdout_lock = BufWriter::new(stdout.lock()); let (n, m, k) = { let tmp: Vec<_> = lines .next() .unwrap() .unw...
easy
0024
The title is a reference to the very first Educational Round from our writers team, Educational Round 18.There is a bag, containing colored balls. There are $$$n$$$ different colors of balls, numbered from $$$1$$$ to $$$n$$$. There are $$$\mathit{cnt}_i$$$ balls of color $$$i$$$ in the bag. The total amount of balls in...
int solution() { int t; scanf("%d", &t); for (int i = 0; i < t; i++) { int n; scanf("%d", &n); int cnt[n]; for (int j = 0; j < n; j++) { scanf("%d", &cnt[j]); } int a = 0; int b = 1; while (a < n && b < n) { cnt[a]--; cnt[b]--; while (cnt[a] == 0) { ...
fn solution() { let stdin = io::stdin(); let mut num = String::new(); stdin.read_line(&mut num).expect("Failed to parse line"); let num: i32 = num.trim().parse().expect("Please type a number!"); for _ in 0..num { let mut num2 = String::new(); stdin.read_line(&mut num2).expect("Failed...
hard
0025
There are $$$n$$$ people who want to participate in a boat competition. The weight of the $$$i$$$-th participant is $$$w_i$$$. Only teams consisting of two people can participate in this competition. As an organizer, you think that it's fair to allow only teams with the same total weight.So, if there are $$$k$$$ teams ...
int solution(void) { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); int W[n]; for (int i = 0; i < n; i++) { scanf("%d", &W[i]); } int B[101][2500]; int P[101] = {0}; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { B[W[i] + W[j]...
fn solution() { let t: usize = { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); buf.trim_end().parse().unwrap() }; for _ in 0..t { let n: usize = { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap()...
medium
0026
You are given integer $$$n$$$. You have to arrange numbers from $$$1$$$ to $$$2n$$$, using each of them exactly once, on the circle, so that the following condition would be satisfied:For every $$$n$$$ consecutive numbers on the circle write their sum on the blackboard. Then any two of written on the blackboard $$$2n$$...
int solution() { int n; scanf("%d", &n); if (n & 1) { puts("YES"); printf("1 "); for (int i = 1; i <= (n - 1) / 2; ++i) { printf("%d %d ", 4 * i, (4 * i) + 1); } for (int i = 1; i <= (n - 1) / 2; ++i) { printf("%d %d ", (4 * i) - 2, (4 * i) + 1 - 2); } printf("%d\n", 2 * n)...
fn solution() { let mut input = String::new(); io::stdin() .read_line(&mut input) .expect("failed to read input"); let n = input.trim().parse::<usize>().unwrap(); if n % 2 == 0 { println!("NO"); } else { println!("YES"); print!("1"); for i in (4..(2 ...
easy
0027
Alice has a grid with $$$2$$$ rows and $$$n$$$ columns. She fully covers the grid using $$$n$$$ dominoes of size $$$1 \times 2$$$ — Alice may place them vertically or horizontally, and each cell should be covered by exactly one domino.Now, she decided to show one row of the grid to Bob. Help Bob and figure out what the...
int solution() { int tc = 0; scanf("%d", &tc); getchar(); for (int i = 0; i < tc; i++) { int n = 0; scanf("%d", &n); getchar(); char chars[100] = {0}; for (int j = 0; j < n; j++) { scanf("%c", &chars[j]); } getchar(); char result[100] = {0}; for (int j = 0; j < n; j+...
fn solution() { let (i, o) = (io::stdin(), io::stdout()); let mut o = bw::new(o.lock()); for l in i.lock().lines().skip(2).step_by(2) { let s = l .unwrap() .chars() .map(|c| match c { 'U' => 'D', 'D' => 'U', _ => c, ...
easy
0028
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is <code>YES</code> or <code>NO</code>.</p> <p>When he checked the detailed status of the submissio...
int solution() { double N; double M; scanf("%lf %lf", &N, &M); int i = 1; double exp = 0.0; while (i * ((N - M) * 100.0 + 1900.0 * M) * pow(1 - pow(0.50, M), i - 1) * pow(0.50, M) > 0.01) { exp += i * ((N - M) * 100.0 + 1900.0 * M) * pow(1 - pow(0.50, M), i - 1) * pow(0....
fn solution() { let mut s = String::new(); std::io::stdin().read_line(&mut s).unwrap(); let v: Vec<usize> = s.trim().split(" ").map(|x| x.parse().unwrap()).collect(); println!("{}", (100 * (v[0] - v[1]) + 1900 * v[1]) << v[1]); }
hard
0029
<h1>ゼッケンの交換 (Swapping Bibs)</h1> <h2> 問題</h2> <p> JOI 高校の N 人の生徒が東西に一列に並んでいる.列の西の端から i 番目の生徒が生徒 i である.それぞれの生徒は整数が 1 つ書かれたゼッケンを付けている.最初,生徒 i のゼッケンには整数 A<sub>i</sub> が書かれている. </p> <p> バトンが M 個あり,バトンには 1 から M までの番号が付けられている.k = 1, 2, ..., M に対し,以下の操作を行う.バトン k (2 ≦ k ≦ M) に関する操作は,バトン k - 1 に関する操作が終わってから行う. </p> <ol sty...
int solution(void) { int n; int m; int bib[128] = {0}; int swh; int i; int j; scanf("%d%d", &n, &m); for (i = 1; i <= n; i++) { scanf("%d", &bib[i]); } for (i = 1; i <= m; i++) { for (j = 1; j < n; j++) { if (bib[j] % i > bib[j + 1] % i) { swh = bib[j]; bib[j] = bib[j +...
fn solution() { let input = { let mut buf = vec![]; stdin().read_to_end(&mut buf); unsafe { String::from_utf8_unchecked(buf) } }; let mut lines = input.split('\n'); let (n, m) = { let line = lines.next().unwrap(); let mut iter = line.split(' ').map(|s| s.parse()....
medium
0030
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Joisino is planning to open a shop in a shopping street.</p> <p>Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either o...
int solution() { int N; scanf("%d", &N); int F[100][14]; for (int i = 0; i < N; i++) { for (int j = 0; j < 10; j++) { scanf("%d", &F[i][j]); } } int P[100][15]; for (int i = 0; i < N; i++) { for (int j = 0; j < 11; j++) { scanf("%d", &P[i][j]); } } int res = -(1 << 30); ...
fn solution() { input! { N: usize, F: [ [usize; 10]; N], P: [ [i64; 11]; N], } let mut max = std::i64::MIN; for ind in 1..(1 << 10) { let mut c = vec![0_usize; N]; let mut res = ind; let mut count = 0; while res > 0 { let is = res & 1;...
medium
0031
The time on the planet Lapituletti goes the same way it goes on Earth but a day lasts $$$h$$$ hours and each hour lasts $$$m$$$ minutes. The inhabitants of that planet use digital clocks similar to earth ones. Clocks display time in a format HH:MM (the number of hours in decimal is displayed first, then (after the colo...
int solution() { int t; scanf("%d", &t); for (int i = 1; i <= t; i++) { int h; int m; int flag = 0; char c; scanf("%d%d", &h, &m); getchar(); int arr[4]; for (int j = 0; j < 4; j++) { if (j == 2) { getchar(); } scanf("%c", &c); arr[j] = c - '0'; ...
fn solution() { let mut input = String::new(); stdin().read_to_string(&mut input).unwrap(); let mut it = input.split_whitespace(); let _t = it.next().unwrap(); let a = [ Some(0), Some(1), Some(5), None, None, Some(2), None, None, ...
easy
0032
You are an upcoming movie director, and you have just released your first movie. You have also launched a simple review site with two buttons to press — upvote and downvote.However, the site is not so simple on the inside. There are two servers, each with its separate counts for the upvotes and the downvotes.$$$n$$$ re...
int solution() { int n; int count = 0; scanf("%d", &n); int a[n][51]; int b[n]; for (int i = 0; i < n; i++) { scanf("%d", &b[i]); for (int j = 0; j < b[i]; j++) { scanf("%d", &a[i][j]); } } for (int i = 0; i < n; i++) { count = 0; for (int j = 0; j < b[i]; j++) { if (a[i]...
fn solution() { let (i, o) = (io::stdin(), io::stdout()); let mut o = bw::new(o.lock()); for l in i.lock().lines().skip(2).step_by(2) { let s = l .unwrap() .split(' ') .fold(0, |s, c| if c != "2" { s + 1 } else { s }); writeln!(o, "{}", s).ok(); } }
hard
0033
You are given two arrays $$$a$$$ and $$$b$$$, consisting of $$$n$$$ integers each.Let's define a function $$$f(a, b)$$$ as follows: let's define an array $$$c$$$ of size $$$n$$$, where $$$c_i = a_i \oplus b_i$$$ ($$$\oplus$$$ denotes bitwise XOR); the value of the function is $$$c_1 \mathbin{\&amp;} c_2 \mathbin{\&a...
int solution() { int t = 0; int n = 0; int a[100000] = {}; int b[100000] = {}; int res = 0; int work_a[100000] = {}; int work_b[100000] = {}; int idx[100001] = {}; int work_idx[100001] = {}; res = scanf("%d", &t); while (t > 0) { int ans = 0; int idx_num = 1; res = scanf("%d", &n);...
fn solution() { let t: usize = { let mut line: String = String::new(); std::io::stdin().read_line(&mut line).unwrap(); line.trim().parse().unwrap() }; for _ in 0..t { let _n: usize = { let mut line: String = String::new(); std::io::stdin().read_line(&m...
medium
0034
Magnus decided to play a classic chess game. Though what he saw in his locker shocked him! His favourite chessboard got broken into 4 pieces, each of size n by n, n is always odd. And what's even worse, some squares were of wrong color. j-th square of the i-th row of k-th piece of the board has color ak, i, j; 1 being ...
int solution() { int n; while (scanf("%d", &n) != EOF) { char a[4][100][100]; char b[100][100]; char c[100][100]; int i; int j; int k; int d[4]; int e[4]; int sum = 0; int ans = 1e9; memset(d, 0, sizeof(d)); memset(e, 0, sizeof(e)); for (k = 0; k < 4; k++) { ...
fn solution() { let mut input = String::new(); io::stdin().read_line(&mut input); let n = input.trim().parse::<u32>().unwrap(); let mut boards = Vec::new(); for i in 0..4 { let mut input = String::new(); let mut mini_board = Vec::new(); if i != 0 { io::stdin().re...
medium
0035
Polycarp has an integer $$$n$$$ that doesn't contain the digit 0. He can do the following operation with his number several (possibly zero) times: Reverse the prefix of length $$$l$$$ (in other words, $$$l$$$ leftmost digits) of $$$n$$$. So, the leftmost digit is swapped with the $$$l$$$-th digit from the left, the sec...
int solution(void) { int n; int num; int exist = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &num); if (!(num & 1)) { printf("0\n"); continue; } while (num != 0) { if (!(num & 1)) { exist = 1; } if (num / 10 == 0) { if (!(num & 1...
fn solution() { let mut input: String = String::new(); io::stdin().read_line(&mut input).expect("invalid input"); let t: i32 = input.trim().parse().unwrap(); for _ in 0..t { let mut input_str: String = String::new(); io::stdin().read_line(&mut input_str).expect("invalid str"); ...
hard
0036
Alice and Bob have received three big piles of candies as a gift. Now they want to divide these candies as fair as possible. To do this, Alice takes one pile of candies, then Bob takes one of the other two piles. The last pile is split between Alice and Bob as they want: for example, it is possible that Alice takes the...
int solution() { long long n; scanf("%lld", &n); while (n--) { long long a[3]; long long sum = 0; for (int i = 0; i < 3; i++) { scanf("%lld", &a[i]); sum = sum + a[i]; } printf("%lld\n", sum / 2); } return 0; }
fn solution() { let n = { let mut line = String::new(); stdin().read_line(&mut line).unwrap(); let mut iter = line.split_whitespace(); iter.next().unwrap().parse::<usize>().unwrap() }; for _ in 0..n { let (a, b, c) = { let mut line = String::new(); ...
medium
0037
Numbers $$$1, 2, 3, \dots n$$$ (each integer from $$$1$$$ to $$$n$$$ once) are written on a board. In one operation you can erase any two numbers $$$a$$$ and $$$b$$$ from the board and write one integer $$$\frac{a + b}{2}$$$ rounded up instead.You should perform the given operation $$$n - 1$$$ times and make the result...
int solution() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); printf("2\n"); printf("%d %d\n", n - 1, n); while (n >= 3) { printf("%d %d\n", n - 2, n); n--; } } return 0; }
fn solution() { let mut str = String::new(); let _ = stdin().read_line(&mut str).unwrap(); let test: i32 = str.trim().parse().unwrap(); for _ in 0..test { str.clear(); let _ = stdin().read_line(&mut str).unwrap(); let x: usize = str.trim().parse().unwrap(); let mut ave = ...
hard
0038
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Find the sum of the integers between <var>1</var> and <var>N</var> (inclusive), whose sum of digits written in base <var>10</var> is between <var>A</var> and <var>B</var> (inclusive).</p> </section> </d...
int solution() { int N = 0; int A = 0; int B = 0; int i = 0; int ans = 0; scanf("%d %d %d", &N, &A, &B); for (i = 1; i <= N; i++) { int val = 0; val = (i / 10000) + ((i % 10000) / 1000) + ((i % 1000) / 100) + ((i % 100) / 10) + (i % 10); if ((A <= val) && (val <= B)) { ans += ...
fn solution() { let scan = std::io::stdin(); let mut line = String::new(); let _ = scan.read_line(&mut line); let vec: Vec<&str> = line.split_whitespace().collect(); let mut n: Vec<i32> = Vec::new(); for x in vec { n.push(x.parse().unwrap()); } let mut ans: i32 = 0; for x ...
medium
0039
You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings.An integer greater than 1 is composite, if it is not prime, i.e. if i...
int solution() { int n; scanf("%d\n", &n); int a[n]; for (int i = 0; i < n; i++) { scanf("%d\n", &a[i]); } for (int i = 0; i < n; i++) { if (((a[i] / 4 - a[i] % 2) <= 0) || (a[i] % 4 == 3 && a[i] <= 11)) { printf("-1\n"); } else { printf("%d\n", (a[i] / 4) - (a[i] % 2)); } } ...
fn solution() { let mut s = String::new(); io::stdin().read_line(&mut s).unwrap(); let N: usize = s.trim_end().parse().unwrap(); s.clear(); for _i in 0..N { io::stdin().read_line(&mut s).unwrap(); let q: i32 = s.trim_end().parse().unwrap(); if q < 4 { println!("-1...
medium
0040
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi is hosting an sports meet. There are <var>N</var> people who will participate. These people are conveniently numbered <var>1</var> through <var>N</var>. Also, there are <var>M</var> options of...
int solution(void) { int N; int M; scanf("%d %d", &N, &M); int A[N][M]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { scanf("%d", &A[i][j]); } } int kibousya[M]; int nozoki[M]; for (int i = 0; i < M; i++) { kibousya[i] = 0; nozoki[i] = 0; } int ans = 114514; f...
fn solution() { let mut buf = String::new(); std::io::stdin().read_to_string(&mut buf).unwrap(); let mut buf_it = buf.split_whitespace(); let N = buf_it.next().unwrap().parse::<usize>().unwrap(); let M = buf_it.next().unwrap().parse::<usize>().unwrap(); let A = (0..N) .map(|_| { ...
medium
0041
There are $$$n$$$ kids, numbered from $$$1$$$ to $$$n$$$, dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ (all these numbers are from $$$1$$$ to $$$n$$$ and are distinct, so $$$p$$$ is a permutation). Let the next kid for a kid $$$p_i$...
int solution() { int n; scanf("%d", &n); int ans[n + 5]; int a[n + 5]; int b[n + 5]; for (int i = 1; i <= n; ++i) { scanf("%d%d", &a[i], &b[i]); } ans[1] = 1; ans[2] = a[1]; ans[3] = b[1]; if (a[a[1]] != b[1] && b[a[1]] != b[1]) { ans[2] = b[1]; ans[3] = a[1]; } int place = ...
fn solution() { let stdin = io::stdin(); let mut input = stdin.lock(); let mut line = String::new(); input.read_line(&mut line).unwrap(); let mut count = line.trim().parse().unwrap(); line.clear(); let mut neighbours = Vec::with_capacity(count); while count > 0 { input.read_line(...
hard
0042
<span class="lang-en"> <p>Score: <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>We held two competitions: Coding Contest and Robot Maneuver.</p> <p>In each competition, the contestants taking the <var>3</var>-rd, <var>2</var>-nd, and <var>1</var>-st places receive <var>100000</var>...
int solution() { int x = 0; int y = 0; int money = 0; scanf("%d %d", &x, &y); if (x == 3) { money += 100000; } else if (x == 2) { money += 200000; } else if (x == 1) { money += 300000; } if (y == 3) { money += 100000; } else if (y == 2) { money += 200000; } else if (y == 1) { ...
fn solution() { let (X, Y): (usize, usize) = { let mut line: String = String::new(); std::io::stdin().read_line(&mut line).unwrap(); let mut iter = line.split_whitespace(); ( iter.next().unwrap().parse().unwrap(), iter.next().unwrap().parse().unwrap(), ...
easy
0043
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given <var>N</var> integers <var>A_1, ..., A_N</var>, compute <var>A_1 \times ... \times A_N</var>.</p> <p>However, if the result exceeds <var>10^{18}</var>, print <code>-1</code> instead.</p> </section...
int solution(void) { int i = 0; int N = 0; scanf("%d", &N); long long A[N]; long long ans = 1; long long x = (pow(10, 18.0)); if (2 <= N && N <= (pow(10, 5.0))) { for (i = 0; i < N; i++) { scanf("%lld", &A[i]); } for (i = 0; i < N; i++) { if (A[i] == 0) { printf("0"); ...
fn solution() { let mut is = String::new(); stdin().read_line(&mut is).ok(); is.clear(); stdin().read_line(&mut is).ok(); let itr = is.split_whitespace().map(|e| e.parse::<i128>().unwrap()); let mut ans = 1; let flg = itr.clone().any(|e| e == 0); if !flg { for e in itr { ...
hard
0044
The map of the capital of Berland can be viewed on the infinite coordinate plane. Each point with integer coordinates contains a building, and there are streets connecting every building to four neighbouring buildings. All streets are parallel to the coordinate axes.The main school of the capital is located in $$$(s_x,...
int solution() { int n; int sx; int sy; scanf("%d %d %d", &n, &sx, &sy); int s[n][2]; int l = 0; int r = 0; int u = 0; int d = 0; for (int i = 0; i < n; i++) { scanf("%d %d", &s[i][0], &s[i][1]); if (s[i][0] > sx) { r++; } else if (s[i][0] < sx) { l++; } if (s[i][1] >...
fn solution() { let mut str = String::new(); let _ = stdin().read_line(&mut str).unwrap(); let mut iter = str.split_whitespace(); let n: i64 = iter.next().unwrap().parse().unwrap(); let s_x: i64 = iter.next().unwrap().parse().unwrap(); let s_y: i64 = iter.next().unwrap().parse().unwrap(); le...
medium
0045
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You have <var>N</var> items and a bag of strength <var>W</var>. The <var>i</var>-th item has a weight of <var>w_i</var> and a value of <var>v_i</var>.</p> <p>You will select some of the items and put th...
int solution(void) { int N; long long W; scanf("%d%lld", &N, &W); long long dp[N + 1][N + 1][301]; long long w[N]; long long v[N]; for (int i = 0; i < N; i++) { scanf("%lld%lld", &w[i], &v[i]); } for (int i = 0; i <= N; i++) { for (int j = 0; j <= N; j++) { for (int k = 0; k <= 30...
fn solution() { input! { N: usize, W: u64, WV: [(u64,u64); N], } let mut V = vec![vec![0; 0]; 4]; let mut w0 = 0; for i in 0..N { let (w, v) = WV[i]; if i == 0 { V[0].push(v); w0 = w; } else { V[(w - w0) as usize].p...
hard
0046
There are $$$n$$$ block towers in a row, where tower $$$i$$$ has a height of $$$a_i$$$. You're part of a building crew, and you want to make the buildings look as nice as possible. In a single day, you can perform the following operation: Choose two indices $$$i$$$ and $$$j$$$ ($$$1 \leq i, j \leq n$$$; $$$i \neq j$$$...
int solution() { int n; int x = 0; scanf("%d", &n); int arr_1[n]; int result[n]; for (int i = 0; i < n; i++) { scanf("%d", &arr_1[i]); int arr_2[arr_1[i]]; for (int j = 0; j < arr_1[i]; j++) { scanf("%d", &arr_2[j]); x = x + arr_2[j]; } if (x % arr_1[i] == 0) { result[i...
fn solution() { let stdin = stdin(); let mut lines = stdin.lock().lines(); let cases: u32 = lines.next().unwrap().unwrap().parse().unwrap(); for _ in 0..cases { let buildings_count: u32 = lines.next().unwrap().unwrap().parse().unwrap(); let buildings_line = lines.next().unwrap().unwrap()...
hard
0047
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi and Aoki will have a battle using their monsters.</p> <p>The health and strength of Takahashi's monster are <var>A</var> and <var>B</var>, respectively, and those of Aoki's monster are <var>C<...
int solution() { int A = 0; int B = 0; int C = 0; int D = 0; scanf("%d %d %d %d", &A, &B, &C, &D); while (1) { C = C - B; if (C <= 0) { printf("Yes\n"); break; } A = A - D; if (A <= 0) { printf("No\n"); break; } } return 0; }
fn solution() { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let s: Vec<i32> = s .trim() .split(' ') .map(|x| x.parse::<i32>().unwrap()) .collect(); let (a, b, c, d) = (s[0], s[1], s[2], s[3]); let tk = (c + (b - 1)) / b; let ao = (a + (d -...
medium
0048
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> integers written on a blackboard. The <var>i</var>-th integer is <var>A_i</var>.</p> <p>Takahashi will repeatedly perform the following operation on these numbers:</p> <ul> <li>Se...
int solution() { int N = 0; int count = 0; scanf("%d", &N); int a[N]; for (int i = 0; i < N; i++) { scanf("%d", &a[i]); } for (int i = 0; i < N; i++) { count += a[i] % 2; } if (count % 2 == 0) { printf("YES"); } else { printf("NO"); } return 0; }
fn solution() { let mut line = String::new(); io::stdin() .read_line(&mut line) .expect("Failed to read line"); io::stdin() .read_line(&mut line) .expect("Failed to read line"); let mut vec: Vec<&str> = line.split_whitespace().collect(); let n: u64 = vec.swap_remove(0...
medium
0049
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. I...
int solution() { int i = 0; int a = 0; int b = 0; int n = 0; int c = 0; int count = 0; scanf("%d %d %d", &n, &a, &b); int t[n]; for (i = 0; i < n; i++) { scanf("%d", &t[i]); if (t[i] == 1 && a != 0) { a--; } else if (t[i] == 2 && b != 0) { b--; } else if (t[i] == 1 && a == ...
fn solution() { let (_, a, b) = { let mut input = String::new(); stdin().read_line(&mut input).unwrap(); let mut it = input .split_whitespace() .map(|k| k.parse::<usize>().unwrap()); (it.next().unwrap(), it.next().unwrap(), it.next().unwrap()) }; let ...
medium
0050
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> cities and <var>M</var> roads. The <var>i</var>-th road <var>(1≤i≤M)</var> connects two cities <var>a_i</var> and <var>b_i</var> <var>(1≤a_i,b_i≤N)</var> bidirectionally. There ma...
int solution(void) { int N; int M; scanf("%d", &N); scanf("%d", &M); int city[2 * M]; int ans[N]; for (int i = 0; i < N; i++) { ans[i] = 0; } for (int i = 0; i < 2 * M; i++) { scanf("%d", &city[i]); } for (int i = 0; i < 2 * M; i++) { ans[city[i] - 1]++; } for (int i = 0; i < N;...
fn solution() { let (n, m) = { let mut b = String::new(); std::io::stdin().read_line(&mut b).unwrap(); let vec = b .split_whitespace() .map(|i| i.parse().unwrap()) .collect::<Vec<i32>>(); (vec[0], vec[1]) }; let mut h = std::collections::Ha...
hard
0051
Once upon a time Mike and Mike decided to come up with an outstanding problem for some stage of ROI (rare olympiad in informatics). One of them came up with a problem prototype but another stole the idea and proposed that problem for another stage of the same olympiad. Since then the first Mike has been waiting for an ...
int solution() { long long m; long long n; long long flag; long long k; long long x; long long sum = 0; long long isFill = 0; long long last = 0; long long term = 0; scanf("%lld %lld", &m, &n); long long a[m]; long long num[m]; for (int i = 0; i < m; i++) { scanf("%lld", &a[i]); sum +=...
fn solution() { let mut sin = String::new(); io::stdin().read_line(&mut sin).unwrap(); let mut iter = sin.split_whitespace(); let n = iter.next().unwrap().trim().parse::<i32>().unwrap(); let q = iter.next().unwrap().trim().parse::<i32>().unwrap(); sin.clear(); io::stdin().read_line(&mut sin...
hard
0052
Palo Alto is an unusual city because it is an endless coordinate line. It is also known for the office of Lyft Level 5.Lyft has become so popular so that it is now used by all $$$m$$$ taxi drivers in the city, who every day transport the rest of the city residents — $$$n$$$ riders.Each resident (including taxi drivers)...
int solution() { int n; int m; int j = 0; scanf("%d %d", &n, &m); int x[n + m + 1]; int t[n + m + 1]; int pos[m + 1]; int ans[m + 1]; for (int i = 0; i < n + m; i++) { scanf("%d", &x[i]); } for (int i = 0; i < n + m; i++) { scanf("%d", &t[i]); if (t[i] == 1) { pos[j++] = i; }...
fn solution() { let mut input = String::new(); use std::io::{self, prelude::*}; io::stdin().read_to_string(&mut input).unwrap(); let mut it = input.split_whitespace(); let n: usize = it.next().unwrap().parse().unwrap(); let m: usize = it.next().unwrap().parse().unwrap(); let x: Vec<usize>...
medium
0053
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p><var>1000000000000001</var> dogs suddenly appeared under the roof of Roger's house, all of which he decided to keep. The dogs had been numbered <var>1</var> through <var>1000000000000001</var>, but he g...
int solution(void) { long int dogn = 0; char name[16] = {0}; int i = 0; scanf("%ld", &dogn); dogn--; while (dogn > -1) { name[i] = dogn % 26 + 'a'; dogn = dogn / 26; i++; dogn--; } while (i--) { printf("%c", name[i]); } printf("\n"); return 0; }
fn solution() { let mut is = String::new(); stdin().read_line(&mut is).ok(); let mut n: usize = is.trim().parse::<usize>().unwrap(); let mut ans = String::new(); let a = (b'a'..=b'z').map(|e| e as char).collect::<Vec<char>>(); while n > 0 { n -= 1; let t = n % 26; n /= 2...
easy
0054
<H1>Search I</H1> <p> You are given a sequence of <i>n</i> integers S and a sequence of different <i>q</i> integers T. Write a program which outputs C, the number of integers in T which are also in the set S. </p> <H2>Input</H2> <p> In the first line <i>n</i> is given. In the second line, <i>n</i> integers are given...
int solution(void) { int n = 0; int m = 0; int i = 0; int j = 0; int count = 0; scanf("%d", &n); int a[n]; for (i = 0; i < n; i++) { scanf("%d", &a[i]); } scanf("%d", &m); int b[m]; for (i = 0; i < m; i++) { scanf("%d", &b[i]); for (j = 0; j < n; j++) { if (a[j] == b[i]) { ...
fn solution() { let mut buf = String::new(); std::io::stdin().read_to_string(&mut buf).unwrap(); let mut buf_it = buf.split_whitespace(); let N = buf_it.next().unwrap().parse::<usize>().unwrap(); let A = (0..N) .map(|_| buf_it.next().unwrap().parse::<isize>().unwrap()) .collect::<Ha...
medium
0055
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is an integer sequence <var>A</var> of length <var>N</var>.</p> <p>Find the number of the pairs of integers <var>l</var> and <var>r</var> (<var>1 \leq l \leq r \leq N</var>) that satisfy the follo...
int solution() { int n; scanf("%d", &n); long a[n]; long sum = 0; long xor = 0; long ans = 0; int k = 0; int cnt = 0; for (int i = 0; i < n; i++) { scanf("%ld", a + i); } for (int i = 0; i < n; i++) { while (k < n && (sum + a[k] == (xor^a[k]))) { sum += a[k]; xor += a[k]; ...
fn solution() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.split_whitespace(); let n: usize = itr.next().unwrap().parse().unwrap(); let a: Vec<usize> = (0..n) .map(|_| itr.next().unwrap().parse().unwrap()) .collect(); let mut...
easy
0056
Your company was appointed to lay new asphalt on the highway of length $$$n$$$. You know that every day you can either repair one unit of the highway (lay new asphalt over one unit of the highway) or skip repairing.Skipping the repair is necessary because of the climate. The climate in your region is periodical: there ...
int solution() { int t; scanf("%d", &t); long long n; long long g; long long b; long long m; long long a; long long r; long long s[t]; long long d; long long f; for (int i = 0; i < t; i++) { scanf("%lld %lld %lld", &n, &g, &b); if (n % 2 == 0) { r = n / 2; } else { r = (n...
fn solution() { let mut line = String::new(); io::stdin().read_line(&mut line).unwrap(); let t: u32 = line.trim().parse().unwrap(); for _ in 0..t { let mut line = String::new(); io::stdin().read_line(&mut line).unwrap(); let mut pieces = line.split_whitespace(); let n: u6...
easy
0057
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We ask you to select some number of positive integers, and calculate the sum of them.</p> <p>It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow t...
int solution(void) { int a = 0; int b = 0; int c = 0; int x = 0; int i; scanf("%d", &a); scanf("%d", &b); scanf("%d", &c); for (i = 1; i <= b; i++) { if (c == ((a * i) % b)) { printf("YES"); x = a % b; break; } } if (x == 0) { printf("NO"); } return 0; }
fn solution() { use std::io; let mut input = String::new(); let _ = io::stdin().read_line(&mut input); let input_nums = input .split_whitespace() .map(|x| x.parse::<usize>().unwrap()) .collect::<Vec<_>>(); let a = input_nums[0]; let b = input_nums[1]; let c = input_nu...
easy
0058
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.There are $$$n$$$ displays placed along a road, and the $$$i$$$-th of them can display a text with font size $$$s_i$$$ only. Maria Stepanovna want...
int solution() { int i; int j; int n; int ans = 1e9; scanf("%d", &n); int a[n + 2]; int cost[n + 2]; int d[n + 2]; for (i = 0; i < n; i++) { scanf("%d", &a[i]), d[i] = 1e9; } for (i = 0; i < n; i++) { scanf("%d", &cost[i]); } for (i = 0; i < n; i++) { for (j = 0; j < i; j++) { ...
fn solution() { let mut input = String::new(); use std::io::{self, prelude::*}; io::stdin().read_to_string(&mut input).unwrap(); let mut it = input.split_whitespace(); let n: usize = it.next().unwrap().parse().unwrap(); let s: Vec<u64> = it.by_ref().take(n).map(|x| x.parse().unwrap()).collect(...
medium
0059
Shell sort
void solution(int array[], int len) { int i; int j; int gap; for (gap = len / 2; gap > 0; gap = gap / 2) { for (i = gap; i < len; i++) { for (j = i - gap; j >= 0 && array[j] > array[j + gap]; j = j - gap) { int temp = array[j]; array[j] = array[j + gap]; array[j + gap] = temp;...
fn solution<T: Ord + Copy>(values: &mut [T]) { fn insertion<T: Ord + Copy>(values: &mut [T], start: usize, gap: usize) { for i in ((start + gap)..values.len()).step_by(gap) { let val_current = values[i]; let mut pos = i; while pos >= gap && values[pos - gap] > val_curren...
medium
0060
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3...
int solution() { while (1) { int n; int i; int cnt = 0; int sw = 1; int sosuu[100000]; int t; if (scanf("%d", &n) == EOF) { break; } if (n <= 1) { cnt = 0; } else { sosuu[cnt] = 2; cnt++; for (i = 3; i <= n; i += 2) { sw = 1; for (t...
fn solution() { loop { let mut s = String::new(); stdin().read_line(&mut s).unwrap(); let end: i32 = match s.trim().parse() { Ok(end) => end, Err(_) => return, }; if end < 2 { println!("{}", 0); continue; } let ...
medium
0061
<H1>博士が愛した2進数</H1> <p> 「君の靴のサイズはいくつかね」 <br/> <br/> 初対面の私に、いきなり博士は尋ねました。<br/> <br/> 「 23.5 です」<br/> 「ほお、実にきりのいい数字だ。2 の 4 乗に 2 の 2 乗と 2 の 1 乗と 2 の 0 乗と 2 の -1 乗を 加えた数だ」<br/> <br/> 続けて博士は尋ねました。<br/> <br/> 「君、身長はいくつかね」<br/> 「はい、158.1 です」<br/> <br/> 博士は腕組みをして目を閉じました。しばらくの沈黙の後、口を開きました。<br/> <br/> 「ナァ~」...
int solution() { double n; while (1) { scanf("%lf", &n); if (n < 0) { return 0; } n *= 2 * 2 * 2 * 2; int m = (int)n; if (n - (double)m == 0 && (m >> 12) == 0) { int i = 0; for (; i < 12; ++i) { if (i == 8) { printf("."); } printf("%d...
fn solution() { let stdin = stdin(); let lines = stdin.lock().lines(); for line in lines { let n: f64 = line.unwrap().parse().unwrap(); if n < 0. { return; } let nf = n * 16.; let ni = nf as u64; if ni > 0xfff || nf.fract() != 0. { p...
medium
0062
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>There are <var>N</var> people numbered <var>1</var> to <var>N</var>. Each person wears a red hat or a blue hat.</p> <p>You are given a string <var>s</var> representing the colors of the people. Person ...
int solution() { int n = 0; scanf("%d", &n); char s[100]; scanf("%s", s); int i = 0; int countR = 0; while (i < n) { if (s[i] == 'R') { countR++; } i++; } if (countR > n - countR) { printf("Yes"); } else { printf("No"); } }
fn solution() { let mut buf = String::new(); io::stdin().read_line(&mut buf).unwrap(); buf.clear(); io::stdin().read_line(&mut buf).unwrap(); let (r, b) = buf.chars().fold((0, 0), |(mut r, mut b), c| { match c { 'R' => r += 1, 'B' => b += 1, _ => (), ...
medium
0063
<!--<H1>X-th day of September</H1>--> <h1>Day of Week</h1> <p> The 9th day of September 2017 is Saturday. Then, what day of the week is the X-th of September 2017? </p> <p> Given a day in September 2017, write a program to report what day of the week it is. </p> <h2>Input</h2> <p> The input is given in the...
int solution(void) { char data[7][4] = {"thu", "fri", "sat", "sun", "mon", "tue", "wed"}; int X = 0; scanf("%d", &X); printf("%s\n", data[X % 7]); return 0; }
fn solution() { let mut buf = String::new(); std::io::stdin().read_to_string(&mut buf).unwrap(); let mut iter = buf.split_whitespace(); let a: usize = iter.next().unwrap().parse().unwrap(); let days = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]; let x = (a % 7 + 3) % 7; println!("{}...
easy
0064
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We will call a string that can be obtained by concatenating two equal strings an <em>even</em> string. For example, <code>xyzxyz</code> and <code>aaaaaa</code> are even, while <code>ababab</code> and <c...
int solution() { char str[200] = {0}; int len = 0; scanf("%s", str); len = strlen(str); while (1) { char tmp1[100] = {0}; char tmp2[100] = {0}; if ((strlen(str) % 2) != 0) { len -= 1; } else { len -= 2; } strncpy(tmp1, &str[0], len / 2); strncpy(tmp2, &str[len / 2],...
fn solution() { let stdin = io::stdin(); let mut buf = String::new(); stdin.read_line(&mut buf).ok(); let mut it = buf.split_whitespace().map(|n| String::from_str(n).unwrap()); let mut s = it.next().unwrap(); while !s.is_empty() { s = s[0..s.len() - 2].to_string(); if s.len() %...
medium
0065
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> stones arranged in a row. Every stone is painted white or black. A string <var>S</var> represents the color of the stones. The <var>i</var>-th stone from the left is white if the ...
int solution(void) { int n; int i; char s[200002]; int a[200001]; scanf("%d%s", &n, s + 1); a[0] = 0; for (i = 1; i <= n; i++) { a[i] = a[i - 1] + (s[i] == '#'); } int min = INT_MAX; for (i = 0; i <= n; i++) { int now = a[i] + (n - i - a[n] + a[i]); if (now < min) { min = now; ...
fn solution() { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); let mut iter = buf.split_whitespace(); let n: usize = iter.next().unwrap().parse().unwrap(); let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); let s = buf.trim(); let m...
hard
End of preview. Expand in Data Studio

Dataset Card for C-to-Rust Parallel Semantic Similarity Corpus

Dataset Summary

The C-to-Rust Parallel Semantic Similarity Corpus is a curated dataset consisting of 1,886 aligned, function-level C and Rust code pairs. It was developed to evaluate cross-language semantic similarity and functional equivalence between a traditional legacy language (C) and a modern memory-safe language (Rust).

The source code snippets are drawn from accepted competitive programming submissions across Project CodeNet, xCodeEval, and The Algorithms. Every pair shares identical algorithmic logic, has been validated to compile under modern environments (GCC C17 and Rust 1.94.0), and is filtered to ensure functional correctness.

Dataset Structure

The dataset is distributed as a single JSONL file where each row represents an aligned problem pair.

Data Fields

  • problem_id (string): A zero-padded sequential identifier spanning 0001 to 1886.
  • problem_description (string): The full natural language problem statement provided by the source platform.
  • c_code (string): The normalized, fully functional C implementation.
  • rust_code (string): The normalized, fully functional Rust implementation.
  • difficulty (string): The alignment difficulty tier assigned to the pair (easy, medium, or hard).

Dataset Creation & Curation

Filtering and Preprocessing Pipeline

  1. Functional Correctness: Restricted exclusively to submissions marked as "Accepted" by online judges to guarantee true semantic alignment.
  2. Compilation Validation: Submissions were strictly compiled locally using GCC (C17 standard) and Rust 1.94.0 to eliminate syntax errors or compiler drift.
  3. Code Normalization: Dead code, redundant macros, comments, and explicit Rust #[allow(...)] attributes were systematically stripped. Code layouts were standardized using clang-format and rustfmt.
  4. Function Inlining: Core logic was restricted to a single function block, and all function identifiers were normalized to solution to eliminate superficial retrieval shortcuts.
  5. Semantic Diversity: The final corpus contains a diverse set of unique problems with no overlapping duplicates, providing a clean benchmark for cross-language evaluation.

Difficulty Categorization

Difficulty tiers were empirically mapped using zero-shot cosine similarity scores from the SFR-Embedding-Code-400M_R model. Quantile thresholds at the 25th and 75th percentiles partition the dataset:

  • Easy (25%): Similarity $\ge 0.868$
  • Medium (50%): Similarity between $0.781$ and $0.868$
  • Hard (25%): Similarity $< 0.781$ (Representing heavy syntax/paradigm divergence)

Associated Paper

The complete academic paper detailing the methodology, curation pipeline, and evaluation results for this dataset is available directly within this repository:

Please refer to the paper for in-depth insights into the dataset's design choices and baseline benchmarks.

Citation Information

@proceedings{hejlek2026creating,
  title={Creating a Parallel C to Rust Corpus for Semantic Similarity Evaluation},
  author={Hejlek, Vojtěch},
  year={2026},
  organization={Instituto de Ciências Matemáticas e de Computação, Universidade de São Paulo (ICMC/USP)},
  note={Advisor: Alneu de Andrade Lopes, Coadvisor: Leonardo Jesus Almeida}
}
Downloads last month
-

Models trained or fine-tuned on hejlevoj/C-Rust-parallel-corpus