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 |
|---|---|---|---|---|
1001 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Tak performed the following action <var>N</var> times: rolling two dice.
The result of the <var>i</var>-th roll is <var>D_{i,1}</var> and <var>D_{i,2}</var>.</p>
<p>Check if doublets occurred at least t... | int solution(void) {
int N = 10;
int count = 0;
int judge = 0;
scanf("%d", &N);
int a[N];
int b[N];
for (int n = 0; n < N; n++) {
scanf("%d %d", &a[n], &b[n]);
}
for (int n = 0; n < N; n++) {
if (a[n] == b[n]) {
count++;
} else {
count = 0;
}
if (count == 3) {
... | fn solution() {
let mut s = String::new();
use std::io::Read;
std::io::stdin().read_to_string(&mut s).unwrap();
let mut s = s.split_whitespace();
let n: usize = s.next().unwrap().parse().unwrap();
let a: Vec<_> = (0..n)
.map(|_| {
let a: i32 = s.next().unwrap().parse().unwrap... | medium |
1002 | Polycarp plays a well-known computer game (we won't mention its name). In this game, he can craft tools of two types — shovels and swords. To craft a shovel, Polycarp spends two sticks and one diamond; to craft a sword, Polycarp spends two diamonds and one stick.Each tool can be sold for exactly one emerald. How many e... | int solution() {
int t;
int a;
int b;
int k[1000];
scanf("%i", &t);
for (int i = 0; i < t; i++) {
scanf("%i %i", &a, &b);
if (a > 0 && b > 0 && a * 2 <= b) {
k[i] = a;
} else if (b * 2 <= a && a > 0 && b > 0) {
k[i] = b;
} else if (!(a * 2 <= b) && !(b * 2 <= a) && a > 0 && b > 0... | fn solution() {
let stdin = io::stdin();
let mut lines = stdin.lock().lines();
let t: usize = lines.next().unwrap().unwrap().parse().unwrap();
for _ in 0..t {
let xs: Vec<usize> = lines
.next()
.unwrap()
.unwrap()
.split(' ')
.map(|x| x... | easy |
1003 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You went shopping to buy cakes and donuts with <var>X</var> yen (the currency of Japan).</p>
<p>First, you bought one cake for <var>A</var> yen at a cake shop.
Then, you bought as many donuts as possibl... | int solution() {
int x;
int a;
int b = 0;
scanf("%d %d %d", &x, &a, &b);
x = x - a;
while (x >= b) {
x = x - b;
if (x <= 0) {
break;
}
}
printf("%d", x);
return 0;
} | fn solution() {
let mut buf: String = String::new();
io::stdin().read_line(&mut buf).unwrap();
let x: i32 = buf.trim().parse::<i32>().unwrap();
let mut buf: String = String::new();
io::stdin().read_line(&mut buf).unwrap();
let a: i32 = buf.trim().parse::<i32>().unwrap();
let mut buf: String ... | medium |
1004 | In fact, the problems E1 and E2 do not have much in common. You should probably think of them as two separate problems.A permutation $$$p$$$ of size $$$n$$$ is given. A permutation of size $$$n$$$ is an array of size $$$n$$$ in which each integer from $$$1$$$ to $$$n$$$ occurs exactly once. For example, $$$[1, 4, 3, 2]... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int A[(2 * n) + 1];
int i = n;
int l = n - 1;
int r = n + 1;
int check = 0;
for (int m = 0; m < n; m++) {
int temp;
scanf("%d", &temp);
if (check == 0) {
A[i] = temp;
ch... | 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 mut v = std::collections::VecDeque::new();
l.unwrap()
.split(' ')
.map(|w| w.parse::<u32>().unwrap())
.fold((u32::MA... | hard |
1005 | Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.Ivar has $$$n$$$ warriors, he places them on a straight line in front of the main gate, in a way that the $$$i$$$-th warrior stands right after $$$(i-1)$$$-th ... | int solution() {
long long int n;
long long int m;
scanf("%lld%lld", &n, &m);
long long int a[n + 1];
a[0] = 0;
for (long long int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
a[i] = a[i - 1] + a[i];
}
long long int lb = 0;
long long int ub = n;
long long int mid;
long long int s = 0;
fo... | fn solution() {
use std::io;
use std::io::prelude::*;
let mut input = String::new();
io::stdin().read_to_string(&mut input).unwrap();
let mut it = input.split_whitespace();
let n: usize = it.next().unwrap().parse().unwrap();
let _q: usize = it.next().unwrap().parse().unwrap();
let a:... | hard |
1006 | You are given a string A. Find a string B, where B is a palindrome and A is a subsequence of B.A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, "cotst" is a subsequence of "con... | int solution() {
char A[1003];
char B[2006];
int i = 0;
scanf("%s", A);
int len = 0;
while (A[len] != '\0') {
len++;
}
while (A[i] != '\0') {
B[i] = A[len - i - 1];
i++;
}
int j = 0;
while (A[j] != '\0') {
B[i] = A[j];
j++;
i++;
}
B[i] = '\0';
printf("%s\n", B);
ret... | fn solution() {
let mut input = String::new();
use std::io::prelude::*;
std::io::stdin().read_to_string(&mut input).unwrap();
input.trim();
let output: String = input
.trim()
.chars()
.chain(input.trim().chars().rev())
.collect();
println!("{}", output);
} | hard |
1007 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a box containing <var>N</var> balls. The <var>i</var>-th ball has the integer <var>A_i</var> written on it.
Snuke can perform the following operation any number of times:</p>
<ul>
<li>Take out ... | int solution() {
int i;
int j;
int n;
int k;
int min;
int max;
scanf("%d %d", &n, &k);
int a[n];
scanf("%d", &a[0]);
min = a[0];
max = a[0];
for (i = 1; i < n; i++) {
scanf(" %d", &a[i]);
if (min > a[i]) {
min = a[i];
}
if (max < a[i]) {
max = a[i];
}
}
if (m... | fn solution() {
input! {
n: usize,
k: i64,
a_vec: [i64; n]
}
let words = ("POSSIBLE", "IMPOSSIBLE");
let euc = |num1: i64, num2: i64| -> i64 {
if num1 == 0 || num2 == 0 {
return cmp::max(num1, num2);
}
let mut la;
let mut mi;
if... | medium |
1008 | Monocarp has forgotten the password to his mobile phone. The password consists of $$$4$$$ digits from $$$0$$$ to $$$9$$$ (note that it can start with the digit $$$0$$$).Monocarp remembers that his password had exactly two different digits, and each of these digits appeared exactly two times in the password. Monocarp al... | int solution() {
int n = 0;
scanf("%d", &n);
int i = 0;
int j = 0;
int l = 0;
int result = 0;
int arr[10];
int k = 0;
if (n < 1 || n > 200) {
return 0;
}
for (i = 0; i < n && i < 200; i++) {
scanf("%d", &j);
if (j < 1 || j > 8) {
return 0;
}
k = 0;
while (k < j) {
... | fn solution() {
let mut tests = String::new();
io::stdin().read_line(&mut tests).unwrap();
let tests = tests.trim().parse().unwrap();
for _ in 0..tests {
let mut digits = String::new();
io::stdin().read_line(&mut digits).unwrap();
let digits: i32 = digits.trim().parse().unwrap()... | medium |
1009 | There was an electronic store heist last night.All keyboards which were in the store yesterday were numbered in ascending order from some integer number $$$x$$$. For example, if $$$x = 4$$$ and there were $$$3$$$ keyboards in the store, then the devices had indices $$$4$$$, $$$5$$$ and $$$6$$$, and if $$$x = 10$$$ and ... | int solution() {
int n;
scanf("%d", &n);
int arr[n];
scanf("%d", &arr[0]);
int mx = arr[0];
int mn = arr[0];
for (int i = 1; i < n; i++) {
scanf("%d", &arr[i]);
if (arr[i] > mx) {
mx = arr[i];
}
if (arr[i] < mn) {
mn = arr[i];
}
}
printf("%d", mx - mn + 1 - n);
return... | fn solution() {
let mut buffer = String::new();
let stdin = io::stdin();
let mut handle = stdin.lock();
handle.read_to_string(&mut buffer).expect("stdin");
let arr: Vec<_> = buffer
.split_whitespace()
.map(|x| x.parse::<i64>().unwrap())
.collect();
let n = arr[0] as us... | medium |
1010 | You are given a string $$$s$$$ consisting of the characters 0, 1, and ?.Let's call a string unstable if it consists of the characters 0 and 1 and any two adjacent characters are different (i. e. it has the form 010101... or 101010...).Let's call a string beautiful if it consists of the characters 0, 1, and ?, and you c... | int solution() {
int x;
int y;
int z;
int i;
int j;
int k;
int c;
int n;
int m;
int t;
long long res;
long long a;
long long b;
char s[210210];
scanf("%d", &t);
while (t--) {
res = 0;
scanf("%s", s);
n = strlen(s);
i = a = 0;
for (x = 0; x < n; x++) {
if (s[x]... | fn solution() {
let std_in = stdin();
let in_lock = std_in.lock();
let input = BufReader::new(in_lock);
let std_out = stdout();
let out_lock = std_out.lock();
let mut output = BufWriter::new(out_lock);
let mut lines = input.lines().map(|r| r.unwrap());
let s = lines.next().unwrap();
... | hard |
1011 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>N</var> bricks arranged in a row from left to right.</p>
<p>The <var>i</var>-th brick from the left <var>(1 \leq i \leq N)</var> has an integer <var>a_i</var> written on it.</p>
<p>Among th... | int solution(void) {
int a[200000];
int i = 0;
int N = 0;
int count = 0;
scanf("%d", &N);
while (i < N) {
scanf("%d", &a[i]);
i++;
}
for (i = 0; i < N; i++) {
if (a[i] == count + 1) {
count++;
}
}
if (count == 0) {
printf("%d", -1);
} else {
printf("%d", N - coun... | fn solution() {
let mut s = String::new();
use std::io::Read;
std::io::stdin().read_to_string(&mut s).unwrap();
let mut s = s.split_whitespace();
let n: usize = s.next().unwrap().parse().unwrap();
let remain = s
.map(|a| a.parse().unwrap())
.fold((0, 0), |r, a| if r.1 + 1 == a { ... | medium |
1012 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a staircase with <var>N</var> steps. Takahashi is now standing at the foot of the stairs, that is, on the <var>0</var>-th step.
He can climb up one or two steps at a time.</p>
<p>However, the t... | int solution() {
int N;
int M;
int j = 0;
long long int mod = 1000000007;
scanf("%d%d", &N, &M);
int a[M];
long long int dp[N + 1];
for (int i = 0; i < M; i++) {
scanf("%d", &a[i]);
}
dp[0] = 0;
for (int i = 1; i <= N; i++) {
if (a[j] == i) {
dp[i] = 0;
j++;
} else if (i =... | 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 danger_zone: HashSet<usize> = HashSet::from_iter((0..m).map(|_| {
let mut a = String::new();
s... | medium |
1013 | <span class="lang-en">
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>N</var> pieces of ropes, numbered <var>1</var> through <var>N</var>. The length of piece <var>i</var> is <var>a_i</var>.</p>
<p>At first, for each <var>i (1≤i≤N-1)</var>, piece <var>i</var> and piece <var>i+1</var> are tied at... | int solution() {
int num;
int length;
int arr[100000];
int i;
int check = 0;
int temp;
scanf("%d%d", &num, &length);
for (i = 0; i < num; i++) {
scanf("%d", &arr[i]);
if (i && arr[i - 1] + arr[i] >= length) {
check = 1;
temp = i;
}
}
if (check) {
printf("Possible\n");
... | fn solution() {
let mut s: String = String::new();
stdin().read_to_string(&mut s).ok();
let mut itr = s.split_whitespace();
let n: usize = itr.next().unwrap().parse().unwrap();
let l: usize = itr.next().unwrap().parse().unwrap();
let a: Vec<usize> = (0..n)
.map(|_| itr.next().unwrap().pa... | easy |
1014 | Recently in Divanovo, a huge river locks system was built. There are now $$$n$$$ locks, the $$$i$$$-th of them has the volume of $$$v_i$$$ liters, so that it can contain any amount of water between $$$0$$$ and $$$v_i$$$ liters. Each lock has a pipe attached to it. When the pipe is open, $$$1$$$ liter of water enters th... | int solution() {
int n = 0;
long long v = 0LL;
int q = 0;
long long t = 0LL;
int res = 0;
long long max_t[200000] = {};
long long sum = 0LL;
res = scanf("%d", &n);
for (int i = 0; i < n; i++) {
res = scanf("%lld", &v);
sum += v;
max_t[i] = 1LL + (sum - 1LL) / ((long long)(i + 1));
}
... | fn solution() {
let mut content = String::new();
io::stdin().read_to_string(&mut content);
let mut lines = content.lines();
let n: usize = lines.next().unwrap().parse().unwrap();
let a: Vec<usize> = lines
.next()
.unwrap()
.split(" ")
.map(|token| token.parse::<usize... | hard |
1015 | A bow adorned with nameless flowers that bears the earnest hopes of an equally nameless person.You have obtained the elegant bow known as the Windblume Ode. Inscribed in the weapon is an array of $$$n$$$ ($$$n \ge 3$$$) positive distinct integers (i.e. different, no duplicates are allowed).Find the largest subset (i.e.... | int solution() {
int t;
int i;
scanf("%d", &t);
while (t--) {
int n;
int s = 0;
int c = 0;
int k = 0;
scanf("%d", &n);
int a[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
s = s + a[i];
}
int d = sqrt(s) + 0.5;
for (i = 2; i <= d; i++) {
if (s % i... | fn solution() -> io::Result<()> {
let mut s = String::new();
io::stdin().read_to_string(&mut s)?;
let mut it = s.split_whitespace().map(|s| s.to_string());
let mut out = String::new();
let _case: usize = it.next().unwrap().parse().unwrap();
for _ in 0.._case {
let n: usize = it.next().un... | medium |
1016 | Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.A snake is a pattern on a n by m table. Denote c-th cell of r-th row as (r, c). The tail of the snake is located at (1, 1), then it's body extends to (1, m... | int solution() {
int i = 1;
int j = 0;
int n;
int m;
scanf("%d", &n);
scanf("%d", &m);
while (i <= n) {
if (i % 4 == 0) {
j = 0;
while (j < m) {
if (j == 0) {
printf("#");
} else {
printf(".");
}
j++;
}
} else if (i % 2 == 0 && ... | fn solution() {
let mut line = String::new();
io::stdin().read_line(&mut line).unwrap();
let words: Vec<i64> = line
.split_whitespace()
.map(|x| x.parse().unwrap())
.collect();
let mut n = words[0];
let m = words[1];
let mut direction = true;
while n > 0 {
... | medium |
1017 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation:</p>
<ul>
<li>
<p><var>1</var> yen (the currency of Japan)</p>
... | int solution(void) {
int N;
scanf("%d", &N);
int six[] = {1, 6, 36, 216, 1296, 7776, 46656};
int nine[] = {1, 9, 81, 729, 6561, 59049};
int min = N;
for (int s1 = 0; s1 < 6; s1++) {
for (int s2 = 0; s2 < 6; s2++) {
for (int s3 = 0; s3 < 6; s3++) {
for (int s4 = 0; s4 < 6; s4++) {
... | fn solution() {
input! {
n: usize,
}
let mut ans = n;
for i in 0..n + 1 {
if n < 9 * i {
continue;
}
let r = n - 9 * i;
let j = r / 6;
let k = r % 6;
let mut num = k;
let mut t = i;
while t > 0 {
num += t % ... | medium |
1018 | <H1>Greatest Common Divisor</H1>
<p>
Write a program which finds the greatest common divisor of two natural numbers <i>a</i> and <i>b</i>
</p>
<H2>Input</H2>
<p>
<i>a</i> and <i>b</i> are given in a line sparated by a single space.
</p>
<H2>Output</H2>
<p>
Output the greatest common divisor of <i>a</i> and <i>b</i... | int solution() {
int a = 0;
int b = 0;
scanf("%d%d", &a, &b);
if (a < 1 || a > 1000000000 || b < 1 || b > 1000000000) {
return 0;
}
while (a != b) {
if (a > b) {
a = a - b;
} else {
b = b - a;
}
}
printf("%d\n", a);
return 0;
} | fn solution() {
let stdin = std::io::stdin();
let mut buf = String::new();
stdin.read_line(&mut buf).ok();
let vec: Vec<&str> = buf.split_whitespace().collect();
let mut a: Vec<u32> = vec.iter().map(|&x| x.parse().unwrap_or(0)).collect();
let mut gcd = 1;
let mut d = 2;
loop {
if... | hard |
1019 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>A game is played on a strip consisting of <var>N</var> cells consecutively numbered from 1 to <var>N</var>. </p>
<p>Alice has her token on cell <var>A</var>. Borys has his token on a different cell <var... | int solution() {
int a;
int b;
scanf("%*d %d %d", &a, &b);
printf("%s\n", (b - a) % 2 ? "Borys" : "Alice");
return 0;
} | fn solution() {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).ok();
let v: Vec<usize> = buf.split_whitespace().map(|x| x.parse().unwrap()).collect();
if (v[2] - v[1]).is_multiple_of(2) {
println!("Alice");
} else {
println!("Borys");
}
} | easy |
1020 | <h2>クリスマスパーティー (Christmas Party)</h2>
<h2> 問題</h2>
<p>
JOI 君は友達 1 から友達 N までの N 人の友達を招いてクリスマスパーティーを行った.クリスマスパーティーも盛り上がってきたところで,友達と一緒に次のようなゲームを行うことになった.
</p>
<ol>
<li>
最初に JOI 君は N 人の友達の中から 1 人を選ぶ.以降はその友達をターゲットと呼ぶことにする.
</li>
<li>
JOI 君は,ターゲットとして選んだ友達に,その人がターゲットであることをこっそり伝える.ターゲット以外の友達は,誰がターゲットかを知ることはできない.
</li>
<li>
... | int solution() {
int friends = 0;
int game = 0;
int yosou = 0;
int i = 0;
int j = 0;
int k = 0;
int target[1000] = {0};
int point[1000] = {0};
scanf("%d", &friends);
scanf("%d", &game);
for (i = 0; game > i; i++) {
scanf("%d", &target[i]);
}
for (i = 0; game > i; i++) {
for (j = 1; fri... | 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 = lines.next().unwrap().parse().unwrap();
let m = lines.next().unwrap().parse().unwrap();
let targe... | hard |
1021 | You are given a string $$$s$$$, consisting of $$$n$$$ letters, each letter is either 'a' or 'b'. The letters in the string are numbered from $$$1$$$ to $$$n$$$.$$$s[l; r]$$$ is a continuous substring of letters from index $$$l$$$ to $$$r$$$ of the string inclusive. A string is called balanced if the number of letters '... | int solution(void) {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
char s[n];
scanf("%s", s);
int temp = 0;
for (int i = 0; i < n - 1; i++) {
if ((s[i] == 'a' && s[i + 1] == 'b') ||
(s[i] == 'b' && s[i + 1] == 'a')) {
printf("%d %d", i + 1, i + 2);
... | fn solution() {
let stdin = std::io::stdin();
let mut input = String::new();
stdin.read_line(&mut input).unwrap();
let n = input.trim().parse::<usize>().unwrap();
for _ in 0..n {
input.clear();
stdin.read_line(&mut input).unwrap();
input.clear();
stdin.read_line(&mut ... | medium |
1022 | This is the easy version of the problem. The difference between the versions is that the easy version does not require you to output the numbers of the rods to be removed. You can make hacks only if all versions of the problem are solved.Stitch likes experimenting with different machines with his friend Sparky. Today t... | int solution() {
int t;
int n;
int q;
int l;
int r;
int pre[300001];
int d;
*pre = 0;
scanf("%d", &t);
while (t--) {
scanf("%d %d\n", &n, &q);
for (int i = 0; i < n; i++) {
d = getc(stdin);
pre[i + 1] = pre[i] + ((d == '+') ^ (i & 1)) * 2 - 1;
}
while (q--) {
scanf(... | fn solution() {
let mut line = String::new();
io::stdin().read_line(&mut line).unwrap();
let t: usize = line.trim().parse().unwrap();
line.clear();
let mut subsums: Vec<isize> = Vec::new();
let mut s_buf = String::new();
let mut out_buf = String::new();
for _ in 0..t {
io::stdin(... | medium |
1023 | Selection sort | void solution(int *arr, int size) {
for (int i = 0; i < size - 1; i++) {
int min_index = i;
for (int j = i + 1; j < size; j++) {
if (arr[min_index] > arr[j]) {
min_index = j;
}
}
if (min_index != i) {
int temp = arr[i];
arr[i] = arr[min_index];
arr[min_index] = ... | fn solution<T: Ord>(arr: &mut [T]) {
let len = arr.len();
for left in 0..len {
let mut smallest = left;
for right in (left + 1)..len {
if arr[right] < arr[smallest] {
smallest = right;
}
}
arr.swap(smallest, left);
}
}
| easy |
1024 | <script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
<H1>Watch</H1>
<p>
Write a progr... | int solution(void) {
int S = 0;
scanf("%d", &S);
int h = S / 3600;
int m = (S - h * 3600) / 60;
int s = S - (h * 60 * 60) - (m * 60);
printf("%d:%d:%d\n", h, m, s);
return 0;
} | fn solution() {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
let S = buf.trim().parse::<usize>().unwrap();
println!("{}:{}:{}", S / 3600, S % 3600 / 60, S % 60);
} | easy |
1025 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given three integers <var>A</var>, <var>B</var> and <var>C</var>.
Determine whether <var>C</var> is not less than <var>A</var> and not greater than <var>B</var>.</p>
</section>
</div>
<div class... | int solution() {
int a = 0;
int b = 0;
int c = 0;
scanf("%d%d%d", &a, &b, &c);
if (c >= a && c <= b) {
printf("Yes\n");
} else {
printf("No\n");
}
return 0;
} | fn solution() {
let mut b = String::new();
let _ = std::io::stdin().read_line(&mut b);
let c = b
.split_whitespace()
.map(|i| i.parse().unwrap())
.collect::<Vec<i32>>();
if c[0] <= c[2] && c[2] <= c[1] {
println!("Yes");
} else {
println!("No");
}
} | easy |
1026 | The only difference between easy and hard versions is constraints.There are $$$n$$$ kids, each of them is reading a unique book. At the end of any day, the $$$i$$$-th kid will give his book to the $$$p_i$$$-th kid (in case of $$$i = p_i$$$ the kid will give his book to himself). It is guaranteed that all values of $$$p... | int solution(void) {
int n;
int q;
int *a = calloc(1000002, sizeof(*a));
int *b = calloc(1000002, sizeof(*a));
int *temp = calloc(1000002, sizeof(*temp));
scanf("%d", &q);
for (int j = 0; j < q; j++) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
int k = 1;
... | fn solution() {
let stdin = io::stdin();
let mut input = stdin.lock();
let mut line = String::new();
input.read_line(&mut line).unwrap();
let mut queries: i16 = line.trim().parse().unwrap();
line.clear();
while queries > 0 {
input.read_line(&mut line).unwrap();
let total = li... | hard |
1027 | You're given an array $$$a$$$ of length $$$n$$$. You can perform the following operations on it: choose an index $$$i$$$ $$$(1 \le i \le n)$$$, an integer $$$x$$$ $$$(0 \le x \le 10^6)$$$, and replace $$$a_j$$$ with $$$a_j+x$$$ for all $$$(1 \le j \le i)$$$, which means add $$$x$$$ to all the elements in the prefix en... | int solution() {
int n;
scanf("%d", &n);
int ar[n + 1];
ar[0] = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &ar[i]);
}
printf("%d\n", n + 1);
printf("1 %d %d\n", n, (2 * n) + 1);
for (int i = 1; i <= n; i++) {
printf("2 %d %d\n", i, ar[i] + (2 * n) + 1 - i);
}
return 0;
} | fn solution() {
let mut l1 = String::new();
stdin().read_line(&mut l1);
let n: usize = l1.trim().parse().unwrap();
let mut l2 = String::new();
stdin().read_line(&mut l2);
let l2: Vec<&str> = l2.trim().split(" ").collect();
let mut v: Vec<usize> = Vec::new();
v.push(0);
for x in l2 {... | medium |
1028 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In Takahashi Kingdom, which once existed, there are <var>N</var> cities, and some pairs of cities are connected bidirectionally by roads.
The following are known about the road network:</p>
<ul>
<li>Peo... | int solution(void) {
int n;
scanf("%d", &n);
long long a[n][n];
long long b[n][n];
long long c[n][n];
long long ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
scanf("%lld", &a[i][j]);
b[i][j] = a[i][j];
c[i][j] = 1;
}
}
for (int k = 0; k < n; 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 mut g = vec![vec![0; n]; n];
for i in 0..n {
for j in 0..n {
g[i][j] = itr.next().un... | easy |
1029 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. T... | int solution() {
int n;
scanf("%d", &n);
int arrx[n];
int arry[n];
for (int i = 0; i < n; i++) {
scanf("%d %d", &arrx[i], &arry[i]);
}
int minx = 1000000000;
int miny = 1000000000;
int maxx = -1000000000;
int maxy = -1000000000;
for (int i = 0; i < n; i++) {
if (arrx[i] > maxx) {
max... | fn solution() {
let mut input_text = String::new();
io::stdin()
.read_line(&mut input_text)
.expect("failed to read from stdin");
let n: usize = input_text.trim().parse().unwrap();
let mut min_x: i32 = 0x3f3f3f3f;
let mut min_y: i32 = 0x3f3f3f3f;
let mut max_x: i32 = -0x3f3f3f3f... | medium |
1030 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>AtCoDeer the deer is going on a trip in a two-dimensional plane.
In his plan, he will depart from point <var>(0, 0)</var> at time <var>0</var>, then for each <var>i</var> between <var>1</var> and <var>N... | int solution(void) {
int x = 0;
int y = 1;
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
int f = 0;
int g = 0;
int h = 0;
int i = 0;
scanf("%d", &x);
while (x >= y) {
scanf("%d %d %d", &a, &b, &c);
g = abs(b - e);
h = abs(c - f);
if (a - d < g) {
puts("No");
... | fn solution() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
let n: usize = s.trim().parse().unwrap();
let mut v: Vec<isize> = vec![0; 3];
for _ in 0..n {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
let u: Vec<isize> = s... | easy |
1031 | <h2>A: A-Z-</h2>
<h3>問題</h3>
<p><var>26</var> マスの円環状のボードがあり、各マスには大文字のアルファベット <var>1</var> 文字が、アルファベット順に時計回りに書かれています。すなわち、 'A' のマスの時計回り隣は 'B' のマスで、 'B' のマスの隣は 'C' のマスで、・・・、 'Z' のマスの時計回り隣は 'A' のマスです。</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2017Day3_HUPC2017_aizu17-a-01" type="image/png" ... | int solution() {
int i;
int ans = 0;
char *S = (char *)malloc(sizeof(char) * 102);
S[0] = 'A';
scanf("%s", &S[1]);
for (i = 1; S[i] != '\0'; i++) {
if (S[i] <= S[i - 1]) {
ans++;
}
}
printf("%d\n", ans);
return 0;
} | fn solution() {
input!(S:chars);
let S: Vec<char> = S;
let mut ans = 0;
let mut now: char = 'A';
for i in 0..S.len() {
if S[i] <= now {
ans += 1;
}
now = S[i];
}
println!("{}", ans);
} | easy |
1032 | You are given an array $$$a$$$ of size $$$n$$$. Each element in this array is an integer between $$$1$$$ and $$$10^9$$$.You can perform several operations to this array. During an operation, you can replace an element in the array with any integer between $$$1$$$ and $$$10^9$$$. Output the minimum number of operations ... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int a[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
int cnt = 0;
for (int j = 1; j < n - 1; j++) {
if (a[j] > a[j - 1] && a[j] > a[j + 1]) {
if (j + 2 < n && a[j + 2] > a[j]) {
... | fn solution() {
let mut input = String::new();
io::stdin().read_line(&mut input);
let input: i32 = input.trim().parse().unwrap();
for i in 0..input {
let mut input = String::new();
io::stdin().read_line(&mut input);
let non: i32 = input.trim().parse().unwrap();
let mut ... | medium |
1033 | <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, <var>A_1, A_2, ..., A_N</var>, written on the blackboard.</p>
<p>You will choose one of them and replace it with an integer of your choice between <var>1</var> and <var>... | int solution(void) {
int n;
scanf("%d", &n);
long long int a[n];
long long int min1 = 10000000000;
long long int min2 = 10000000000;
for (int i = 0; i < n; i++) {
scanf("%lld", &a[i]);
if (min2 > a[i]) {
min2 = a[i];
} else if (min1 > a[i]) {
min1 = a[i];
}
}
for (long long i... | fn solution() {
input! {
n: usize,
a: [i64; n],
}
let f = |i| a.iter().filter(|&&a| a % i == 0).count();
let mut ans = 1;
for &a in a[0..2].iter() {
for i in 1.. {
if i * i > a {
break;
}
if a % i == 0 {
if... | medium |
1034 | You have been blessed as a child of Omkar. To express your gratitude, please solve this problem for Omkar!An array $$$a$$$ of length $$$n$$$ is called complete if all elements are positive and don't exceed $$$1000$$$, and for all indices $$$x$$$,$$$y$$$,$$$z$$$ ($$$1 \leq x,y,z \leq n$$$), $$$a_{x}+a_{y} \neq a_{z}$$$ ... | int solution() {
int n = 0;
int t;
scanf("%d", &t);
while (t != 0) {
if (n == 0) {
scanf("%d", &n);
}
if (n > 1) {
printf("1 ");
n--;
}
if (n == 1) {
printf("1 \n");
n--;
t--;
}
}
} | fn solution() {
let stdin = io::stdin();
let mut lines = stdin.lock().lines();
let t: usize = lines.next().unwrap().unwrap().parse().unwrap();
for _ in 0..t {
let n: usize = lines.next().unwrap().unwrap().parse().unwrap();
for _ in 0..n {
print!("1 ");
}
print... | easy |
1035 | <span class="lang-en">
<p>Score: <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p><var>N</var> people are standing in a queue, numbered <var>1, 2, 3, ..., N</var> from front to back. Each person wears a hat, which is red, blue, or green.</p>
<p>The person numbered <var>i</var> says:<... | int solution() {
int n;
scanf("%d", &n);
int i;
int a[100005];
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
long long int p = 1000000007;
long long int dp[100005];
long long int count[100005];
for (i = 0; i < n; i++) {
dp[i] = 0;
}
for (i = 0; i < n; i++) {
count[i] = 0;
}
for... | fn solution() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).ok();
let n: usize = s.trim().parse().ok().unwrap();
let mut t = String::new();
std::io::stdin().read_line(&mut t).ok();
let a: Vec<usize> = t
.split_whitespace()
.map(|e| e.parse().ok().unwrap())
... | medium |
1036 | Given an array of integer $$$a_1, a_2, \ldots, a_n$$$. In one operation you can make $$$a_i := a_i + 1$$$ if $$$i < n$$$ and $$$a_i \leq a_{i + 1}$$$, or $$$i = n$$$ and $$$a_i \leq a_1$$$.You need to check whether the array $$$a_1, a_2, \ldots, a_n$$$ can become equal to the array $$$b_1, b_2, \ldots, b_n$$$ in som... | int solution() {
int t;
scanf("%d", &t);
int n;
for (int j = 0; j < t; j++) {
scanf("%d", &n);
long long b[n];
long long a[n];
int flag = 0;
for (int i = 0; i < n; i++) {
scanf("%lld", &a[i]);
}
for (int i = 0; i < n; i++) {
scanf("%lld", &b[i]);
if (a[i] > b[i]) {
... | fn solution() {
let std_in = stdin();
let mut input = Scanner::new(std_in.lock());
let std_out = stdout();
let mut output = BufWriter::new(std_out.lock());
let t: usize = input.token();
for _ in 0..t {
let n: usize = input.token();
let a: Vec<i32> = (0..n).map(|_| input.token()... | easy |
1037 | Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per c... | int solution(void) {
long long x;
long long y;
long long z;
scanf("%lld %lld %lld", &x, &y, &z);
if (z > 0) {
long long a;
long long b;
long long c;
long long d;
long long e;
long long f;
long long m;
long long mn;
a = x % z;
d = x / z;
b = y % z;
e = y / z;
... | fn solution() {
let mut buffer = String::new();
let stdin = io::stdin();
let mut handle = stdin.lock();
handle.read_to_string(&mut buffer).expect("stdin");
let arr: Vec<_> = buffer
.split_whitespace()
.map(|x| x.parse::<i64>().unwrap())
.collect();
let x = *arr.get(0).... | medium |
1038 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><var>N</var> of us are going on a trip, by train or taxi.</p>
<p>The train will cost each of us <var>A</var> yen (the currency of Japan).</p>
<p>The taxi will cost us a total of <var>B</var> yen.</p>
<p... | int solution(void) {
int a = 0;
int b = 0;
int n = 0;
scanf("%d %d %d", &n, &a, &b);
if (n * a >= b) {
printf("%d", b);
} else {
printf("%d", n * a);
}
} | fn solution() {
let mut line = String::new();
let _ = std::io::stdin().read_line(&mut line);
let vec: Vec<&str> = line.split_whitespace().collect();
let n: i32 = vec[0].parse().unwrap();
let a: i32 = vec[1].parse().unwrap();
let b: i32 = vec[2].parse().unwrap();
println!("{}", std::cmp::min... | medium |
1039 | A permutation of length $$$n$$$ 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 permutation ($$$n=3$$$ but there is... | int solution(void) {
int linenum;
scanf("%d", &linenum);
int len[linenum];
for (int i = 0; i < linenum; i++) {
scanf("\n%d", &len[i]);
}
for (int i = 0; i < linenum; i++) {
for (int j = 0; j < len[i]; j++) {
printf("%d ", j + 1);
}
printf("\n");
}
} | 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 |
1040 | Let's call a binary string $$$T$$$ of length $$$m$$$ indexed from $$$1$$$ to $$$m$$$ paranoid if we can obtain a string of length $$$1$$$ by performing the following two kinds of operations $$$m-1$$$ times in any order : Select any substring of $$$T$$$ that is equal to 01, and then replace it with 1. Select any substri... | int solution() {
int t;
int n;
char s[200001];
scanf("%d", &t);
for (int i = 1; i <= t; i++) {
scanf("%d", &n);
scanf("%s", s);
long long int count = n;
for (int k = 1; k < n; k++) {
if (s[k] == '1' && s[k - 1] == '0') {
count = count + k;
}
if (s[k] == '0' && s[k ... | fn solution() {
let mut content = String::new();
io::stdin().read_to_string(&mut content);
let mut lines = content.lines();
let num_tests: i32 = lines.next().unwrap().parse().unwrap();
for _ in 0..num_tests {
let _n: i32 = lines.next().unwrap().parse().unwrap();
let s: Vec<char> = l... | hard |
1041 | You have $$$r$$$ red and $$$b$$$ blue beans. You'd like to distribute them among several (maybe, one) packets in such a way that each packet: has at least one red bean (or the number of red beans $$$r_i \ge 1$$$); has at least one blue bean (or the number of blue beans $$$b_i \ge 1$$$); the number of red and blue b... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int r;
int b;
int d;
scanf("%d%d%d", &r, &b, &d);
if ((r == b && d >= 0) || (r == 1 && b > 1 && d >= b - r) ||
(b == 1 && r > 1 && d >= r - b)) {
printf("YES\n");
} else if (r > 1 && b > 1 && b > r) {
if ((b % r == ... | fn solution() {
let mut buff = String::new();
io::stdin().read_line(&mut buff).unwrap();
let t = buff.trim().parse::<u16>().unwrap();
for _ in 0..t {
buff = String::new();
io::stdin().read_line(&mut buff).unwrap();
let v = buff
.split_whitespace()
.map(|x|... | medium |
1042 | You are given two integers $$$x$$$ and $$$y$$$ (it is guaranteed that $$$x > y$$$). You may choose any prime integer $$$p$$$ and subtract it any number of times from $$$x$$$. Is it possible to make $$$x$$$ equal to $$$y$$$?Recall that a prime number is a positive integer that has exactly two positive divisors: $$$1$... | int solution() {
long long n;
long long m;
scanf("%lld", &n);
while (scanf("%lld%lld", &n, &m) == 2) {
printf(n - m == 1 ? "NO\n" : "YES\n");
}
} | fn solution() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
let t = s.trim().parse::<i64>().unwrap();
for _ in 0..t {
s.clear();
std::io::stdin().read_line(&mut s).unwrap();
let vec = s
.split_whitespace()
.map(|x| x.parse::<i6... | medium |
1043 | For some binary string $$$s$$$ (i.e. each character $$$s_i$$$ is either '0' or '1'), all pairs of consecutive (adjacent) characters were written. In other words, all substrings of length $$$2$$$ were written. For each pair (substring of length $$$2$$$), the number of '1' (ones) in it was calculated.You are given three ... | int solution() {
int t;
int i;
int a;
int b;
int c;
int j;
scanf("%d", &t);
while (t--) {
j = 1;
scanf("%d%d%d", &a, &b, &c);
for (i = 0; i <= a && a != 0; i++) {
printf("0");
}
if (a == 0 && b != 0) {
printf("0");
}
for (i = 0; i < b - 1; i++) {
if (i == b ... | fn solution() -> io::Result<()> {
let mut input = String::new();
io::stdin().read_line(&mut input)?;
let n = input.trim().parse().unwrap();
for _ in 0..n {
input.clear();
io::stdin().read_line(&mut input)?;
let numbers: Vec<u8> = input
.trim()
.split(" "... | medium |
1044 | You have an $$$n \times n$$$ chessboard and $$$k$$$ rooks. Rows of this chessboard are numbered by integers from $$$1$$$ to $$$n$$$ from top to bottom and columns of this chessboard are numbered by integers from $$$1$$$ to $$$n$$$ from left to right. The cell $$$(x, y)$$$ is the cell on the intersection of row $$$x$$$ ... | int solution() {
int N;
scanf("%d", &N);
int chess[N][2];
for (int i = 0; i < N; i++) {
for (int j = 0; j < 2; j++) {
scanf("%d", &chess[i][j]);
}
}
for (int k = 0; k < N; k++) {
int count = 0;
if (chess[k][1] <= ceil(chess[k][0] / 2.0)) {
for (int i = 0; i < chess[k][0]; i++) ... | fn solution() {
let mut handle = std::io::BufWriter::new(std::io::stdout());
let mut test_no = String::new();
std::io::stdin().read_line(&mut test_no).unwrap();
let test_no: u8 = test_no.trim().parse().unwrap();
for _ in 0..test_no {
let mut string = String::new();
std::io::stdin().r... | medium |
1045 | Bajtek, known for his unusual gifts, recently got an integer array $$$x_0, x_1, \ldots, x_{k-1}$$$.Unfortunately, after a huge array-party with his extraordinary friends, he realized that he'd lost it. After hours spent on searching for a new toy, Bajtek found on the arrays producer's website another array $$$a$$$ of l... | int solution() {
int n;
int a = 0;
int ai;
int c = 0;
scanf("%d", &n);
int A[n];
int R[n];
for (int i = 0; i < n; i++) {
scanf("%d", &ai);
A[i] = ai - a;
a = ai;
}
for (int k = 1; k <= n; k++) {
char p = 1;
for (int i = k; i < n; i++) {
if (A[i % k] != A[i]) {
p = ... | fn solution() {
let sin = io::stdin();
let mut f = sin.lock();
let mut buf = String::new();
f.read_line(&mut buf).unwrap();
let n: usize = buf.trim().parse().unwrap();
buf = "".to_string();
f.read_line(&mut buf).unwrap();
let mut a = Vec::<i32>::new();
a.push(0i32);
for p in buf.... | medium |
1046 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>A programming competition site <em>AtCode</em> regularly holds programming contests.</p>
<p>The next contest on AtCode is called ABC, which is rated for contestants with ratings less than <var>1200</var... | int solution() {
int R = 0;
scanf("%d", &R);
if (R < 1200) {
printf("ABC");
} else if (1200 <= R && R < 2800) {
printf("ARC");
} else if (2800 <= R) {
printf("AGC");
}
return 0;
} | fn solution() {
let stdin = io::stdin();
let mut s = String::new();
stdin.read_line(&mut s).ok();
s.pop();
let r = u32::from_str(&s).expect("e");
if r < 1200 {
println!("ABC");
} else if r < 2800 {
println!("ARC");
} else {
println!("AGC");
}
} | easy |
1047 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Cat Snuke is learning to write characters.
Today, he practiced writing digits <code>1</code> and <code>9</code>, but he did it the other way around.</p>
<p>You are given a three-digit integer <var>n</va... | int solution() {
int due = 0;
int a = 0;
int b = 0;
int c = 0;
scanf("%d", &due);
a = due / 100;
b = (due - a * 100) / 10;
c = (due - a * 100 - b * 10) / 1;
a = 10 - a;
b = 10 - b;
c = 10 - c;
printf("%d", (a * 100) + (b * 10) + c);
return 0;
} | fn solution() {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).ok();
let s = buf.trim();
let mut v: Vec<char> = s.chars().collect();
for i in &mut v {
if *i == '1' {
*i = '9';
} else if *i == '9' {
*i = '1';
}
}
println! {... | hard |
1048 | Wabbit is trying to move a box containing food for the rest of the zoo in the coordinate plane from the point $$$(x_1,y_1)$$$ to the point $$$(x_2,y_2)$$$.He has a rope, which he can use to pull the box. He can only pull the box if he stands exactly $$$1$$$ unit away from the box in the direction of one of two coordina... | int solution() {
int n;
int a;
int b;
int c;
int d;
int sum = 0;
scanf("%d\n", &n);
while (n--) {
sum = 0;
scanf("%d %d %d %d\n", &a, &b, &c, &d);
if (a > c) {
sum += a - c;
} else {
sum += c - a;
}
if (b > d) {
sum += b - d;
} else {
sum += d - b;
... | fn solution() {
let mut str = String::new();
let _ = stdin().read_line(&mut str).unwrap();
let test: i64 = str.trim().parse().unwrap();
for _ in 0..test {
str.clear();
let _ = stdin().read_line(&mut str).unwrap();
let mut iter = str.split_whitespace();
let x1: i64 = iter.... | medium |
1049 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi has decided to work on <var>K</var> days of his choice from the <var>N</var> days starting with tomorrow.</p>
<p>You are given an integer <var>C</var> and a string <var>S</var>. Takahashi will... | int solution() {
int n;
int k;
int c;
scanf("%d%d%d", &n, &k, &c);
char s[n + 5];
scanf("%s", s);
int cnt[n + 1];
int j = INT_MAX;
cnt[n] = 0;
for (int i = n - 1; i >= 0; i--) {
if (s[i] == 'x' || j - i < c + 1) {
cnt[i] = cnt[i + 1];
} else {
cnt[i] = cnt[i + 1] + 1;
j = i... | fn solution() {
let stdin = std::io::stdin();
let stdout = std::io::stdout();
let mut reader = std::io::BufReader::new(stdin.lock());
let mut writer = std::io::BufWriter::new(stdout.lock());
let (n, k, c): (usize, usize, usize) = {
let mut buf = String::new();
reader.read_line(&mut ... | easy |
1050 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Print the <var>K</var>-th element of the following sequence of length <var>32</var>:</p>
<pre>1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
</pre>
</s... | int solution() {
int in[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int innum = 0;
scanf("%d", &innum);
if (innum > 0 && innum <= 32) {
printf("%d\n", in[innum - 1]);
}
return 0;
} | fn solution() {
let array = [
1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4,
1, 51,
];
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("Failed to read line");
let index: usize = input.trim().pars... | medium |
1051 | <h1>Red Dragonfly</h1>
<p>
It’s still hot every day, but September has already come. It’s autumn according to the calendar. Looking around, I see two red dragonflies at rest on the wall in front of me. It’s autumn indeed.
</p>
<p>
When two red dragonflies’ positional information as measured from the end of the w... | int solution() {
int x1 = 0;
int x2 = 0;
int X = 0;
scanf("%d %d\n", &x1, &x2);
if (((0 <= x1) && (x1 <= 100)) && ((0 <= x2) && (x2 <= 100))) {
if (x1 > x2) {
X = x1 - x2;
} else {
X = x2 - x1;
}
printf("%d\n", X);
}
return 0;
} | fn solution() {
let stdin = stdin();
let line = stdin.lock().lines().next().unwrap().unwrap();
let mut iter = line.split_whitespace().map(|s| s.parse::<i32>().unwrap());
let (a, b) = (iter.next().unwrap(), iter.next().unwrap());
println!("{}", (a - b).abs());
} | medium |
1052 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi is going to buy <var>N</var> items one by one.</p>
<p>The price of the <var>i</var>-th item he buys is <var>A_i</var> yen (the currency of Japan).</p>
<p>He has <var>M</var> discount tickets, ... | int solution(void) {
int n;
int m;
int a[200000] = {0};
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
int ind = i;
while (ind > 0 && a[ind] > a[(ind - 1) / 2]) {
int temp = a[ind];
a[ind] = a[(ind - 1) / 2];
a[(ind - 1) / 2] = temp;
ind = (ind - ... | fn solution() {
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).ok();
let mut it = buf.split_whitespace();
let n = it.next().unwrap().parse::<usize>().unwrap();
let m = it.next().unwrap().parse::<usize>().unwrap();
let a = (0..n)
.map(|_| it.next().unwrap().parse::... | medium |
1053 | Riley is a very bad boy, but at the same time, he is a yo-yo master. So, he decided to use his yo-yo skills to annoy his friend Anton.Anton's room can be represented as a grid with $$$n$$$ rows and $$$m$$$ columns. Let $$$(i, j)$$$ denote the cell in row $$$i$$$ and column $$$j$$$. Anton is currently standing at positi... | int solution() {
short int t;
scanf("%hd", &t);
int arr[t][4];
for (short int i = 0; i < t; i++) {
for (short int j = 0; j < 4; j++) {
scanf("%d", &arr[i][j]);
}
}
for (int i = 0; i < t; i++) {
printf("%d %d %d %d\n", arr[i][0], 1, 1, arr[i][1]);
}
return 0;
} | fn solution() {
let std_in = stdin();
let in_lock = std_in.lock();
let input = BufReader::new(in_lock);
let std_out = stdout();
let out_lock = std_out.lock();
let mut output = BufWriter::new(out_lock);
let mut lines = input.lines().map(|r| r.unwrap());
let s = lines.next().unwrap();
... | hard |
1054 | Berland crossword is a puzzle that is solved on a square grid with $$$n$$$ rows and $$$n$$$ columns. Initially all the cells are white.To solve the puzzle one has to color some cells on the border of the grid black in such a way that: exactly $$$U$$$ cells in the top row are black; exactly $$$R$$$ cells in the right... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
int u;
int r;
int d;
int l;
bool f = 1;
scanf("%d %d %d %d %d", &n, &u, &r, &d, &l);
while (1) {
if (u == n || d == n) {
if (r == 0 || l == 0) {
f = 0;
break;
}
}
... | fn solution() {
let mut input = String::new();
stdin().read_to_string(&mut input).unwrap();
let mut it = input
.split_whitespace()
.map(|x| x.parse::<usize>().unwrap());
let _t = it.next();
'outer: while let Some(n) = it.next() {
let u = it.next().unwrap();
let r =... | medium |
1055 | Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of a-s and others — a gr... | int solution() {
char a[100000];
int i;
int sum = 0;
int k = 0;
int m = 0;
int b[30] = {0};
int p = 0;
int c[30];
int j = 0;
scanf("%s", a);
k = strlen(a);
for (i = 0; i < k; i++) {
b[a[i] - 'a']++;
}
for (i = 0; i <= 26; i++) {
if (b[i] > 0) {
p++;
}
}
if (p > 4) {
... | fn solution() {
let mut input = String::new();
use std::io::{self, prelude::*};
io::stdin().read_to_string(&mut input).unwrap();
let mut a = [0; 26];
let mut uc = 0;
let mut tc = 0;
let s = input.trim();
for i in s.bytes().map(|b| (b - b'a') as usize) {
if a[i] == 0 {
... | easy |
1056 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><font color="red"><strong>This is an interactive task.</strong></font></p>
<p>Let <var>N</var> be an odd number at least <var>3</var>.</p>
<p>There are <var>N</var> seats arranged in a circle.
The seats... | int solution() {
long n;
scanf("%ld", &n);
char s[100001][7];
printf("0\n");
fflush(stdout);
scanf("%s", s[0]);
if (s[0][0] == 'V') {
return 0;
}
int i;
long min = 0;
long max = n;
for (i = 1; i < 19; i++) {
printf("%ld\n", (max + min) / 2);
fflush(stdout);
scanf("%s", s[(max + m... | fn solution() {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
let n: usize = buf.trim().parse().unwrap();
println!("0");
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
let mut start = buf.trim().to_string();
if start == "Vacant... | medium |
1057 | Bessie has way too many friends because she is everyone's favorite cow! Her new friend Rabbit is trying to hop over so they can play! More specifically, he wants to get from $$$(0,0)$$$ to $$$(x,0)$$$ by making multiple hops. He is only willing to hop from one point to another point on the 2D plane if the Euclidean dis... | int solution() {
int t;
int n;
int x;
scanf("%d", &t);
while (t-- > 0) {
scanf("%d%d", &n, &x);
int arr[n];
int count = INT_MAX;
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
for (int i = n - 1; i >= 0 && x > 0; i--) {
int temp = x >= arr[i] ? (x + arr[i] - 1) / arr... | fn solution() {
let t = {
let mut buf = String::new();
stdin().read_line(&mut buf).expect("Failed to read line");
buf.trim().parse::<i32>().unwrap()
};
for _ in 0..t {
let (_, x) = {
let mut buf = String::new();
stdin().read_line(&mut buf).expect("Fail... | medium |
1058 | There are $$$n$$$ boxes with different quantities of candies in each of them. The $$$i$$$-th box has $$$a_i$$$ candies inside.You also have $$$n$$$ friends that you want to give the candies to, so you decided to give each friend a box of candies. But, you don't want any friends to get upset so you decided to eat some (... | int solution() {
int arr[52];
int acc[1001];
int i = 0;
int j = 0;
int k = 0;
int o = 0;
int min = 100000000;
int sum = 0;
scanf("%d", &j);
for (i = 0; i < j; i++) {
scanf("%d", &k);
for (o = 0; o < k; o++) {
scanf("%d", &arr[o]);
if (arr[o] < min) {
min = arr[o];
}... | fn solution() {
let mut input = String::new();
stdin().read_to_string(&mut input).ok();
let mut output = String::new();
let mut input = input.split_ascii_whitespace().flat_map(str::parse);
let t: usize = input.next().unwrap();
for _ in 0..t {
let n = input.next().unwrap();
let a:... | medium |
1059 | <span class="lang-en">
<p>Score: <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens.</p>
<p>There are <var>N</var> ... | int solution() {
int n;
scanf("%d", &n);
static int a[200003];
static int conne[200003][2];
for (int i = 1; i <= n; i++) {
conne[i][0] = conne[i][1] = 0;
}
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (i + a[i] <= n) {
conne[i + a[i]][0]++;
}
if (i - a[i] > 1) {
... | fn solution() {
let mut line = String::new();
let stdin = std::io::stdin();
let _ = stdin.read_line(&mut line);
line.clear();
let _ = stdin.read_line(&mut line);
let a: Vec<_> = line
.split_whitespace()
.map(|x| x.parse::<i64>().unwrap())
.collect();
let (mut map1, mu... | hard |
1060 | You are given an array $$$a$$$ of size $$$n$$$.You can perform the following operation on the array: Choose two different integers $$$i, j$$$ $$$(1 \leq i < j \leq n$$$), replace $$$a_i$$$ with $$$x$$$ and $$$a_j$$$ with $$$y$$$. In order not to break the array, $$$a_i | a_j = x | y$$$ must be held, where $$$|$$$ ... | int solution(void) {
int t = 0;
scanf("%d", &t);
while (t--) {
int n = 0;
scanf("%d", &n);
int a[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
int or = a[0];
for (int i = 1; i < n; i++) {
or = or | a[i];
}
printf("%d\n", or);
}
return 0;
} | fn solution() {
let mut input = String::new();
io::stdin().read_line(&mut input);
let T: i32 = input.trim().parse().unwrap();
for _i in 0..T {
let mut input = String::new();
io::stdin().read_line(&mut input);
let n: usize = input.trim().parse().unwrap();
let mut input =... | medium |
1061 | <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> sightseeing spots on the <var>x</var>-axis, numbered <var>1, 2, ..., N</var>.
Spot <var>i</var> is at the point with coordinate <var>A_i</var>.
It costs <var>|a - b|</var> yen (th... | int solution() {
int points = 0;
int diff = 0;
int diff2 = 0;
int total = 0;
int cnt = 0;
int p[100002] = {0};
scanf("%d", &points);
while (cnt < points) {
scanf("%d", &p[cnt + 1]);
diff = p[cnt + 1] - p[cnt];
if (diff < 0) {
diff = diff * -1;
}
total = total + diff;
cn... | fn solution() {
let mut buf = String::new();
io::stdin().read_line(&mut buf).unwrap();
let n = buf.trim().parse::<usize>().unwrap();
let mut buf = String::new();
io::stdin().read_line(&mut buf).unwrap();
let mut an = vec![0];
let iter = buf.split_whitespace();
for it in iter {
a... | medium |
1062 | Maria is the most active old lady in her house. She was tired of sitting at home. She decided to organize a ceremony against the coronavirus.She has $$$n$$$ friends who are also grannies (Maria is not included in this number). The $$$i$$$-th granny is ready to attend the ceremony, provided that at the time of her appea... | int solution() {
long y;
long x;
scanf("%ld", &x);
long a[100000];
long B[100000];
for (y = 0; y < x; y++) {
long i;
long n;
long k = 0;
scanf("%ld\n", &n);
for (i = 0; i < n; i++) {
scanf("%ld", &a[i]);
if (a[i] > n) {
i--;
n--;
}
}
for (i = 0;... | fn solution() {
let mut s: String = String::new();
std::io::stdin().read_to_string(&mut s).ok();
let mut itr = s.split_whitespace();
let t: usize = itr.next().unwrap().parse().unwrap();
for _ in 0..t {
let n: usize = itr.next().unwrap().parse().unwrap();
let mut a: Vec<usize> = (0..... | hard |
1063 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi is playing with <var>N</var> cards.</p>
<p>The <var>i</var>-th card has an integer <var>X_i</var> on it.</p>
<p>Takahashi is trying to create as many pairs of cards as possible satisfying one ... | int solution() {
int n;
int m;
scanf("%d %d", &n, &m);
int i;
int x[100005];
for (i = 0; i < n; i++) {
scanf("%d", &x[i]);
}
int a[100005];
for (i = 0; i < 100005; i++) {
a[i] = 0;
}
for (i = 0; i < n; i++) {
a[x[i]]++;
}
int b[100005];
for (i = 0; i <= m; i++) {
b[i] = 0;
... | 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 m: usize = itr.next().unwrap().parse().unwrap();
let mut x: Vec<usize> = (0..n)
.map(|_| itr.next(... | medium |
1064 | <span class="lang-en">
<p>Score: <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>The weather in Takahashi's town changes day by day, in the following cycle: Sunny, Cloudy, Rainy, Sunny, Cloudy, Rainy, ...</p>
<p>Given is a string <var>S</var> representing the weather in the town tod... | int solution() {
char s1[7] = {'S', 'u', 'n', 'n', 'y'};
char s2[7] = {'C', 'l', 'o', 'u', 'd', 'y'};
char s3[7] = {'R', 'a', 'i', 'n', 'y'};
char n[7] = {0};
scanf("%s", n);
if (*n == *s1) {
puts(s2);
} else if (*n == *s2) {
puts(s3);
} else if (*n == *s3) {
puts(s1);
} else {
retur... | fn solution() {
let mut w = String::new();
io::stdin().read_line(&mut w).expect("Failed to read line");
let w_str: &str = &w;
match w_str {
"Sunny\n" => println!("Cloudy"),
"Cloudy\n" => println!("Rainy"),
"Rainy\n" => println!("Sunny"),
_ => println!("retry enter!"),
... | hard |
1065 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi is a member of a programming competition site, <em>ButCoder</em>.</p>
<p>Each member of ButCoder is assigned two values: <strong>Inner Rating</strong> and <strong>Displayed Rating</strong>.</p... | int solution(void) {
int N = 0;
int R = 0;
scanf("%d %d", &N, &R);
if (N < 10) {
R = R + 100 * (10 - N);
}
printf("%d\n", R);
return 0;
} | fn solution() {
let mut buf = String::new();
io::stdin()
.read_line(&mut buf)
.expect("Failed to read line");
let vec_1: Vec<&str> = buf.split_whitespace().collect();
let n: i32 = vec_1[0].parse().unwrap_or(0);
let r: i32 = vec_1[1].parse().unwrap_or(0);
let ans = if n >= 10 { r... | easy |
1066 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>A sequence <var>a=\{a_1,a_2,a_3,......\}</var> is determined as follows:</p>
<ul>
<li>
<p>The first term <var>s</var> is given as input.</p>
</li>
<li>
<p>Let <var>f(n)</var> be the following function: ... | int solution() {
int s = 0;
scanf("%d", &s);
int count[1000000];
for (int i = 0; i < 1000000; i++) {
count[i] = 0;
}
int buf = s;
int ans = 0;
while (1) {
count[buf]++;
ans++;
if (count[buf] > 1) {
break;
}
if (buf % 2 == 0) {
buf = buf / 2;
} else {
buf = 3... | fn solution() {
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).unwrap();
let mut iter = buf.split_whitespace();
let s: usize = iter.next().unwrap().parse().unwrap();
let mut a: Vec<usize> = vec![s];
let mut prev = s;
if s == 1 || s == 2 || s == 4 {
printl... | medium |
1067 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>On the Planet AtCoder, there are four types of bases: <code>A</code>, <code>C</code>, <code>G</code> and <code>T</code>. <code>A</code> bonds with <code>T</code>, and <code>C</code> bonds with <code>G</... | int solution(void) {
char s[1];
scanf("%s", s);
if (*s == 'A') {
puts("T");
} else if (*s == 'T') {
puts("A");
} else if (*s == 'C') {
puts("G");
} else if (*s == 'G') {
puts("C");
}
return 0;
} | fn solution() {
let mut b = String::new();
std::io::stdin().read_line(&mut b).expect("failed");
let s = b.trim();
match s {
"A" => println!("T"),
"T" => println!("A"),
"C" => println!("G"),
"G" => println!("C"),
_ => println!("_"),
}
} | medium |
1068 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Some number of chocolate pieces were prepared for a training camp.
The camp had <var>N</var> participants and lasted for <var>D</var> days.
The <var>i</var>-th participant (<var>1 \leq i \leq N</var>) a... | int solution(void) {
static int n;
static int d;
static int x;
scanf("%d%d%d", &n, &d, &x);
for (int i = 0; i < n; i++) {
int a[i];
scanf("%d", &a[i]);
x += ((d - 1) / a[i]) + 1;
}
printf("%d\n", x);
return 0;
} | 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 l: i32 = vec[0].parse().unwrap();
let scan = std::io::stdin();
let mut line = String::new();
let _ = scan.read_line(&... | hard |
1069 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a tree with <var>N</var> vertices and <var>N-1</var> edges, respectively numbered <var>1, 2,\cdots, N</var> and <var>1, 2, \cdots, N-1</var>. Edge <var>i</var> connects Vertex <var>u_i</var> and... | int solution() {
int i;
int N;
int u;
int w;
long long ans = 0;
long long tmp;
scanf("%d", &N);
for (i = 1; i <= N; i++) {
ans += (long long)(N - i + 2) * (N - i + 1) / 2;
}
for (i = 1; i <= N - 1; i++) {
scanf("%d %d", &u, &w);
if (u > w) {
u ^= w;
w ^= u;
u ^= w;
... | fn solution() {
let n: usize = {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
buf.trim_end().parse().unwrap()
};
let mut ans = 0;
for i in 1..=n {
ans += i * (n - i + 1);
}
for _ in 0..(n - 1) {
let [u, v]: [usize; 2] = {
... | medium |
1070 | Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing nu... | int solution() {
int x = 0;
int n = 0;
int m = 0;
scanf("%d %d", &n, &m);
if (n > m + 1 || m > n * 2 + 2) {
printf("-1");
return 0;
}
while (n + m) {
if (x < 2 && m >= n) {
printf("1");
m--;
x++;
} else {
printf("0");
x = 0;
n--;
}
}
return 0;... | fn solution() {
let mut line = String::new();
io::stdin().read_line(&mut line).unwrap();
let words: Vec<i64> = line
.split_whitespace()
.map(|x| x.parse().unwrap())
.collect();
let mut n = words[0];
let mut m = words[1];
let mut ans = String::new();
while m > n &... | medium |
1071 | Given an array $$$a$$$ of length $$$n$$$, find another array, $$$b$$$, of length $$$n$$$ such that: for each $$$i$$$ $$$(1 \le i \le n)$$$ $$$MEX(\{b_1$$$, $$$b_2$$$, $$$\ldots$$$, $$$b_i\})=a_i$$$. The $$$MEX$$$ of a set of integers is the smallest non-negative integer that doesn't belong to this set.If such array do... | int solution() {
long long int n;
scanf("%lld", &n);
long long int i;
long long int a[n];
for (i = 0; i < n; ++i) {
scanf("%lld", &a[i]);
}
long long int *isin =
(long long int *)malloc((pow(10, 6) + 1) * sizeof(long long int));
long long int *sol = (long long int *)malloc(n * sizeof(long l... | fn solution() {
let stdin = io::stdin();
let mut lines = stdin.lock().lines();
let n: usize = lines.next().unwrap().unwrap().parse().unwrap();
let xs: Vec<i32> = lines
.next()
.unwrap()
.unwrap()
.split(' ')
.map(|x| x.parse().unwrap())
.collect();
let... | medium |
1072 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a string <var>S</var> of length <var>2</var> or <var>3</var> consisting of lowercase English letters. If the length of the string is <var>2</var>, print it as is; if the length is <var>3</... | int solution(void) {
char S[5];
scanf("%s", &S[0]);
if (strlen(S) == 2) {
printf("%c%c", S[0], S[1]);
return 0;
}
if (strlen(S) == 3) {
printf("%c%c%c", S[2], S[1], S[0]);
return 0;
}
} | fn solution() {
let mut stdin = String::new();
std::io::Read::read_to_string(&mut std::io::stdin(), &mut stdin).unwrap();
let mut stdin = stdin.split_whitespace();
let mut get = || stdin.next().unwrap();
let s = get().as_bytes();
if s.len() == 2 {
print!("{}", s[0] as char);
pr... | medium |
1073 | This is yet another problem dealing with regular bracket sequences.We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not. Y... | int solution() {
char string[10009001];
fgets(string, 10090001, stdin);
int len = strlen(string);
int stack[10000001];
stack[0] = -1;
int top = 0;
int max_len = 0;
int temp_len = 0;
int count = 0;
for (int i = 0; i < len - 1; i++) {
if (string[i] == '(') {
stack[++top] = i;
} else {
... | fn solution() {
let line = io::stdin().lock().lines().next().unwrap().unwrap();
let mut cnt = 1;
let mut max = 0;
let mut xs: Vec<i64> = vec![-1];
for (i, &c) in line.as_bytes().to_vec().iter().enumerate() {
if c == b'(' {
xs.push(i as i64);
} else if xs.len() > 1 {
... | easy |
1074 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> squares aligned in a row.
The <var>i</var>-th square from the left contains an integer <var>a_i</var>.</p>
<p>Initially, all the squares are white.
Snuke will perform the followin... | int solution(void) {
int n;
int k;
scanf("%d%d", &n, &k);
int a[n];
long long ans = 0;
long long plus[n + 1];
long long all = 0;
long long sum = 0;
long long tmp;
plus[0] = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (a[i] > 0) {
all += a[i];
plus[i + 1] = plus[i] +... | fn solution() {
let (N, K): (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(),
... | hard |
1075 | Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...$$$n$$$ friends live in a city which can be represented as a number line. The $$$i$$$-th friend lives in a house with an integer coordinate $$$x_i$$$. The $$$i$$$-th friend can come celebrate the New Year to the ... | int solution() {
long n;
int i;
scanf("%ld", &n);
int *p = (int *)malloc((n + 4) * sizeof(int));
for (i = 0; i <= n + 1; i++) {
p[i] = 0;
}
for (i = 0; i < n; i++) {
int temp;
scanf("%d", &temp);
p[temp]++;
}
long min = 0;
long max = 0;
for (i = 1; i <= n; i++) {
if (p[i] >= 1)... | fn solution() {
let is_print = false;
let mut input_str = String::new();
let mut friend_count = 0_usize;
match io::stdin().read_line(&mut input_str) {
Ok(_n) => {
if input_str.as_str() == "" {
panic!("friend count number");
}
friend_count = i... | hard |
1076 | The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.At some points on the road there are n friends, and i-th of them is standing at the point xi meters and can move with any speed no greater than vi me... | int solution() {
int n = 0;
scanf("%d", &n);
int a[n + 1];
int b[n + 1];
for (int i = 0; i < n; i++) {
a[i] = 0;
b[i] = 0;
}
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i < n; i++) {
scanf("%d", &b[i]);
}
int north = 0;
int south = 0;
double time;
if (... | fn solution() {
let mut s = String::new();
io::stdin().read_line(&mut s).expect("");
let n = s.trim().parse::<usize>().unwrap();
let mut input = io::stdin();
let reader = BufReader::new(&mut input);
let mut line = reader.lines().map(|a| a.expect(""));
let a: Vec<f64> = line
.next(... | hard |
1077 | The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair... | int solution() {
int g[103] = {0};
int b[103] = {0};
int j;
int r = 0;
int i;
int c;
scanf("%d", &c);
for (i = 0; i < c; i++) {
scanf("%d", &j), b[j]++;
}
scanf("%d", &c);
for (i = 0; i < c; i++) {
scanf("%d", &j), g[j]++;
}
for (i = 1, r = 0; i < 101; i++) {
while (b[i - 1] && g[i... | fn solution() {
let mut input = stdin();
let _output = stdout();
let mut buffer = [0; 4 * 2 * 100 + 100];
let mut boys_girls = [0; 202];
let len = input.read(&mut buffer).unwrap();
let mut mi = 0;
let mut pos = 0;
let mut skip = true;
let (mut n_s, mut n_e) = (0, 0);
let mut num... | medium |
1078 | You are given a text consisting of n lines. Each line contains some space-separated words, consisting of lowercase English letters.We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowels: '... | int solution() {
int N;
int P[100];
char Str[103];
scanf("%d", &N);
for (int i = 0; i < N; ++i) {
scanf("%d", &P[i]);
}
scanf("\n");
for (int i = 0; i < N; ++i) {
fgets(Str, 102, stdin);
int cnt = 0;
for (int j = 0; Str[j] != '\0'; ++j) {
if (Str[j] == 'a' || Str[j] == 'e' || Str[j... | fn solution() {
let mut line = String::new();
io::stdin().read_line(&mut line).unwrap();
let tokens: Vec<&str> = line.split_whitespace().collect();
let n = tokens[0].parse().unwrap();
let mut line = String::new();
io::stdin().read_line(&mut line).unwrap();
let tokens: Vec<&str> = line.split... | easy |
1079 | Mainak has an array $$$a_1, a_2, \ldots, a_n$$$ of $$$n$$$ positive integers. He will do the following operation to this array exactly once: Pick a subsegment of this array and cyclically rotate it by any amount. Formally, he can do the following exactly once: Pick two integers $$$l$$$ and $$$r$$$, such that $$$1 \l... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int A[n];
int ans = 0;
for (int i = 0; i < n; i++) {
scanf("%d", A + i);
}
for (int i = 0; i < n; i++) {
int k = A[i] - A[(i + 1) % n];
int k0 = A[i] - A[0];
int kn = A[n - 1] - A[i];... | fn solution() {
let mut input_line = String::new();
io::stdin().read_line(&mut input_line).unwrap();
let t: i32 = input_line.trim().parse().unwrap();
for _ in 0..t {
input_line.clear();
io::stdin().read_line(&mut input_line).unwrap();
input_line.clear();
std::io::stdin().... | medium |
1080 | During a daily walk Alina noticed a long number written on the ground. Now Alina wants to find some positive number of same length without leading zeroes, such that the sum of these two numbers is a palindrome. Recall that a number is called a palindrome, if it reads the same right to left and left to right. For exampl... | int solution() {
int t;
scanf("%d\n", &t);
while (t--) {
int n;
scanf("%d\n", &n);
char a[n];
char c[n + 1];
int b[n];
scanf("%s\n", a);
if (a[0] != 57) {
for (int i = 0; i < n; i++) {
printf("%d", 57 - a[i]);
}
printf("\n");
} else {
for (int i = 0;... | fn solution() {
let mut buffer = String::new();
stdin().read_to_string(&mut buffer).unwrap();
let input_params: Vec<&str> = buffer.split_whitespace().collect();
let mut param_iter = input_params.iter();
let t = param_iter.next().unwrap().parse::<u32>().unwrap();
for _i in 0..t {
let n =... | medium |
1081 | <h1>幹線道路 (Trunk Road)</h1>
<h2>問題文</h2>
<p>
JOI 市は,東西方向にまっすぐに伸びる <var>H</var> 本の道路と,南北方向にまっすぐに伸びる <var>W</var> 本の道路によって,碁盤の目の形に区分けされている.道路と道路の間隔は <var>1</var> である.JOI 市では,これら <var>H+W</var> 本の道路から,東西方向に <var>1</var> 本,南北方向に <var>1</var> 本,合計 <var>2</var> 本の道路を幹線道路として選ぶことになった.</p>
<p>
北から <var>i</var> 本目 (<var>1≦i≦H</... | int solution(void) {
int H;
int W;
int A[101][101];
int b;
int c;
int d;
int j;
int i;
int t = 0;
int sss = 0;
scanf("%d %d", &H, &W);
for (b = 1; b <= H; b++) {
for (c = 1; c <= W; c++) {
scanf("%d", &d);
A[b][c] = d;
};
};
for (b = 1; b <= H; b++) {
for (c = 1; c <=... | fn solution() {
let mut stdin = io::stdin();
let mut buf = String::new();
let _ = stdin.read_to_string(&mut buf);
let mut iter = buf.split_whitespace();
let h: usize = iter.next().unwrap().parse().unwrap();
let w: usize = iter.next().unwrap().parse().unwrap();
let a: Vec<Vec<usize>> = (0..h... | easy |
1082 | <span class="lang-en">
<p>Score: <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Takahashi is solving quizzes. He has easily solved all but the last one.</p>
<p>The last quiz has three choices: <var>1</var>, <var>2</var>, and <var>3</var>.</p>
<p>With his supernatural power, Takahas... | int solution(void) {
int A = 0;
int B = 0;
scanf("%d", &A);
scanf("%d", &B);
if (A != 1 && B != 1) {
printf("1\n");
} else if (A != 2 && B != 2) {
printf("2\n");
} else {
printf("3\n");
}
return 0;
} | fn solution() {
let mut input = String::new();
let _ = io::stdin().read_to_string(&mut input);
let lines: Vec<&str> = input.split("\n").collect();
let a = lines[0].parse::<i32>().unwrap();
let b = lines[1].parse::<i32>().unwrap();
println!("{}", 6 - a - b);
} | hard |
1083 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are two buttons, one of size <var>A</var> and one of size <var>B</var>.</p>
<p>When you press a button of size <var>X</var>, you get <var>X</var> coins and the size of that button decreases by <va... | int solution() {
int a = 0;
int b = 0;
scanf("%d %d", &a, &b);
if (a == b) {
printf("%d\n", a * 2);
} else if (a > b) {
printf("%d\n", (a * 2) - 1);
} else {
printf("%d\n", (b * 2) - 1);
}
return 0;
} | fn solution() {
let stdin = std::io::stdin();
let mut buf = String::new();
let _ = stdin.read_line(&mut buf);
let ns = buf
.split_whitespace()
.map(|s| s.parse().unwrap())
.collect::<Vec<isize>>();
let (a, b) = (ns[0], ns[1]);
if a < b {
println!("{}", b * 2 - 1);... | easy |
1084 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In order to pass the entrance examination tomorrow, Taro has to study for <var>T</var> more hours.</p>
<p>Fortunately, he can <em>leap</em> to World B where time passes <var>X</var> times as fast as it ... | int solution(void) {
float t = 0;
float x = 0;
scanf("%f %f", &t, &x);
printf("%f\n", t / x);
return 0;
} | fn solution() {
let mut tx = String::new();
stdin().read_line(&mut tx).unwrap();
let tx: Vec<isize> = tx.split_whitespace().flat_map(str::parse).collect();
let t = tx[0] * 10000;
let x = tx[1];
println!("{}.{:>04}", t / x / 10000, (t / x) % 10000);
} | medium |
1085 | The round carousel consists of $$$n$$$ figures of animals. Figures are numbered from $$$1$$$ to $$$n$$$ in order of the carousel moving. Thus, after the $$$n$$$-th figure the figure with the number $$$1$$$ follows. Each figure has its own type — the type of the animal corresponding to this figure (the horse, the tiger ... | int solution() {
int t;
scanf("%d", &t);
int n;
while (t--) {
scanf("%d", &n);
int a[n];
int b[n + 1];
int edge = 0;
int store = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i < n; i++) {
if (a[i] != a[(i + 1) % n]) {
edge++;
}
... | fn solution() {
let stdin = io::stdin();
let mut lock = stdin.lock();
let mut line = String::new();
lock.read_line(&mut line).unwrap();
let q = line.trim().parse().unwrap();
for _ in 0..q {
let mut line = String::new();
lock.read_line(&mut line).unwrap();
let mut line =... | medium |
1086 | You are given an array $$$a_1, a_2, \dots, a_n$$$, consisting of $$$n$$$ positive integers. Initially you are standing at index $$$1$$$ and have a score equal to $$$a_1$$$. You can perform two kinds of moves: move right — go from your current index $$$x$$$ to $$$x+1$$$ and add $$$a_{x+1}$$$ to your score. This move c... | int solution() {
int t;
int i;
int n;
int k;
int z;
int a[100000];
int max;
int ind;
int b[100000];
int s[100000];
int temp;
int p;
scanf("%d", &t);
while (t--) {
scanf("%d%d%d", &n, &k, &z);
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
max = 0;
s[0] = a[0];
... | 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, k, z): (usize, usize, usize) = {
let mut buf = String::new();
std::io::stdin().read... | easy |
1087 | This problem is actually a subproblem of problem G from the same contest.There are $$$n$$$ candies in a candy box. The type of the $$$i$$$-th candy is $$$a_i$$$ ($$$1 \le a_i \le n$$$).You have to prepare a gift using some of these candies with the following restriction: the numbers of candies of each type presented in... | int solution() {
long int q;
long int n;
long int i;
long int j;
long int k;
long int l;
long int f;
long int c;
scanf("%ld", &q);
for (i = 0; i < q; i++) {
f = 0;
c = 0;
k = 0;
scanf("%ld", &n);
long int ar[n];
long int br[n];
long int cr[n];
for (j = 0; j < n; j++) ... | fn solution() -> io::Result<()> {
let stdin = io::stdin();
let mut input = String::new();
stdin.read_line(&mut input)?;
let q: u32 = input.trim().parse().unwrap();
for _ in 1..q + 1 {
stdin.read_line(&mut input)?;
let mut input = String::new();
stdin.read_line(&mut input)?;... | hard |
1088 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a trapezoid. The lengths of its upper base, lower base, and height are <var>a</var>, <var>b</var>, and <var>h</var>, respectively.</p>
<div style="text-align: center;">
<img src="https://a... | int solution(void) {
int a = 0;
int h = 0;
int b = 0;
scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &h);
printf("%d\n", (a + b) * h / 2);
return 0;
} | fn solution() {
let mut s = String::new();
stdin().read_line(&mut s).ok();
let a: i64 = s.trim().parse().unwrap();
let mut s = String::new();
stdin().read_line(&mut s).ok();
let b: i64 = s.trim().parse().unwrap();
let mut s = String::new();
stdin().read_line(&mut s).ok();
let h: i64 ... | easy |
1089 | Alice and Bob are playing chess on a huge chessboard with dimensions $$$n \times n$$$. Alice has a single piece left — a queen, located at $$$(a_x, a_y)$$$, while Bob has only the king standing at $$$(b_x, b_y)$$$. Alice thinks that as her queen is dominating the chessboard, victory is hers. But Bob has made a devious ... | int solution() {
int n = 0;
scanf("%*d");
int ara[6];
for (int i = 0; i < 6; i++) {
scanf("%d", &ara[i]);
}
if (((ara[0] - ara[2]) * (ara[0] - ara[4])) > 0) {
n = 1;
}
if (n && ((ara[1] - ara[3]) * (ara[1] - ara[5])) > 0) {
n = 1;
} else {
n = 0;
}
if (n) {
printf("YES\n");
}... | fn solution() {
let mut buffer = String::new();
let stdin = io::stdin();
let mut handle = stdin.lock();
handle.read_to_string(&mut buffer).unwrap();
let arr: Vec<_> = buffer
.split_whitespace()
.map(|x| x.parse::<i32>().unwrap())
.collect();
let _n = arr[0];
let (ax,... | medium |
1090 | There is a grid with $$$n$$$ rows and $$$m$$$ columns, and three types of cells: An empty cell, denoted with '.'. A stone, denoted with '*'. An obstacle, denoted with the lowercase Latin letter 'o'. All stones fall down until they meet the floor (the bottom row), an obstacle, or other stone which is already immovab... | int solution() {
int t;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
int n;
int m;
scanf("%d %d", &n, &m);
char grid[n + 2][m + 3];
for (int j = 0; j < n; j++) {
char newlinechar;
scanf("%1c", &newlinechar);
for (int k = 0; k < m; k++) {
scanf("%1c", &grid[j][k]);
... | fn solution() {
let mut line = String::new();
stdin().read_line(&mut line).unwrap();
let t = line.trim().parse::<i32>().unwrap();
for _tx in 0..t {
line.clear();
stdin().read_line(&mut line).unwrap();
let mut nm = line.trim().split(" ").filter(|x| !x.is_empty());
let n... | easy |
1091 | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.Now let's imagine a typical morning in your family. You haven't wok... | int solution() {
int n = 0;
scanf("%d", &n);
if (n <= 1) {
printf("%d", n);
return 0;
}
int a[n];
int sum = 0;
int mymoney = 0;
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
sum += a[i];
}
for (int c = 0; c < n - 1; c++) {
for (int d = 0; d < n - c - 1; d++) {
if (a[d] ... | fn solution() {
let mut input = String::new();
io::stdin().read_line(&mut input).expect("Input error");
input.clear();
io::stdin().read_line(&mut input).expect("Input error");
let mut coins: Vec<i32> = input
.trim()
.split_ascii_whitespace()
.map(|coin| coin.parse::<i32>()... | medium |
1092 | — Hey folks, how do you like this problem?— That'll do it. BThero is a powerful magician. He has got $$$n$$$ piles of candies, the $$$i$$$-th pile initially contains $$$a_i$$$ candies. BThero can cast a copy-paste spell as follows: He chooses two piles $$$(i, j)$$$ such that $$$1 \le i, j \le n$$$ and $$$i \ne j$$$. ... | int solution() {
int t;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
int n;
int knum;
scanf("%d", &n);
scanf("%d", &knum);
int arr[n];
int pos = 0;
for (int j = 0; j < n; j++) {
scanf("%d", &arr[j]);
}
int min = arr[0];
for (int k = 1; k < n; k++) {
if (min > ... | fn solution() {
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
let t = input.trim().parse::<u32>().unwrap();
for _i in 0..t {
let mut n_k = String::new();
io::stdin().read_line(&mut n_k).unwrap();
let v = n_k.trim().split(" ").collect::<Vec<&str>>()... | medium |
1093 | You are given $$$n$$$ chips on a number line. The $$$i$$$-th chip is placed at the integer coordinate $$$x_i$$$. Some chips can have equal coordinates.You can perform each of the two following types of moves any (possibly, zero) number of times on any chip: Move the chip $$$i$$$ by $$$2$$$ to the left or $$$2$$$ to th... | int solution() {
int n;
int x[110];
int sol = 0;
int sol2 = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &x[i]);
if (x[i] % 2 == 0 && x[i] > 2) {
x[i] = x[i] - x[i] + 2;
}
if (x[i] % 2 == 1 && x[i] > 1) {
x[i] = x[i] - x[i] + 1;
}
}
for (int i = 0; i < n;... | fn solution() {
let mut _buffer = String::new();
io::stdin()
.read_line(&mut _buffer)
.expect("failed to read input");
let mut buffer = String::new();
io::stdin()
.read_line(&mut buffer)
.expect("failed to read input");
let a = buffer
.split_whitespace()
... | medium |
1094 | You have an array $$$a_1, a_2, \dots, a_n$$$. All $$$a_i$$$ are positive integers.In one step you can choose three distinct indices $$$i$$$, $$$j$$$, and $$$k$$$ ($$$i \neq j$$$; $$$i \neq k$$$; $$$j \neq k$$$) and assign the sum of $$$a_j$$$ and $$$a_k$$$ to $$$a_i$$$, i. e. make $$$a_i = a_j + a_k$$$.Can you make all... | int solution() {
int t;
scanf("%d", &t);
int arr[101];
while (t--) {
int n;
int d;
scanf("%d%d", &n, &d);
int check = 1;
int min = 101;
int temp = -1;
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
if (arr[i] > d) {
check = 0;
}
if (arr[i] < min) ... | fn solution() {
let mut input = String::new();
stdin().read_to_string(&mut input).unwrap();
let mut lines = input.lines();
lines.next();
while let Some(line) = lines.next() {
let d: u8 = line.split_whitespace().nth(1).unwrap().parse().unwrap();
let line = lines.next().unwrap();
... | medium |
1095 | Sasha likes investigating different math objects, for example, magic squares. But Sasha understands that magic squares have already been studied by hundreds of people, so he sees no sense of studying them further. Instead, he invented his own type of square — a prime square. A square of size $$$n \times n$$$ is called ... | int solution() {
int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41,
43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101};
int T;
scanf("%d", &T);
for (int C = 0; C < T; C++) {
int n;
scanf("%d", &n);
int p;
for (int i = 0; i < 26; i++) {
if (n < primes[... | fn solution() {
let mut t = String::new();
stdin().read_line(&mut t).unwrap();
let t: u32 = t.trim().parse().unwrap();
for _i in 0..t {
let mut n = String::new();
stdin().read_line(&mut n).unwrap();
let n: u32 = n.trim().parse().unwrap();
for height in 0..n {
... | hard |
1096 | <H1>Exhaustive Search</H1>
<p>
Write a program which reads a sequence <i>A</i> of <i>n</i> elements and an integer <i>M</i>, and outputs "<span>yes</span>" if you can make <i>M</i> by adding elements in <i>A</i>, otherwise "<span>no</span>". You can use an element only once.
</p>
<p>
You are given the sequence <i>A</... | int solution() {
int n;
int i;
int j;
int k;
int A[100];
int B[3000];
memset(B, 0, sizeof(B));
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", A + i);
}
B[0] = 1;
for (i = 0; i < n; i++) {
for (j = 2000; j >= 0; j--) {
if (B[j] && j + A[i] <= 2000) {
B[j + A[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::<usize>().unwrap())
.collect::<Ve... | hard |
1097 | You are given an array $$$a$$$ of length $$$n$$$, which initially is a permutation of numbers from $$$1$$$ to $$$n$$$. In one operation, you can choose an index $$$i$$$ ($$$1 \leq i < n$$$) such that $$$a_i < a_{i + 1}$$$, and remove either $$$a_i$$$ or $$$a_{i + 1}$$$ from the array (after the removal, the remai... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int ns[n];
for (int i = 0; i < n; i++) {
scanf("%d", &ns[i]);
}
if (ns[0] <= ns[n - 1]) {
printf("YES\n");
} else {
printf("NO\n");
}
}
} | fn solution() {
let stdin = io::stdin();
let mut lines = stdin.lock().lines();
let t: usize = lines.next().unwrap().unwrap().parse().unwrap();
for _ in 0..t {
let n: usize = lines.next().unwrap().unwrap().parse().unwrap();
let xs: Vec<usize> = lines
.next()
.unwra... | easy |
1098 | You are given a rooted tree with n vertices. The vertices are numbered from 1 to n, the root is the vertex number 1.Each vertex has a color, let's denote the color of vertex v by cv. Initially cv = 0.You have to color the tree into the given colors using the smallest possible number of steps. On each step you can choos... | int solution() {
int n;
scanf("%d", &n);
int p[n];
p[0] = 1;
int i;
for (i = 1; i < n; i++) {
scanf("%d", &p[i]);
}
int c[n];
for (i = 0; i < n; i++) {
scanf("%d", &c[i]);
}
int steps = n;
for (i = 1; i < n; i++) {
if (c[p[i] - 1] == c[i]) {
steps--;
}
}
printf("%d... | fn solution() {
let mut stdin = String::new();
std::io::Read::read_to_string(&mut std::io::stdin(), &mut stdin).unwrap();
let mut stdin = stdin.split_whitespace();
let mut get = || stdin.next().unwrap();
let n = get!(usize);
let mut tree = vec![vec![]; n + 1];
for i in 2..n + 1 {
l... | medium |
1099 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> stones arranged in a row. The <var>i</var>-th stone from the left is painted in the color <var>C_i</var>.</p>
<p>Snuke will perform the following operation zero or more times:</p>... | int solution() {
int n;
scanf("%d", &n);
int c[n + 1];
int i;
for (i = 1; i <= n; i++) {
scanf("%d", &c[i]);
}
int c_idx[200001];
for (i = 1; i <= 200000; i++) {
c_idx[i] = -1;
}
long long int ans[n + 1];
ans[1] = 1;
c_idx[c[1]] = 1;
for (i = 2; i <= n; i++) {
if (c_idx[c[i]] == i ... | fn solution() {
input! {
n: usize,
v: [usize; n]
}
let d = 1000000007;
let mut map: BTreeMap<usize, Vec<usize>> = BTreeMap::new();
for i in 0..n {
map.entry(v[i]).or_default().push(i);
}
let css: Vec<Vec<usize>> = map.values().cloned().collect();
let mut line: Vec... | medium |
1100 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>The development of algae in a pond is as follows.</p>
<p>Let the total weight of the algae at the beginning of the year <var>i</var> be <var>x_i</var> gram. For <var>i≥2000</var>, the following formula ... | int solution(void) {
int r = 0;
int d = 0;
int x = 0;
scanf("%d %d %d", &r, &d, &x);
for (int i = 1; i <= 10; i++) {
x = r * x - d;
printf("%d\n", x);
}
return 0;
} | fn solution() {
let mut ab = String::new();
stdin().read_line(&mut ab).unwrap();
let ab: Vec<isize> = ab.split_whitespace().flat_map(str::parse).collect();
let (r, d, x) = (ab[0], ab[1], ab[2]);
let mut v = x;
for _ in 0..10 {
v = r * v - d;
println!("{}", v);
}
} | easy |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.