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 |
|---|---|---|---|---|
1801 | You are given a positive integer $$$n$$$, it is guaranteed that $$$n$$$ is even (i.e. divisible by $$$2$$$).You want to construct the array $$$a$$$ of length $$$n$$$ such that: The first $$$\frac{n}{2}$$$ elements of $$$a$$$ are even (divisible by $$$2$$$); the second $$$\frac{n}{2}$$$ elements of $$$a$$$ are odd (n... | int solution(void) {
int t;
scanf("%d", &t);
while (t--) {
int n;
int sum = 0;
int num = 0;
scanf("%d", &n);
if (n % 4 != 0) {
printf("NO\n");
} else {
printf("YES\n");
for (int i = 1; i < (n / 2) + 1; i++) {
int x = 2 * i;
sum = sum + x;
printf("%... | fn solution() {
let mut stdin = BufReader::new(io::stdin());
let mut stdout = BufWriter::new(io::stdout());
let mut buffer = String::new();
stdin.read_line(&mut buffer).unwrap();
let t = buffer.trim().parse().unwrap();
for _ in 0..t {
let mut buffer = String::new();
stdin.read_l... | medium |
1802 | <h1>A: テスト</h1>
<h2>問題</h2>
<p>
$N$ 個の席が一直線上に並んでいる教室で $M$ 人の生徒がテストを受けることになった。
席には、前から $1 \dots N$ の番号が振られており、席 $1$ つにつき生徒 $1$ 人が座れる。
</p>
<p>
いま、 各生徒は、 $A_1, \dots, A_M$ 番の席に座っている。
</p>
<p>
テストを始めるためには、以下の条件を満たさなければならない。
<ul>
<li> $1 \dots M$ 番のどの席にも生徒が座っている。</li>
</ul>
</p>
<p>
そこで、条件を満たすまで次の操作を繰... | int solution() {
int m;
scanf("%*d%d", &m);
int ans = 0;
for (int i = 0; i < m; i++) {
int t;
scanf("%d", &t);
if (t <= m) {
ans++;
}
}
printf("%d\n", m - ans);
} | fn solution() {
input!(n: usize, m: usize, a: [usize1; m]);
let mut ans = 0;
for &a in a.iter() {
if a >= m {
ans += 1;
}
}
println!("{}", ans);
} | medium |
1803 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is going to open a contest named "AtCoder <var>s</var> Contest".
Here, <var>s</var> is a string of length <var>1</var> or greater, where the first character is an uppercase English letter, and the... | int solution(void) {
char text0[100];
char text[100];
char text1[100];
scanf("%s", text0);
scanf("%s", text);
scanf("%s", text1);
printf("%c", *text0);
printf("%c", *text);
printf("%c", *text1);
return 0;
} | fn solution() {
let mut buf = String::new();
io::stdin().read_line(&mut buf).expect("");
let iter = buf.split_whitespace();
for i in iter {
let s: Vec<char> = i.chars().collect::<Vec<char>>();
print!("{}", s[0]);
}
println!();
} | hard |
1804 | For the New Year, Polycarp decided to send postcards to all his $$$n$$$ friends. He wants to make postcards with his own hands. For this purpose, he has a sheet of paper of size $$$w \times h$$$, which can be cut into pieces.Polycarp can cut any sheet of paper $$$w \times h$$$ that he has in only two cases: If $$$w$$... | int solution() {
int t;
scanf("%d", &t);
while (t-- != 0) {
int w = 0;
int h = 0;
int n = 0;
int count = 1;
scanf("%d%d%d", &w, &h, &n);
while (h % 2 == 0) {
count *= 2;
h = h / 2;
}
while (w % 2 == 0) {
count *= 2;
w = w / 2;
}
if (count >= n) ... | fn solution() {
let mut n = String::new();
io::stdin().read_line(&mut n).unwrap();
for _ in 0..n.trim().parse::<i32>().unwrap() {
let mut a = String::new();
io::stdin().read_line(&mut a).unwrap();
let array = a.trim().split(" ").collect::<Vec<&str>>();
let mut w = array[0].... | easy |
1805 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a rooted tree (see Notes) with <var>N</var> vertices numbered <var>1</var> to <var>N</var>.
Each of the vertices, except the root, has a directed edge coming from its parent.
Note that the root... | int solution() {
int n;
int m;
scanf("%d %d", &n, &m);
m = n - 1 + m;
int **graph;
int to[100005] = {0};
graph = (int **)malloc(sizeof(int *) * (n + 10));
for (int i = 0; i < n + 10; i++) {
graph[i] = (int *)malloc(sizeof(int) * (m));
}
while (m--) {
int a;
int b;
scanf("%d %d", &a, ... | 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!();
let m = get!();
let mut tree = vec![vec![]; n];
let mut undi = vec... | medium |
1806 | You are given two strings $$$s$$$ and $$$t$$$, both consisting of exactly $$$k$$$ lowercase Latin letters, $$$s$$$ is lexicographically less than $$$t$$$.Let's consider list of all strings consisting of exactly $$$k$$$ lowercase Latin letters, lexicographically not less than $$$s$$$ and not greater than $$$t$$$ (includ... | int solution() {
int i;
int j;
int k;
int n;
scanf("%d", &n);
char a[n + 1];
char b[n + 1];
scanf("%s%s", a, b);
int c[n];
int d[n];
for (i = 0; i < n; i++) {
c[i] = a[i] - 97;
d[i] = b[i] - 97;
c[i] = c[i] + d[i];
}
for (i = n - 1; i > 0; i--) {
c[i - 1] += c[i] / 26;
c[i]... | fn solution() {
let mut line = String::new();
stdin().read_line(&mut line).unwrap();
let len = line.trim().parse::<usize>().unwrap();
let mut s = String::new();
let mut t = String::new();
{
let i = stdin();
let mut lock = i.lock();
lock.read_line(&mut s).unwrap();
... | medium |
1807 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>N+1</var> integers: <var>10^{100}</var>, <var>10^{100}+1</var>, ..., <var>10^{100}+N</var>.</p>
<p>We will choose <var>K</var> or more of these integers. Find the number of possible values ... | int solution(void) {
int N;
int K;
scanf("%d %d", &N, &K);
if (N + 1 == K) {
printf("1\n");
return 0;
}
if (N == K) {
printf("%d\n", 1 + (N + 1));
return 0;
}
long long result = 1 + (N + 1);
long long i = 1;
long long mod = 1000000007;
long long n = (long long)N;
while (N - i >... | fn solution() {
let a: i64 = 10;
let mo: i64 = a.pow(9) + 7;
let mut st = String::new();
stdin().read_line(&mut st).unwrap();
let (n, k) = {
let nk: Vec<i64> = st.trim().split(" ").map(|x| x.parse().unwrap()).collect();
(nk[0], nk[1])
};
let mut r: i64 = 0;
for i in k..(n... | medium |
1808 | <p>
There are <i>n</i> processes in a queue. Each process has name<sub><i>i</i></sub> and time<sub><i>i</i></sub>. The round-robin scheduling handles the processes in order. A round-robin scheduler gives each process a <i>quantum</i> (a time slot) and interrupts the process if it is not completed by then. The process ... | int solution(void) {
int i;
int n;
int q;
scanf("%d %d", &n, &q);
pro pr[n];
for (i = 0; i < n; i++) {
scanf("%*c%s %d", pr[i].na, &pr[i].ti);
}
int top = 0;
int tail = 0;
int tim = 0;
int sta = 0;
while (1) {
if (sta == 1 && top == tail) {
break;
}
if (pr[top].ti <... | fn solution() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
let a = s.split_whitespace().collect::<Vec<&str>>();
let n = a[0].parse::<usize>().unwrap();
let q = a[1].parse::<i64>().unwrap();
let mut queue: VecDeque<(String, i64)> = VecDeque::new();
for _ in 0..n... | medium |
1809 | Phoenix has decided to become a scientist! He is currently investigating the growth of bacteria.Initially, on day $$$1$$$, there is one bacterium with mass $$$1$$$.Every day, some number of bacteria will split (possibly zero or all). When a bacterium of mass $$$m$$$ splits, it becomes two bacteria of mass $$$\frac{m}{2... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int num;
int arr[1000000];
scanf("%d", &num);
int massbact = 1;
int rate = 1;
int count = 0;
while (1) {
if (num - massbact >= 4 * rate) {
arr[count++] = rate;
rate *= 2;
massbact += rate;
;
... | fn solution() {
let mut str = String::new();
let _ = stdin().read_line(&mut str).unwrap();
let test: u64 = str.trim().parse().unwrap();
for _ in 0..test {
str.clear();
let _ = stdin().read_line(&mut str).unwrap();
let mut n: i64 = str.trim().parse().unwrap();
n -= 1;
... | hard |
1810 | <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> boxes arranged in a row.
Initially, the <var>i</var>-th box from the left contains <var>a_i</var> candies.</p>
<p>Snuke can perform the following operation any number of times:</p... | int solution(void) {
int N = 0;
long x = 0;
long count = 0;
long a[100002] = {0};
scanf("%d %ld", &N, &x);
for (int i = 0; i < N; i++) {
scanf("%ld", &a[i]);
}
for (int i = 0; i < N - 1; i++) {
if (i == 0 && a[i] > x) {
count += a[i] - x;
a[i] = x;
}
if (a[i] + a[i + 1] > x) ... | fn solution() {
let mut s = String::new();
stdin().read_line(&mut s).ok();
let mut itr = s.split_whitespace().map(|e| e.parse().unwrap());
let _n: i64 = itr.next().unwrap();
let x: i64 = itr.next().unwrap();
let mut s = String::new();
stdin().read_line(&mut s).ok();
let mut a: Vec<i64> =... | medium |
1811 | Polycarp wrote on the board a string $$$s$$$ containing only lowercase Latin letters ('a'-'z'). This string is known for you and given in the input.After that, he erased some letters from the string $$$s$$$, and he rewrote the remaining letters in any order. As a result, he got some new string $$$t$$$. You have to find... | int solution() {
int q;
scanf("%d", &q);
char s[55];
int n;
int i;
int j;
int m;
int b[55];
int cnt[30];
char t[55];
int v[55];
int c;
int cc;
for (; q > 0; q--) {
scanf("%s", s);
scanf("%d", &m);
for (i = 0; i < m; i++) {
scanf("%d", &b[i]);
}
n = 0;
while (s[n... | fn solution() {
let q: usize = {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
buf.trim_end().parse().unwrap()
};
for _ in 0..q {
let s: Vec<char> = {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwr... | hard |
1812 | <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> positive integers written on a blackboard: <var>A_1, ..., A_N</var>.</p>
<p>Snuke can perform the following operation when all integers on the blackboard are even:</p>
<ul>
<li>Re... | int solution(void) {
int data[200];
int max = 0;
int result = 0;
int i = 0;
int j = 0;
scanf("%d", &max);
for (i = 0; i < max; i++) {
scanf("%d", &data[i]);
}
i = 0;
for (; i == 0;) {
for (j = 0; j < max; j++) {
if (data[j] % 2 != 0) {
i = 1;
break;
}
data[j... | fn solution() {
let mut buffer = String::new();
io::stdin().read_line(&mut buffer).unwrap();
let mut buffer = String::new();
io::stdin().read_line(&mut buffer).unwrap();
let ns = buffer.trim().split(' ').collect::<Vec<&str>>();
let xs = ns.into_iter().map(|n| {
let mut counter = 0;
... | medium |
1813 | You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis. | int solution() {
int a = 0;
int d = 0;
int e = 0;
scanf("%d", &a);
int b[a];
int c[a];
for (int i = 0; i < a; i++) {
scanf("%d %d", &b[i], &c[i]);
}
for (int i = 0; i < a; i++) {
if (b[i] > 0) {
d++;
}
if (b[i] < 0) {
e++;
}
}
if (d < 2 || e < 2) {
printf("Yes")... | fn solution() {
let mut input = String::new();
use std::io::prelude::*;
std::io::stdin().read_to_string(&mut input).unwrap();
let mut it = input.split_whitespace();
let n: usize = it.next().unwrap().parse().unwrap();
let mut cnt = (0, 0);
for _ in 0..n {
let (x, _y): (i32, i32) =... | medium |
1814 | The only difference between easy and hard versions is the maximum value of $$$n$$$.You are given a positive integer number $$$n$$$. You really love good numbers so you want to find the smallest good number greater than or equal to $$$n$$$.The positive integer is called good if it can be represented as a sum of distinct... | int solution() {
int q;
scanf("%d", &q);
while (q--) {
int n;
scanf("%d", &n);
int i = n;
while (1) {
n = i;
int res = 0;
while (n > 0) {
if (n % 3 == 0) {
n = n / 3;
} else {
n--;
if (n % 3 == 0) {
n = n / 3;
}... | fn solution() {
let mut buffer = String::new();
io::stdin()
.read_line(&mut buffer)
.expect("failed to read input");
let q: u16 = buffer.trim().parse().expect("invalid input");
for _ in 0..q {
let mut input = String::new();
io::stdin()
.read_line(&mut input)
... | medium |
1815 | Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.Sometimes Vladik’s mom sort... | int solution() {
int n;
int m;
int p[100002];
int l[100002];
int r[100002];
int x[100002];
scanf("%d%d", &n, &m);
int i;
int j;
for (i = 0; i < n; i++) {
scanf("%d", &p[i]);
}
for (i = 0; i < m; i++) {
scanf("%d%d%d", &l[i], &r[i], &x[i]);
int count = 0;
for (j = l[i] - 1; j < r[... | fn solution() {
let (_n, m) = {
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
let mut it = input
.split_whitespace()
.map(|k| k.parse::<usize>().unwrap());
(it.next().unwrap(), it.next().unwrap())
};
let p: Vec<usize> = {
... | easy |
1816 | You are given a sequence $$$a=[a_1,a_2,\dots,a_n]$$$ consisting of $$$n$$$ positive integers.Let's call a group of consecutive elements a segment. Each segment is characterized by two indices: the index of its left end and the index of its right end. Denote by $$$a[l,r]$$$ a segment of the sequence $$$a$$$ with the lef... | int solution(void) {
int t;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
int n;
scanf("%d", &n);
int seq[n];
int seq_sum[n];
scanf("%d", &seq[0]);
seq_sum[0] = seq[0];
for (int j = 1; j < n; j++) {
scanf("%d", &seq[j]);
seq_sum[j] = seq_sum[j - 1] + seq[j];
}
int ... | 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 testline = String::new();
io::stdin().read_line(&mut testline).unwrap();
testline = String::new();
io::stdin(... | hard |
1817 | A new entertainment has appeared in Buryatia — a mathematical circus! The magician shows two numbers to the audience — $$$n$$$ and $$$k$$$, where $$$n$$$ is even. Next, he takes all the integers from $$$1$$$ to $$$n$$$, and splits them all into pairs $$$(a, b)$$$ (each integer must be in exactly one pair) so that for e... | int solution() {
int numSets = 0;
scanf("%d", &numSets);
for (int current_set = 0; current_set < numSets; ++current_set) {
int n = 0;
int k = 0;
scanf("%d %d", &n, &k);
if (n % 2 == 1) {
printf("NO\n");
}
int k_remnant = k % 4;
switch (k_remnant) {
case 0: {
printf("... | fn solution() {
let stdin = io::stdin();
let mut iterator = stdin.lock().lines();
let line = iterator.next().unwrap().unwrap();
let amount = line.parse::<i32>().unwrap();
for _i in 0..amount {
let line = iterator.next().unwrap().unwrap();
let strings: Vec<&str> = line.split(" ").coll... | easy |
1818 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke prepared <var>6</var> problems for a upcoming programming contest.
For each of those problems, Rng judged whether it can be used in the contest or not.</p>
<p>You are given a string <var>S</var> o... | int solution(void) {
char s[7];
scanf("%s", s);
printf("%d", s[0] + s[1] + s[2] + s[3] + s[4] + s[5] - (48 * 6));
return 0;
} | fn solution() {
println!(
"{}",
io::stdin()
.bytes()
.take(6)
.filter(|r| r.as_ref().map(|b| b'1' == *b).unwrap_or(false))
.count()
);
} | hard |
1819 | Mikhail walks on a Cartesian plane. He starts at the point $$$(0, 0)$$$, and in one move he can go to any of eight adjacent points. For example, if Mikhail is currently at the point $$$(0, 0)$$$, he can go to any of the following points in one move: $$$(1, 0)$$$; $$$(1, 1)$$$; $$$(0, 1)$$$; $$$(-1, 1)$$$; $$$(-1,... | int solution() {
int q;
scanf("%d", &q);
while (q--) {
long long int a[3];
int i;
for (i = 0; i < 3; i++) {
scanf("%lld", &a[i]);
}
long long int bigger;
long long int smaller;
long long int ans = 0;
if (a[0] > a[1]) {
bigger = a[0];
smaller = a[1];
} else {
... | 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 mut ind = 0;
... | hard |
1820 | <H1>Structured Programming</H1>
<p>
In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loo... | int solution(void) {
int n;
scanf("%d", &n);
for (int i = 3; i <= n; i++) {
if (i % 3 == 0) {
printf(" %d", i);
continue;
}
for (int j = 1; j <= n * 10; j *= 10) {
if ((i / j) % 10 == 3) {
printf(" %d", i);
break;
}
}
}
printf("\n");
return 0;
} | fn solution() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).ok();
let n = s.trim().parse::<usize>().ok().unwrap();
for i in 1..n + 1 {
if i % 3 == 0 || i.to_string().contains("3") {
print!(" {}", i);
}
}
println!();
} | medium |
1821 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Takahashi loves palindromes. Non-palindromic strings are unacceptable to him. Each time he hugs a string, he can change one of its characters to any character of his choice.</p>
<p>Given is a string <v... | int solution() {
char a[100];
int i = 0;
int count = 0;
int change = 0;
scanf("%s", &a[0]);
for (count = 0; a[count] != '\0'; count++) {
;
}
for (i = 0; i < count / 2; i++) {
if (a[i] != a[count - i - 1]) {
change++;
}
}
printf("%d\n", change);
return 0;
} | fn solution() {
let mut s = String::new();
io::stdin().read_line(&mut s).unwrap();
let s = s.trim();
let n = s.len();
let s: Vec<char> = s.chars().collect();
let mut answer = 0;
for i in 0..n {
if s[i] != s[n - i - 1] {
answer += 1;
}
}
println!("{}"... | easy |
1822 | <H1>階乗 II</H1>
<p>
<var>n! = n × (n − 1) × (n − 2) ×</var> ... <var> × 3 × 2 × 1</var><br/>
<br/>
を <var>n</var> の階乗といいます。例えば、12 の階乗は<br/>
<br/>
<var>12! = 12 × 11 × 10 × 9 × 8 × 7 × 6 × 5 × 4 × 3 × 2 × 1... | int solution() {
while (1) {
int n;
int c = 0;
int k = 5;
scanf("%d", &n);
if (n == 0) {
break;
}
while (k < 20000) {
c += n / (k);
k *= 5;
}
printf("%d\n", c);
}
return 0;
} | fn solution() {
let mut input;
loop {
input = String::new();
std::io::stdin().read_line(&mut input).expect("Input error");
let mut n = input.trim().parse::<u64>().expect("Error parse");
if n == 0 {
break;
}
let mut zero = 0;
while n >= 5 {
... | easy |
1823 | A chess tournament will be held soon, where $$$n$$$ chess players will take part. Every participant will play one game against every other participant. Each game ends in either a win for one player and a loss for another player, or a draw for both players.Each of the players has their own expectations about the tournam... | int solution(void) {
int t;
scanf("%d", &t);
for (int k = 0; k < t; k++) {
int n;
scanf("%d", &n);
char s[n];
scanf("%s", s);
char m[n][n];
int c = 0;
int d = 0;
for (int j = 0; j < n; j++) {
if (s[j] == '1') {
c++;
} else {
d++;
}
}
int r ... | 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 v = l
.unwrap()
.chars()
.map(|c| c.to_digit(10).unwrap())
.collect::<Vec<_>>();
let t = v.iter().filter... | medium |
1824 | You are given an array $$$a$$$ of length $$$n$$$.Let's define the eversion operation. Let $$$x = a_n$$$. Then array $$$a$$$ is partitioned into two parts: left and right. The left part contains the elements of $$$a$$$ that are not greater than $$$x$$$ ($$$\le x$$$). The right part contains the elements of $$$a$$$ that ... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int a[n];
int max = -1;
int end = 0;
int count = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (a[i] >= max) {
max = a[i];
end = i;
}
}
int prev = -1;
... | fn solution() {
let mut t = String::new();
io::stdin().read_line(&mut t).unwrap();
for _ in 0..t.trim().parse::<i64>().unwrap() {
let mut n = String::new();
io::stdin().read_line(&mut n).unwrap();
let mut a = String::new();
io::stdin().read_line(&mut a).unwrap();
le... | easy |
1825 | Polycarp found a rectangular table consisting of $$$n$$$ rows and $$$m$$$ columns. He noticed that each cell of the table has its number, obtained by the following algorithm "by columns": cells are numbered starting from one; cells are numbered from left to right by columns, and inside each column from top to bottom... | int solution() {
int t;
scanf("%d", &t);
long long n[t];
long long m[t];
long long x[t];
long long c;
long long r;
for (int i = 0; i < t; ++i) {
scanf("%lld %lld %lld", &n[i], &m[i], &x[i]);
c = x[i] / n[i];
r = x[i] % n[i];
if (r == 0) {
r = n[i];
} else {
++c;
}
... | fn solution() -> Result<(), Box<dyn std::error::Error>> {
let mut input = String::new();
let stdin = io::stdin();
let mut stdin = stdin.lock();
stdin.read_line(&mut input)?;
let stdout = io::stdout();
let mut stdout = BufWriter::new(stdout.lock());
let case_count: usize = input.trim_end().p... | medium |
1826 | <span class="lang-en">
<p>Score: <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>To become a millionaire, M-kun has decided to make money by trading in the next <var>N</var> days. Currently, he has <var>1000</var> yen and no stocks - only one kind of stock is issued in the country w... | int solution(void) {
long n;
scanf("%ld", &n);
long a[n];
for (long i = 0; i < n; i++) {
scanf("%ld", &a[i]);
}
long stock = 0;
long money = 1000;
int flag = 0;
for (long i = 0; i < n; i++) {
if (flag == 0) {
if (i != n - 1 && a[i] < a[i + 1]) {
stock += money / a[i];
mo... | fn solution() {
let n: usize = {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
buf.trim_end().parse().unwrap()
};
let a: Vec<usize> = {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
let iter = buf.spl... | hard |
1827 | Polycarp has a poor memory. Each day he can remember no more than $$$3$$$ of different letters. Polycarp wants to write a non-empty string of $$$s$$$ consisting of lowercase Latin letters, taking minimum number of days. In how many days will he be able to do it?Polycarp initially has an empty string and can only add ch... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int d = 0;
int l;
char arr[2000001];
char a = '1';
char b = '1';
char c = '1';
scanf("%s", arr);
l = strlen(arr);
for (int i = 0; i < l; i++) {
if (a == '1' && b == '1' && c == '1') {
a = arr[i];
} else ... | fn solution() {
let mut line = String::new();
io::stdin().read_line(&mut line).expect("Error!");
let x: i32 = line.trim().parse().expect("Error!");
for _ in 0..x {
let mut stroke = String::new();
io::stdin().read_line(&mut stroke).expect("Error!");
let mut res = 1;
let ... | hard |
1828 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><em>ButCoder Inc.</em> runs a programming competition site called <em>ButCoder</em>. In this site, a user is given an integer value called rating that represents his/her skill, which changes each time h... | int solution() {
long long a;
long long b;
long long c;
scanf("%lld %lld %lld", &a, &b, &c);
if (a <= b) {
printf("1\n");
} else if (b <= c) {
printf("-1\n");
} else {
printf("%lld\n", ((a - b - 1) / (b - c) * 2) + 3);
}
return 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 k: usize = itr.next().unwrap().parse().unwrap();
let a: usize = itr.next().unwrap().parse().unwrap();
let b: usize = itr.next().unwrap().parse().unwrap();
... | medium |
1829 | There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while pass... | int solution() {
int beauty[1005];
int i = 0;
for (; i < 1002; i++) {
beauty[i] = 0;
}
int n;
int a;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &a);
beauty[a]++;
}
int max = 0;
for (i = 0; i < 1002; i++) {
if (beauty[i] > max) {
max = beauty[i];
}
}
printf... | fn solution() {
use std::io;
let mut buf = String::new();
io::stdin().read_line(&mut buf).unwrap();
buf.clear();
io::stdin().read_line(&mut buf).unwrap();
let mut ns: Vec<usize> = buf
.split(" ")
.map(|str| str.trim().parse().unwrap())
.collect();
{
let (i, ... | hard |
1830 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke loves working out. He is now exercising <var>N</var> times.</p>
<p>Before he starts exercising, his <em>power</em> is <var>1</var>. After he exercises for the <var>i</var>-th time, his power gets ... | int solution() {
long long int N = 0;
long long int power = 1;
scanf("%lld", &N);
for (long long int i = 1; i <= N; i++) {
power = power * i % 1000000007;
}
printf("%lld", power);
return 0;
} | fn solution() {
let n: u64 = {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).ok();
buf.trim().parse().unwrap()
};
println!(
"{}",
(1..(n + 1)).fold(1, |p, k| (p * k) % (10u64.pow(9) + 7))
);
} | medium |
1831 | It's a walking tour day in SIS.Winter, so $$$t$$$ groups of students are visiting Torzhok. Streets of Torzhok are so narrow that students have to go in a row one after another.Initially, some students are angry. Let's describe a group of students by a string of capital letters "A" and "P": "A" corresponds to an angry... | int solution() {
int totalGroups;
scanf("%d", &totalGroups);
int studentsPerGroup[totalGroups];
char *groups[totalGroups];
int *angryStudents[totalGroups];
int totalAngryStudents[totalGroups];
for (int i = 0; i < totalGroups; i++) {
scanf("%d", &studentsPerGroup[i]);
groups[i] = malloc(studen... | fn solution() {
let mut buffer = String::new();
io::stdin().read_line(&mut buffer).expect("err");
let n: i32 = buffer.trim().parse().unwrap();
for _ in 0..n {
io::stdin().read_line(&mut buffer).expect("err");
buffer.clear();
io::stdin().read_line(&mut buffer).expect("err");
... | hard |
1832 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Alice and Bob are controlling a robot. They each have one switch that controls the robot.<br/>
Alice started holding down her button <var>A</var> second after the start-up of the robot, and released her... | int solution() {
int as = 0;
int ae = 0;
int bs = 0;
int be = 0;
scanf("%d %d %d %d", &as, &ae, &bs, &be);
if (as - bs >= 0) {
if (be - as <= 0) {
printf("0\n");
} else if (be - as > 0 && ae - be > 0) {
printf("%d\n", be - as);
} else if (be - as > 0 && ae - be <= 0) {
printf(... | fn solution() {
let mut times: Vec<isize> = {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).ok();
buf.split_whitespace()
.map(|e| e.trim().parse().ok().unwrap())
.collect()
};
if times[0] >= times[3] || times[1] <= times[2] {
print... | medium |
1833 | <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>Distance II</h1><br>
<p>
... | int solution() {
int n;
int x[100];
int y[100];
double ans[3] = {0.0};
int ans_max = -1;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &x[i]);
}
for (int i = 0; i < n; i++) {
scanf("%d", &y[i]);
}
for (int i = 0; i < n; i++) {
double temp = (double)abs(x[i] - y[i]);
... | fn solution() {
let mut s = String::new();
io::stdin().read_line(&mut s).unwrap();
let n = s.trim().parse().unwrap();
let mut s = String::new();
io::stdin().read_line(&mut s).unwrap();
let x: Vec<f64> = s
.split_whitespace()
.map(|x| x.parse().unwrap())
.collect::<_>();
... | medium |
1834 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>N</var> squares assigned the numbers <var>1,2,3,\ldots,N</var>. Each square has an integer written on it, and the integer written on Square <var>i</var> is <var>a_i</var>.</p>
<p>How many s... | int solution() {
int n = 0;
int a = 0;
int array[101];
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &array[i]);
if (((array[i] % 2) == 1) && ((i % 2) == 1)) {
a++;
}
}
printf("%d", a);
return 0;
} | fn solution() {
let mut buf = String::new();
std::io::stdin()
.read_line(&mut buf)
.expect("failed to read");
buf.clear();
std::io::stdin()
.read_line(&mut buf)
.expect("failed to read");
let va: Vec<u32> = buf.split_whitespace().map(|e| e.parse().unwrap()).collect();... | medium |
1835 | <H1>Counting Sort</H1>
<p>
Counting sort can be used for sorting elements in an array which each of the n input elements is an integer in the range 0 to k. The idea of counting sort is to determine, for each input element x, the number of elements less than x as C[x]. This information can be used to place element x di... | int solution() {
int i = 0;
int j;
int k = 0;
int n;
scanf("%d", &n);
int A[n];
int B[n];
int C[2000001];
for (i = 0; i < n; i++) {
scanf("%d", &A[i]);
}
for (i = 0; i < 2000001; i++) {
C[i] = 0;
}
for (i = 0; i < n; i++) {
C[A[i]]++;
}
i = 0;
k = 0;
while (i < n) {
fo... | fn solution() {
input!(n: usize, vs: [usize; n]);
let nax = vs.iter().max().unwrap();
let nax = *nax;
let mut cs = vec![0usize; nax + 1];
for i in 0..n {
cs[vs[i]] += 1;
}
for i in 1..nax + 1 {
cs[i] += cs[i - 1];
}
let mut bs = vec![0usize; n];
for i in (0..n... | medium |
1836 | Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to a1, a2, ..., an.While Vasya was walking, his little brother Stepan played with Vasya's cubes and change... | int solution() {
int n = 0;
int l = 0;
int r = 0;
scanf("%d %d %d", &n, &l, &r);
int a[n + 1];
int b[n + 1];
int dp1[100001];
int dp2[100001];
int i;
for (int i = 0; i <= 100000; i++) {
dp1[i] = 0;
dp2[i] = 0;
}
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (i >= l && i <... | fn solution() {
let mut line = String::new();
io::stdin().read_line(&mut line).unwrap();
let mut numbers = line.split_whitespace();
let n: usize = numbers.next().unwrap().parse().unwrap();
let l: usize = numbers.next().unwrap().parse().unwrap();
let r: usize = numbers.next().unwrap().parse().un... | easy |
1837 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Let us define the <strong>FizzBuzz sequence</strong> <var>a_1,a_2,...</var> as follows:</p>
<ul>
<li>If both <var>3</var> and <var>5</var> divides <var>i</var>, <var>a_i=\mbox{FizzBuzz}</var>.</li>
<li>... | int solution() {
int n = 0;
unsigned long long total = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
if (i % 3 != 0 && i % 5 != 0) {
total += i;
}
}
printf("%llu", total);
return 0;
} | fn solution() {
let mut s = String::new();
stdin().read_line(&mut s).ok();
let n: i64 = s.trim().parse().unwrap();
let itr = (1..=n).filter(|&e| !(e % 5 == 0 || e % 3 == 0));
println!("{}", itr.sum::<i64>());
} | easy |
1838 | For his birthday, Kevin received the set of pairwise distinct numbers $$$1, 2, 3, \ldots, n$$$ as a gift.He is going to arrange these numbers in a way such that the minimum absolute difference between two consecutive numbers be maximum possible. More formally, if he arranges numbers in order $$$p_1, p_2, \ldots, p_n$$$... | int solution() {
int n;
scanf("%d", &n);
int A[n];
for (int i = 0; i < n; i++) {
scanf("%d", &A[i]);
}
for (int k = 0; k < n; k++) {
int z = A[k];
int a = z / 2;
int b = 2 * a;
for (int q = 1; q <= z / 2; q++) {
printf("%d %d ", a, b);
a--;
b--;
}
if (z % 2 =... | fn solution() {
let mut buf = BufWriter::new(io::stdout().lock());
io::stdin()
.lines()
.skip(1)
.flatten()
.flat_map(|s| s.parse::<u16>())
.for_each(|n| {
for i in 0..(n.wrapping_div(2)) {
write!(
buf,
"... | hard |
1839 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> points on the 2D plane, <var>i</var>-th of which is located on <var>(x_i, y_i)</var>.
There can be multiple points that share the same coordinate.
What is the maximum possible Man... | int solution(void) {
int n;
scanf("%d", &n);
long int x;
long int y;
long int minz = 2000000000;
long int maxz = 2;
long int minw = 1000000000;
long int maxw = -1000000000;
for (int i = 0; i < n; i++) {
scanf("%ld %ld", &x, &y);
if (x + y < minz) {
minz = x + y;
}
if (x + y > max... | 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 x, mut y) = (vec![0i64; n], vec![0i64; n]);
for i in 0..n {
let mut buf = String::new();
std::io::stdin().read... | easy |
1840 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a grid of <var>H</var> rows and <var>W</var> columns of squares. The color of the square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left <var>(1 \leq i \leq ... | int solution() {
int H;
int W;
int K;
scanf("%d %d %d", &H, &W, &K);
char m[H * W];
for (int i = 0; i < H * W; i++) {
scanf(" %c", &m[i]);
}
int count = 0;
for (int h = 0; h < 1 << H; h++) {
for (int w = 0; w < 1 << W; w++) {
int black = 0;
for (int i = 0; i < H; i++) {
for... | fn solution() {
let mut x = String::new();
io::stdin().read_line(&mut x).unwrap();
let hwk: Vec<usize> = x
.trim_end()
.split(' ')
.map(|s| s.parse().unwrap())
.collect();
let h = hwk[0];
let w = hwk[1];
let k = hwk[2];
let mut b: [[bool; 6]; 6] = Default::def... | easy |
1841 | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and d... | int solution() {
int n;
scanf("%d", &n);
int a[n];
long long int b[100002];
long long int dp[100002];
for (int i = 0; i <= 100001; i++) {
b[i] = 0;
dp[i] = 0;
}
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
b[a[i]]++;
}
dp[1] = b[1] * 1;
dp[2] = b[2] * 2;
long long int max ... | fn solution() {
let _ = {
let mut line = String::new();
std::io::stdin().read_line(&mut line).unwrap();
line.trim().to_string()
};
let v: Vec<i64> = {
let mut line = String::new();
std::io::stdin().read_line(&mut line).unwrap();
line.trim()
.split(... | medium |
1842 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Having learned the multiplication table, Takahashi can multiply two integers between <var>1</var> and <var>9</var> (inclusive) together.</p>
<p>Given an integer <var>N</var>, determine whether <var>N</v... | int solution(void) {
int n = 0;
int flag = 0;
scanf("%d", &n);
for (int i = 1; i <= 9; i++) {
if (n == (n / i) * i && (n / i) <= 9) {
flag = 1;
break;
}
}
if (flag == 1) {
printf("Yes");
} else {
printf("No");
}
return 0;
} | fn solution() {
let stdin = io::stdin();
let mut buf = String::new();
stdin.read_line(&mut buf).ok();
let line: Vec<i32> = buf.split_whitespace().map(|s| s.parse().unwrap()).collect();
let N = line[0];
for i in 1..10 {
for j in 1..10 {
if i * j == N {
println!... | medium |
1843 | Exponential search | int64_t solution(const int64_t *arr, const uint16_t length,
const int64_t n) {
if (length == 0) {
return -1;
}
uint32_t upper_bound = 1;
while (upper_bound < length && arr[upper_bound] < n) {
upper_bound = upper_bound * 2;
}
uint16_t lower_bound = upper_bound / 2;
if (... | fn solution<T: Ord>(item: &T, arr: &[T]) -> Option<usize> {
let len = arr.len();
if len == 0 {
return None;
}
let mut upper = 1;
while (upper < len) && (&arr[upper] <= item) {
upper *= 2;
}
if upper > len {
upper = len
}
let mut lower = upper / 2;
while l... | medium |
1844 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. E... | int solution() {
int i;
int n;
int j;
int c = 0;
scanf("%d", &n);
int k[n];
char s[n][100];
for (i = 0; i < n; i++) {
k[i] = 0;
scanf("%s", s[i]);
for (j = i - 1; j >= 0; j--) {
for (c = 0; s[i][c] == s[j][c]; c++) {
if (s[i][c] == 0) {
break;
}
}
... | fn solution() {
let mut s = String::new();
io::stdin().read_line(&mut s).unwrap();
let n: i32 = s.trim().parse().unwrap();
let mut map = HashMap::new();
for _i in 0..n {
let mut s = String::new();
io::stdin().read_line(&mut s).unwrap();
s = s.trim().to_string();
let s... | medium |
1845 | <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> not less than <var>1</var>.
The values of <var>a_1, a_2, ..., a_N</var> are not known, but it is known that <var>a_1 \times a_2 \times ... \... | int solution(void) {
long N;
long P;
long ans = 1;
scanf("%ld %ld", &N, &P);
if (N == 1) {
printf("%ld", P);
return 0;
}
int div = 0;
for (int i = 2; P > 1 && i <= sqrt(P); i++) {
div = 0;
while (P % i == 0) {
P /= i;
div++;
if (div >= N) {
ans *= i;
... | 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!();
let mut p = get!();
if n == 1 {
println!("{}", p);
ret... | easy |
1846 | Consider the array $$$a$$$ composed of all the integers in the range $$$[l, r]$$$. For example, if $$$l = 3$$$ and $$$r = 7$$$, then $$$a = [3, 4, 5, 6, 7]$$$.Given $$$l$$$, $$$r$$$, and $$$k$$$, is it possible for $$$\gcd(a)$$$ to be greater than $$$1$$$ after doing the following operation at most $$$k$$$ times? Cho... | int solution(void) {
int n;
scanf("%d", &n);
while (n--) {
int l;
int r;
int k;
scanf("%d %d %d", &l, &r, &k);
int j = 0;
if (l == r && l > 1) {
j = 1;
} else {
int number = r - l + 1;
int js = number / 2;
if (l % 2 && r % 2) {
js++;
}
if (js... | fn solution() {
let mut input = String::new();
stdin().read_to_string(&mut input).unwrap();
let mut input = input.split_ascii_whitespace().flat_map(str::parse);
let t = input.next().unwrap();
let mut output = String::new();
for _ in 0..t {
let l = input.next().unwrap();
let r = i... | easy |
1847 | You are given three integers $$$a$$$, $$$b$$$, and $$$c$$$. Determine if one of them is the sum of the other two. | int solution() {
int a = 0;
int b[4];
scanf("%d", &a);
for (int j = 0; j < a; j++) {
for (int i = 0; i < 3; i++) {
scanf("%d", &b[i]);
}
if ((b[0] == b[1] + b[2]) || (b[1] == b[2] + b[0]) ||
(b[2] == b[0] + b[1])) {
printf("YES\n");
} else {
printf("NO\n");
}
}
... | fn solution() {
let mut line = String::new();
std::io::stdin().read_line(&mut line).unwrap();
let line_len = line.trim().parse::<i32>().unwrap();
for _ in 0..line_len {
line = String::new();
std::io::stdin().read_line(&mut line).unwrap();
let num_strs: Vec<&str> = line.trim()... | easy |
1848 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a sequence of <var>N \times K</var> integers: <var>X=(X_0,X_1,\cdots,X_{N \times K-1})</var>.
Its elements are represented by another sequence of <var>N</var> integers: <var>A=(A_0,A_1,\cdots,A_... | int solution() {
int i;
int N;
int A[200001];
long long K;
scanf("%d %lld", &N, &K);
for (i = 1; i <= N; i++) {
scanf("%d", &(A[i]));
}
A[0] = 0;
list *L[200001] = {};
list d[200002];
list *p;
d[0].v = 0;
d[0].next = L[0];
L[0] = &(d[0]);
d[N + 1].v = 0;
d[N + 1].next = NULL;
for ... | fn solution() {
let mut input_str = String::new();
std::io::stdin().read_to_string(&mut input_str).unwrap();
let input_parts = input_str.split_whitespace().collect::<Vec<_>>();
let mut input_parts_it = input_parts.iter().cloned();
let n: usize = input_parts_it.next().unwrap().parse().unwrap();
... | medium |
1849 | Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has. Unfortunately, Igor could only get v liters of paint. He did the math and concluded that digit d requ... | int solution() {
int n;
int i = 0;
int l = 0;
int min = 1000000;
int a[9];
scanf("%d", &n);
for (i = 0; i < 9; i++) {
scanf("%d", &a[i]);
if (min >= a[i]) {
min = a[i];
}
}
if (n < min) {
printf("-1");
}
l = n / min;
while (l--) {
for (i = 8; i >= 0; i--) {
if ((n... | fn solution() {
let stdin = io::stdin();
let mut s = String::new();
let mut t = String::new();
stdin.read_line(&mut s).unwrap();
stdin.read_line(&mut t).unwrap();
let n: i32 = s.trim().parse().unwrap();
let v: Vec<i32> = t.trim().split(' ').map(|x| x.parse().unwrap()).collect();
let m... | medium |
1850 | One day Prof. Slim decided to leave the kingdom of the GUC to join the kingdom of the GIU. He was given an easy online assessment to solve before joining the GIU. Citizens of the GUC were happy sad to see the prof leaving, so they decided to hack into the system and change the online assessment into a harder one so tha... | int solution() {
unsigned short t;
scanf("%hu", &t);
while (t--) {
unsigned short n;
scanf("%hu", &n);
int arr[n];
unsigned short neg_count = 0;
for (unsigned register short i = 0; i < n; i++) {
scanf("%i", &arr[i]);
neg_count += arr[i] < 0;
}
for (unsigned register short i... | fn solution() {
let stdin = io::stdin();
let lines = stdin
.lock()
.lines()
.collect::<Vec<Result<String, std::io::Error>>>();
let mut lines = lines.iter();
lines.next();
lines.next();
for line in lines.step_by(2) {
let line = line.as_ref().unwrap();
let ... | medium |
1851 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You have three tasks, all of which need to be completed.</p>
<p>First, you can complete any one task at cost <var>0</var>.</p>
<p>Then, just after completing the <var>i</var>-th task, you can complete t... | int solution(void) {
int A1 = 0;
int A2 = 0;
int A3 = 0;
int tmp = 0;
do {
scanf("%d %d %d", &A1, &A2, &A3);
} while (A1 < 1 && A1 > 100 && A2 < 1 && A2 > 100 && A3 < 1 && A3 > 100);
if (A1 >= A2 && A1 >= A3) {
tmp = A1;
} else if (A2 >= A1 && A2 >= A3) {
tmp = A2;
} else if (A3 >= A1 &&... | fn solution() {
let mut n = String::new();
std::io::stdin().read_line(&mut n).unwrap();
let mut task: Vec<i32> = n.split_whitespace().map(|x| x.parse().unwrap()).collect();
task.sort();
let mut ans = 0;
for i in 1..task.len() {
ans += task[i] - task[i - 1];
}
println!("{}", ans... | hard |
1852 | Cowboy Vlad has a birthday today! There are $$$n$$$ children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child stan... | int solution() {
int n;
int a[100];
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
for (int i = 0; i < n; ++i) {
int k = i;
for (int j = i + 1; j < n; ++j) {
if (a[j] > a[k]) {
k = j;
}
}
if (k != i) {
int temp = a[k];
a[k] = a[i];
... | fn solution() {
let mut sin = String::new();
std::io::stdin().read_line(&mut sin).expect("read error");
sin.clear();
std::io::stdin().read_line(&mut sin).expect("read error");
let mut vi32: Vec<i32> = sin.split_whitespace().map(|c| c.parse().unwrap()).collect();
vi32.sort_unstable();
let m... | hard |
1853 | Masha has $$$n$$$ types of tiles of size $$$2 \times 2$$$. Each cell of the tile contains one integer. Masha has an infinite number of tiles of each type.Masha decides to construct the square of size $$$m \times m$$$ consisting of the given tiles. This square also has to be a symmetric with respect to the main diagonal... | int solution() {
int k;
int j = 0;
int yes = 0;
scanf("%d", &k);
int n[k];
int m[k];
int matrix[k][100][2][2];
while (j < k) {
int i = 0;
scanf("%d %d", &n[j], &m[j]);
while (i < n[j]) {
scanf("%d %d", &matrix[j][i][0][0], &matrix[j][i][0][1]);
scanf("%d %d", &matrix[j][i][1][0]... | fn solution() {
let mut t = String::new();
io::stdin().read_line(&mut t).unwrap();
let t = t.trim().parse::<i32>().unwrap();
for _i in 0..t {
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
let mut input = input.split_whitespace();
let n = inp... | hard |
1854 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a sequence with <var>N</var> integers: <var>A = \{ A_1, A_2, \cdots, A_N \}</var>.
For each of these <var>N</var> integers, we will choose a color and paint the integer with that color. He... | int solution(void) {
int n;
scanf("%d", &n);
int ary[n];
int bry[n];
int length = 0;
for (int i = 0; i < n; i++) {
bry[i] = -1;
scanf("%d", &ary[i]);
int k = 0;
while (bry[k] >= ary[i]) {
k++;
}
if (bry[k] == -1) {
length++;
}
bry[k] = ary[i];
}
printf("%d\n"... | fn solution() {
input! {
n: usize,
v: [usize; n]
}
let mut c = vec![v[0]];
for &a in &v[1..] {
if a > c[0] {
c[0] = a;
continue;
}
let mut l = 0;
let mut r = c.len();
while l + 1 < r {
let m = (l + r) / 2;
... | medium |
1855 | Stooge sort | void solution(int arr[], int i, int j) {
int temp;
int k;
if (arr[i] > arr[j]) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
if ((i + 1) >= j) {
return;
}
k = ((j - i + 1) / 3);
stoogesort(arr, i, j - k);
stoogesort(arr, i + k, j);
stoogesort(arr, i, j - k);
}
| fn solution<T: Ord>(arr: &mut [T]) {
if arr.is_empty() {
return;
}
fn sort<T: Ord>(arr: &mut [T], start: usize, end: usize) {
if arr[start] > arr[end] {
arr.swap(start, end);
}
if start + 1 >= end {
return;
}
let k = (end - start + 1... | easy |
1856 | Mahmoud was trying to solve the vertex cover problem on trees. The problem statement is:Given an undirected tree consisting of n nodes, find the minimum number of vertices that cover all the edges. Formally, we need to find a set of vertices such that for each edge (u, v) that belongs to the tree, either u is in the se... | int solution() {
int n;
scanf("%d", &n);
if (2 <= n && n <= 5) {
puts("-1");
} else {
for (int i = 2; i <= 4; i++) {
printf("%d 1\n", i);
}
for (int i = 5; i <= n; i++) {
printf("%d 2\n", i);
}
}
for (int i = 2; i <= n; i++) {
printf("%d %d\n", i, 1);
}
return 0;
} | fn solution() {
use std::io;
use std::io::prelude::*;
let mut input = String::new();
io::stdin().read_to_string(&mut input).unwrap();
let n: usize = input.trim().parse().unwrap();
let _g = "1 2
1 3
2 4
2 5
3 6
4 7
4 8\n";
let g = "1 2
1 3
1 4
2 5
2 6\n";
let mut ans = String::new()... | medium |
1857 | Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes...Let's define a Rooted Dead Bush (RDB) of level $$$n... | int solution(int argc, char const *argv[]) {
const long long int N = 2e6;
const long long int T = 1e4 + 1;
const long long int mod = 1e9 + 7;
long long int a[N];
long long int n;
long long int max = 0;
a[0] = 0;
a[1] = 0;
a[2] = 0;
a[3] = 4;
if (scanf("%lld", &n) != EOF) {
};
long long int q... | fn solution() {
let stdin = io::stdin();
let mut lines = stdin.lock().lines();
let t: usize = lines.next().unwrap().unwrap().parse().unwrap();
let mut xs: Vec<i64> = Vec::new();
for _ in 0..t {
let x: i64 = lines.next().unwrap().unwrap().parse().unwrap();
xs.push(x);
}
let m ... | easy |
1858 | There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights. Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1] Polycarpus has bought a posh piano and is... | int solution(void) {
int n = 0;
int k = 0;
scanf("%d %d", &n, &k);
int arr[n];
for (int i = 0, a = 0, b = 0; i < n; i++) {
scanf("%d", &a);
arr[i] = a + b;
b = arr[i];
}
int m = arr[k - 1];
int r = 0;
for (int i = 1, j = k; j < n; i++, j++) {
int tmp = arr[j] - arr[i - 1];
if ... | fn solution() {
let stdin = io::stdin();
let input = &mut String::new();
input.clear();
stdin.read_line(input);
let A: Vec<usize> = input
.trim()
.split(' ')
.map(|s| s.parse().unwrap())
.collect();
let n = A[0];
let k = A[1];
input.clear();
stdin.r... | medium |
1859 | You are given a multiset (i. e. a set that can contain multiple equal integers) containing $$$2n$$$ integers. Determine if you can split it into exactly $$$n$$$ pairs (i. e. each element should be in exactly one pair) so that the sum of the two elements in each pair is odd (i. e. when divided by $$$2$$$, the remainder ... | int solution() {
int t = 0;
scanf("%d", &t);
while (t--) {
int n = 0;
scanf("%d", &n);
int A[2 * n];
int sum = 0;
int even = 0;
int odd = 0;
for (int i = 0; i < 2 * n; i++) {
scanf("%d", &A[i]);
if (A[i] % 2 == 0) {
even++;
}
if (A[i] % 2 == 1) {
... | 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 (l, e) = l
.unwrap()
.trim()
.split(' ')
.map(|w| w.parse::<u32>().unwrap())
.fold((0, 0), |(c, e), ... | medium |
1860 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given two non-negative integers <var>L</var> and <var>R</var>.
We will choose two integers <var>i</var> and <var>j</var> such that <var>L \leq i < j \leq R</var>.
Find the minimum possible va... | int solution() {
long long L = 0;
long long R = 0;
long long i = 0;
long long j = 0;
long long ans = 0;
long long min = -1;
scanf("%lld %lld", &L, &R);
if (R - L >= 2019) {
min = 0;
} else {
for (i = 0; L + i < R; i++) {
for (j = i + 1; L + j <= R; j++) {
ans = (((L + i) % 2019) ... | fn solution() {
let mut s: String = String::new();
std::io::stdin().read_to_string(&mut s).ok();
let mut itr = s.split_whitespace();
let l: u64 = itr.next().unwrap().parse().unwrap();
let r: u64 = itr.next().unwrap().parse().unwrap();
if r - l >= 2019 {
println!("0");
} else {
... | easy |
1861 | This is an interactive problem.This is an easy version of the problem. The difference from the hard version is that in the easy version $$$t=1$$$ and the number of queries is limited to $$$20$$$.Polycarp is playing a computer game. In this game, an array consisting of zeros and ones is hidden. Polycarp wins if he guess... | int solution() {
int n;
int t;
int k;
int l = 1;
int r;
int mid;
int cnt;
scanf("%d%d%d", &n, &t, &k);
r = n;
while (l <= r) {
mid = (l + r) / 2;
printf("? 1 %d\n", mid);
fflush(stdout);
scanf("%d", &cnt);
if (mid - cnt >= k) {
r = mid - 1;
} else {
l = mid + 1;
... | 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(|x| x.unwrap());
let s = lines.next().unwrap();
... | medium |
1862 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have an <var>H</var>-by-<var>W</var> matrix.
Let <var>a_{ij}</var> be the element at the <var>i</var>-th row from the top and <var>j</var>-th column from the left.
In this matrix, each <var>a_{ij}</v... | int solution(void) {
int h;
int w;
scanf("%d %d", &h, &w);
char a[h][w + 1];
for (int i = 0; i < h; i++) {
scanf("%s", a[i]);
}
int alp[26];
for (int i = 0; i < 26; i++) {
alp[i] = 0;
}
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
alp[a[i][j] - 'a']++;
}
}
i... | fn solution() {
let (H, W): (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 |
1863 | Omkar is building a waterslide in his water park, and he needs your help to ensure that he does it as efficiently as possible.Omkar currently has $$$n$$$ supports arranged in a line, the $$$i$$$-th of which has height $$$a_i$$$. Omkar wants to build his waterslide from the right to the left, so his supports must be non... | int solution() {
int t;
scanf("%d", &t);
while (t) {
int n;
long long d = 0;
long long sum = 0;
scanf("%d", &n);
long long a[n];
for (long long i = 0; i < n; i++) {
scanf("%lld ", &a[i]);
}
for (int i = n - 1; i > 0; i--) {
d = a[i - 1] - a[i];
if (d > 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: usize = {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap()... | medium |
1864 | Ashish has a binary string $$$s$$$ of length $$$n$$$ that he wants to sort in non-decreasing order.He can perform the following operation: Choose a subsequence of any length such that its elements are in non-increasing order. Formally, choose any $$$k$$$ such that $$$1 \leq k \leq n$$$ and any sequence of $$$k$$$ ind... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
char string[n + 1];
scanf("%s", string);
int ans[n + 1];
int one = 0;
int zero = 0;
for (int i = 0; i < n; i++) {
if (string[i] == '1') {
one++;
} else {
zero++;
}
... | 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 x, mut y) = (vec![], vec![]);
for (j, c) in l.unwrap().chars().enumerate() {
if c == '0' {
x.push(j)
} else... | hard |
1865 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>N</var> bulbs arranged on a number line, numbered <var>1</var> to <var>N</var> from left to right.
Bulb <var>i</var> is at coordinate <var>i</var>.</p>
<p>Each bulb has a non-negative integ... | int solution() {
int n;
int k;
scanf("%d%d", &n, &k);
int a[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
int b[n];
for (; k > 0; k--) {
int j = 0;
for (int i = 0; i < n; i++) {
if (a[i] < n) {
j++;
}
}
if (j == 0) {
break;
}
for (int i = 0... | fn solution() {
let mut is = String::new();
stdin().read_line(&mut is).ok();
let mut itr = is.split_whitespace().map(|e| e.parse::<usize>().unwrap());
let n: usize = itr.next().unwrap();
let k: usize = itr.next().unwrap();
is.clear();
stdin().read_line(&mut is).ok();
let mut a = is
... | medium |
1866 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke received a positive integer <var>N</var> from Takahashi.
A positive integer <var>m</var> is called a <em>favorite number</em> when the following condition is satisfied:</p>
<ul>
<li>The quotient a... | int solution() {
long long int n = 0;
long long int sum = 0;
scanf("%lld\n", &n);
for (long long int i = 1; i * (i + 1) + 1 <= n; i++) {
if ((n - i) % i == 0) {
sum += (n - i) / i;
}
}
printf("%lld\n", sum);
return 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 mut ans = 0;
let mut i = 1;
while i * i <= n {
if n.is_multiple_of(i) {
let d = n... | medium |
1867 | <H1>Prime Numbers</H1>
<p>
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, 5 and 7.
</p>
<p>
Write a program which reads a list of <i>N</i> integers and prints the number of prime numbers in the list.
</p>
<... | int solution() {
int N = 0;
int number = 0;
int i = 0;
int divide = 0;
int count = 0;
int flag = 0;
scanf("%d", &N);
for (i = 0; i < N; i++) {
scanf("%d", &number);
divide = 2;
flag = 0;
while (divide * divide <= number) {
if ((number % divide) == 0) {
flag = 1;
br... | fn solution() {
let mut s = String::new();
let stdin = io::stdin();
let _ = stdin.read_line(&mut s);
let n: usize = s.trim().parse().unwrap();
s.clear();
let nums = stdin
.lock()
.lines()
.take(n)
.map(|s| s.ok().unwrap().trim().parse().unwrap_or(0));
let... | medium |
1868 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a string <var>s</var> consisting of lowercase English letters.
Snuke can perform the following operation repeatedly:</p>
<ul>
<li>Insert a letter <code>x</code> to any position in <var>s</var> o... | int solution() {
int ans = 0;
int flag = 0;
int first = 0;
int last = 99999;
char s[100001];
scanf("%s", s);
last = strlen(s) - 1;
while (flag == 0) {
if (s[first] != s[last] && s[first] != 'x' && s[last] != 'x') {
flag++;
} else if (s[first] == s[last]) {
first++;
last--;
... | fn solution() {
let mut s: String = String::new();
std::io::stdin().read_to_string(&mut s).ok();
let mut itr = s.split_whitespace();
let s: Vec<char> = itr.next().unwrap().chars().collect();
let mut l = 0;
let mut r = s.len() - 1;
let mut ans = 0;
while r > l {
if s[l] == s[r] {... | easy |
1869 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>An altar enshrines <var>N</var> stones arranged in a row from left to right. The color of the <var>i</var>-th stone from the left <var>(1 \leq i \leq N)</var> is given to you as a character <var>c_i</va... | int solution(void) {
int n;
scanf("%d", &n);
char s[n + 1];
scanf("%s", s);
int r = 0;
int w = 0;
int ans[n];
for (int i = 0; i < n; i++) {
ans[i] = w;
(*(s[i] == 'R' ? &r : &w))++;
}
printf("%d\n", r < n ? ans[r] : 0);
} | fn solution() {
let mut s = String::new();
io::stdin().read_line(&mut s).ok();
let n: usize = s.trim().parse().ok().unwrap();
let mut s = String::new();
io::stdin().read_line(&mut s).ok();
let (mut r, mut w) = (VecDeque::new(), VecDeque::new());
r.push_back(0);
for (i, c) in s.trim().ch... | easy |
1870 | Jump search | int solution(const int *arr, int x, size_t n) {
if (n == 0)
return -1;
size_t step = (size_t)floor(sqrt((double)n));
size_t prev = 0;
size_t current_limit;
while (1) {
current_limit = (step < n) ? step : n;
if (arr[current_limit - 1] >= x) {
break;
}
prev = step;
step += (siz... | fn solution<T: Ord>(item: &T, arr: &[T]) -> Option<usize> {
let len = arr.len();
if len == 0 {
return None;
}
let mut step = (len as f64).sqrt() as usize;
let mut prev = 0;
while &arr[min(len, step) - 1] < item {
prev = step;
step += (len as f64).sqrt() as usize;
... | medium |
1871 | Suppose you are living with two cats: A and B. There are $$$n$$$ napping spots where both cats usually sleep.Your cats like to sleep and also like all these spots, so they change napping spot each hour cyclically: Cat A changes its napping place in order: $$$n, n - 1, n - 2, \dots, 3, 2, 1, n, n - 1, \dots$$$ In othe... | int solution() {
int j = 0;
int n;
int k;
int t;
scanf("%d", &t);
int ans[t];
while (j++ < t) {
scanf("%d %d", &n, &k);
if (n % 2 == 0) {
ans[j] = (k - 1) % n + 1;
} else {
ans[j] = ((k - 1) % n + (k - 1) / (n / 2)) % n + 1;
}
}
j = 0;
while (j++ < t) {
printf("%d\n",... | fn solution() {
let mut t = String::new();
io::stdin().read_line(&mut t).unwrap();
let t: usize = t.trim().parse().unwrap();
let mut n_k = String::new();
for _t in 0..t {
n_k.clear();
io::stdin().read_line(&mut n_k).unwrap();
let mut n_k = n_k.split_whitespace();
let... | medium |
1872 | <H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
... | int solution() {
int i = 0;
int count = 0;
int tate = 0;
int yoko = 0;
int change = 0;
int in_out_box[30 + 1];
int num1 = 0;
int num1_index = 0;
int num2 = 0;
int num2_index = 0;
char str[10];
scanf("%d", &tate);
fgets(str, (sizeof(str)), stdin);
for (i = 0; i < tate; i++) {
in_out_box... | fn solution() {
let mut w: u32 = 0;
for i in 0..2 {
let mut buf = String::new();
stdin().read_line(&mut buf).unwrap();
match i {
0 => w = buf.trim().parse().unwrap(),
_ => break,
}
}
let reader = BufReader::new(stdin());
let mut hlines = vec![]... | hard |
1873 | You are given a board of size $$$2 \times n$$$ ($$$2$$$ rows, $$$n$$$ columns). Some cells of the board contain chips. The chip is represented as '*', and an empty space is represented as '.'. It is guaranteed that there is at least one chip on the board.In one move, you can choose any chip and move it to any adjacent ... | int solution() {
int t = 0;
int n = 0;
char s[2][200001] = {};
int res = 0;
int visited[2][200000] = {};
int rchip[2][200000] = {};
res = scanf("%d", &t);
while (t > 0) {
int cnt[2] = {};
int min = 0;
int ans = 0;
res = scanf("%d", &n);
res = scanf("%s", s[0]);
res = scanf("%... | fn solution() {
let stdin = io::stdin();
let stdin = stdin.lock();
let mut lines = stdin.lines();
lines.next();
while let (Some(_), Some(Ok(first_line)), Some(Ok(second_line))) =
(lines.next(), lines.next(), lines.next())
{
let (mut a, mut b) = (false, false);
let mut cou... | medium |
1874 | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n ... | int solution() {
int t;
long long l;
long long r;
long long m;
scanf("%d", &t);
while (t--) {
scanf("%lld %lld %lld", &l, &r, &m);
long long min = m + l - r;
long long max = m - l + r;
for (long long a = l; a <= r; a++) {
if ((max / a) * a >= min && (max / a > 0)) {
long lon... | 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 (l, r, m): (u64, u64, u64) = {
let mut buf = String::new();
std::io::stdin().read_line(... | easy |
1875 | Kristina has two arrays $$$a$$$ and $$$b$$$, each containing $$$n$$$ non-negative integers. She can perform the following operation on array $$$a$$$ any number of times: apply a decrement to each non-zero element of the array, that is, replace the value of each element $$$a_i$$$ such that $$$a_i > 0$$$ with the va... | int solution() {
int a[50000];
int b[50000];
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i < n; i++) {
scanf("%d", &b[i]);
}
int max = 0;
for (int i = 0; i < n; i++) {
int c ... | fn solution() {
let mut num = String::new();
io::stdin().read_line(&mut num).unwrap();
let num = num.trim().parse::<u32>().unwrap();
'main: for _ in 0..num {
let mut _ln: String = String::new();
io::stdin().read_line(&mut _ln).unwrap();
let ln: usize = _ln.trim().parse::<u32>().u... | medium |
1876 | You have an axis-aligned rectangle room with width $$$W$$$ and height $$$H$$$, so the lower left corner is in point $$$(0, 0)$$$ and the upper right corner is in $$$(W, H)$$$.There is a rectangular table standing in this room. The sides of the table are parallel to the walls, the lower left corner is in $$$(x_1, y_1)$$... | int solution() {
int test;
scanf("%d", &test);
float ans[test];
for (int i = 0; i < test; i++) {
int W;
int H;
int x1;
int y1;
int x2;
int y2;
int w;
int h;
scanf("%d%d%d%d%d%d%d%d", &W, &H, &x1, &y1, &x2, &y2, &w, &h);
ans[i] = 100000000;
if (W >= w + x2 - x1) {
... | fn solution() {
let mut t = String::new();
io::stdin().read_line(&mut t).unwrap();
let t: usize = t.trim().parse().unwrap();
let mut line = String::new();
for _t in 0..t {
line.clear();
io::stdin().read_line(&mut line).unwrap();
let mut rw_rh = line.split_whitespace();
... | medium |
1877 | <H1>A/B Problem</H1>
<p>
Write a program which reads two integers <var>a</var> and <var>b</var>, and calculates the following values:
</p>
<ul>
<li><var>a</var> ÷ <var>b</var>: <var>d</var> (in integer)</li>
<li>remainder of <var>a</var> ÷ <var>b</var>: <var>r</var> (in integer)</li>
<li><var>a<... | int solution() {
double x;
double y;
scanf("%lf %lf", &x, &y);
printf("%.0lf %.0lf %.5lf\n", floor(x / y), x - (y * (int)(x / y)), x / y);
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 a: u32 = vec[0].parse().unwrap_or(0);
let b: u32 = vec[1].parse().unwrap_or(0);
println!("{} {} {:.5}", &(a / b), &(a % b)... | medium |
1878 | You are given an array $$$a$$$ consisting of $$$n$$$ ($$$n \ge 3$$$) positive integers. It is known that in this array, all the numbers except one are the same (for example, in the array $$$[4, 11, 4, 4]$$$ all numbers except one are equal to $$$4$$$).Print the index of the element that does not equal others. The numbe... | int solution() {
int t = 0;
scanf("%d", &t);
while (t--) {
int n = 0;
int k = 0;
scanf("%d", &n);
int a[n];
scanf("%d", &a[0]);
for (int i = 1; i < n; i++) {
scanf("%d", &a[i]);
if (a[i] != a[i - 1]) {
k = i;
}
}
if (a[n - 1] != a[n - 2] && a[n - 2] == a[n... | fn solution() -> Result<(), Box<dyn Error>> {
let stdin = std::io::stdin();
let mut input = stdin.lock();
let stdout = std::io::stdout();
let mut output = stdout.lock();
let mut buffer = String::with_capacity(32);
input.read_line(&mut buffer)?;
let tests = buffer.trim().parse::<u32>()?;
... | hard |
1879 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a sequence of positive integers of length <var>N</var>, <var>a = (a_1, a_2, ..., a_N)</var>.
Your objective is to remove some of the elements in <var>a</var> so that <var>a</var> will be a... | int solution() {
int N;
int p = 0;
scanf("%d", &N);
int a[N];
int b[N];
for (int i = 0; i <= N; i++) {
b[i] = 0;
}
for (int i = 0; i < N; i++) {
scanf("%d", &a[i]);
if (a[i] > N) {
p++;
} else {
b[a[i]]++;
}
}
for (int i = 1; i <= N; i++) {
if (b[i] != i && b[i] !... | fn solution() {
let si = io::stdin();
let mut si = si.lock();
si.read_until(b'\n', &mut Vec::new()).unwrap();
println!(
"{}",
si.split(b' ')
.map(|r| String::from_utf8(r.unwrap())
.unwrap()
.trim_end()
.parse::<u32>()
... | medium |
1880 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given two integer sequences <var>S</var> and <var>T</var> of length <var>N</var> and <var>M</var>, respectively, both consisting of integers between <var>1</var> and <var>10^5</var> (inclusive).... | int solution() {
int n;
int m;
scanf("%d %d", &n, &m);
int i;
int j;
int s[2003];
int t[2003];
for (i = 0; i < n; i++) {
scanf("%d", &s[i]);
}
for (i = 0; i < m; i++) {
scanf("%d", &t[i]);
}
long long int p = 1000000007;
long long int dp[2003][2003];
for (i = 0; i < 2003; i++) {
... | fn solution() {
input! {
n: usize,
m: usize,
s: [usize; n],
t: [usize; m]
}
let d = 1000000007;
let mut tab: Vec<Vec<usize>> = vec![vec![0; m + 1]; n + 1];
for i in 0..n + 1 {
tab[i][0] = 1;
}
for j in 0..m + 1 {
tab[0][j] = 1;
}
for i ... | medium |
1881 | <span class="lang-en">
<p>Score: <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>M-kun is a competitor in AtCoder, whose highest rating is <var>X</var>.<br/>
In this site, a competitor is given a <em>kyu</em> (class) according to his/her highest rating. For ratings from <var>400</va... | int solution(void) {
int X = 0;
scanf("%d", &X);
if (X >= 400 && X <= 599) {
printf("8\n");
} else if (X >= 600 && X <= 799) {
printf("7\n");
} else if (X >= 800 && X <= 999) {
printf("6\n");
} else if (X >= 1000 && X <= 1199) {
printf("5\n");
} else if (X >= 1200 && X <= 1399) {
pri... | fn solution() -> io::Result<()> {
let s = {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
s.trim_end().to_owned()
};
let num: i32 = s.parse().unwrap();
match num {
400..=599 => println!("8"),
600..=799 => println!("7"),
800..=99... | easy |
1882 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are three airports A, B and C, and flights between each pair of airports in both directions.</p>
<p>A one-way flight between airports A and B takes <var>P</var> hours, a one-way flight between air... | int solution() {
int a = 0;
int b = 0;
int c = 0;
int menor = 0;
scanf("%d%d%d", &a, &b, &c);
if (c >= a && c >= b) {
menor = a + b;
} else if (a >= c && a >= b) {
menor = c + b;
} else if (b >= a && b >= c) {
menor = a + c;
}
printf("%d\n", menor);
return 0;
} | fn solution() {
let mut pqr = String::new();
stdin().read_line(&mut pqr).unwrap();
let mut pqr: Vec<isize> = pqr.split_whitespace().flat_map(str::parse).collect();
pqr.sort();
println!("{}", pqr[0] + pqr[1]);
} | hard |
1883 | Being stuck at home, Ray became extremely bored. To pass time, he asks Lord Omkar to use his time bending power: Infinity Clock! However, Lord Omkar will only listen to mortals who can solve the following problem:You are given an array $$$a$$$ of $$$n$$$ integers. You are also given an integer $$$k$$$. Lord Omkar wants... | int solution() {
int t;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
int n;
long long k;
scanf("%d %lld", &n, &k);
int a[n];
for (int j = 0; j < n; j++) {
scanf("%d", &a[j]);
}
int max = a[0];
int min = a[0];
for (int j = 1; j < n; j++) {
if (max < a[j]) {
... | fn solution() {
let reader = BufReader::new(stdin());
let mut lines = reader.lines();
let cases: usize = lines.next().unwrap().unwrap().parse().unwrap();
let mut lines_take = lines.take(cases << 1);
for _ in 0..cases {
let info = lines_take.next().unwrap().unwrap();
let mut info_sp =... | medium |
1884 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>For a positive integer <var>X</var>, let <var>f(X)</var> be the number of positive divisors of <var>X</var>.</p>
<p>Given a positive integer <var>N</var>, find <var>\sum_{K=1}^N K\times f(K)</var>.</p>
... | int solution(void) {
long int n;
scanf("%ld", &n);
long int ans = 0;
for (int i = 1; i <= n; i++) {
long int now = n / i;
ans += (now + 1) * now / 2 * i;
}
printf("%ld\n", ans);
return 0;
} | fn solution() {
let mut s = String::new();
io::stdin().read_line(&mut s).ok();
let n: u64 = s.trim().parse().unwrap();
let mut v: Vec<(u64, u64)> = (1..(n + 1))
.map(|e| (e, n / e))
.filter(|(e, _)| e * e <= n)
.collect();
let x = v[v.len() - 1];
let mut ans = 0;
if ... | hard |
1885 | <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>Min, Max and Sum</h1>
<p>
W... | int solution(void) {
int n = 0;
int a = 0;
int maximum = -1000000;
int minimum = 1000000;
long sum = 0;
scanf("%d", &n);
while (scanf("%d", &a) != EOF) {
sum += a;
if (a >= maximum) {
maximum = a;
}
if (a <= minimum) {
minimum = a;
}
}
printf("%d %d %ld\n", minimum, ... | fn solution() {
let stdin = io::stdin();
let mut buf = String::new();
let _ = stdin.read_line(&mut buf);
buf.clear();
let _ = stdin.read_line(&mut buf);
let vec: Vec<i64> = buf
.split_whitespace()
.map(|x| i64::from_str(x).unwrap())
.collect();
println!(
"{... | medium |
1886 | After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum nu... | int solution() {
long long int n;
long long int count = 0;
long long int a = 0;
long long int b = 0;
long long int c = 0;
scanf("%lld", &n);
long long int arr[n];
for (int i = 0; i < n; i++) {
scanf("%lld", &arr[i]);
}
for (int i = 0; i < n; i++) {
if (arr[i] == 4) {
count++;
}
... | 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 nums = buffer
.split_whitespace()
... | easy |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.