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 |
|---|---|---|---|---|
0401 | You are playing a computer game. To pass the current level, you have to kill a big horde of monsters. In this horde, there are $$$n$$$ monsters standing in the row, numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$a_i$$$ health and a special "Death's Blessing" spell of strength $$$b_i$$$ attached to it.Y... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int a[n];
int b[n];
long long sum = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
scanf("%d", &b[0]);
int max = b[0];
sum += b[0] + a[0];
for (int i = 1; i < n; i++) {
sc... | fn solution() {
let mut buffer = String::new();
io::stdin().read_line(&mut buffer).unwrap();
let t = buffer.trim().parse::<u16>().unwrap();
for _ in 0..t {
buffer = String::new();
io::stdin().read_line(&mut buffer).unwrap();
let n = buffer.trim().parse::<u32>().unwrap();
... | easy |
0402 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a bingo card with a <var>3\times3</var> grid. The square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left contains the number <var>A_{i, j}</var>.</p>
<p>The ... | int solution() {
int flag = 0;
int card[3][3] = {0};
int A[3][3] = {0};
int N = 0;
int b[100] = {0};
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
scanf("%d", &A[i][j]);
}
}
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%d", &b[i]);
}
for (int i = 0; i < N; ... | fn solution() {
let mut A = Vec::<Vec<i64>>::new();
for _ in 0..3 {
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();
A.push(words... | medium |
0403 | Jett is tired after destroying the town and she wants to have a rest. She likes high places, that's why for having a rest she wants to get high and she decided to craft staircases.A staircase is a squared figure that consists of square cells. Each staircase consists of an arbitrary number of stairs. If a staircase has ... | int solution(void) {
int a = 0;
scanf("%d", &a);
while (a--) {
long long k;
scanf("%lld", &k);
int m = 0;
for (long long n = 1; n * (n + 1) / 2 <= k; n = 2 * n + 1) {
k -= n * (n + 1) / 2;
m++;
}
printf("%d\n", m);
}
return 0;
} | fn solution() {
let stdin = std::io::stdin();
let mut handle = stdin.lock();
let mut buf = String::new();
handle.read_line(&mut buf).unwrap();
let tests: i64 = buf.trim().parse().unwrap();
for _test in 0..tests {
buf.clear();
handle.read_line(&mut buf).unwrap();
let mu... | medium |
0404 | Boboniu gives you $$$r$$$ red balls, $$$g$$$ green balls, $$$b$$$ blue balls, $$$w$$$ white balls. He allows you to do the following operation as many times as you want: Pick a red ball, a green ball, and a blue ball and then change their color to white. You should answer if it's possible to arrange all the balls... | int solution() {
int t = 0;
int i = 0;
int r = 0;
int g = 0;
int b = 0;
int w = 0;
int p = 0;
int j = 0;
int arr[4];
scanf("%d", &t);
for (i = 1; i <= t; i++) {
scanf("%d %d %d %d", &r, &g, &b, &w);
arr[0] = r % 2;
arr[1] = g % 2;
arr[2] = b % 2;
arr[3] = w % 2;
j = 0;
... | fn solution() {
let stdin = io::stdin();
let mut input = stdin.lock();
let mut line = String::new();
input.read_line(&mut line).unwrap();
let mut tests: u8 = line.trim().parse().unwrap();
while tests > 0 {
line.clear();
input.read_line(&mut line).unwrap();
let mut iter = ... | medium |
0405 | <h1>Enumeration of Subsets I</h1>
<p>
Print all subsets of a set $S$, which contains $0, 1, ... n-1$ as elements. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elements... | int solution() {
long long k = 0;
int n;
scanf("%d", &n);
printf("0:\n");
for (int s = 1; s < pow(2, n); s++) {
printf("%d:", s);
for (int i = 0; i <= n - 1; i++) {
if (s & (1 << i)) {
printf(" %d", i);
}
}
printf("\n");
}
} | fn solution() {
let mut input = String::new();
stdin().read_line(&mut input);
input.pop();
let n = input.parse().unwrap();
let out = stdout();
let mut out = BufWriter::new(out.lock());
writeln!(out, "0:");
for p in 0..n {
for d in (1 << p)..(2 << p) {
write!(out, "... | medium |
0406 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an undirected connected graph with <var>N</var> vertices and <var>M</var> edges that does not contain self-loops and double edges.<br/>
The <var>i</var>-th edge <var>(1 \leq i \leq M)</var... | int solution(void) {
int n;
int m;
scanf("%d %d", &n, &m);
int a[m];
int b[m];
for (int i = 0; i < m; i++) {
scanf("%d %d", &a[i], &b[i]);
}
int check_list[n + 1];
int flag;
int bridge = 0;
for (int i = 0; i < m; i++) {
for (int j = 1; j <= n; j++) {
check_list[j] = 0;
}
if ... | fn solution() {
let (n, m) = input!(usize, usize);
let mut edges: Vec<(usize, usize)> = Vec::with_capacity(m);
let mut graph: Vec<Vec<bool>> = vec![vec![false; n + 1]; n + 1];
for _ in 0..m {
let (from, to) = input!(usize, usize);
graph[from][to] = true;
graph[to][from] = true;
... | medium |
0407 | <h3>Tax Rate Changed</h3>
<p>
VAT (value-added tax) is a tax imposed at a certain rate proportional to the sale price.
</p>
<p>
Our store uses the following rules to calculate the after-tax prices.
</p>
<ul>
<li>
When the VAT rate is <i>x</i>%,
for an item with the before-tax price of <i>p<... | int solution(void) {
while (1) {
int x;
int y;
int s;
scanf("%d %d %d", &x, &y, &s);
if (x == 0) {
break;
}
int max = 0;
for (int i = 1; i <= s; i++) {
for (int j = 1; j <= s; j++) {
if (i * (100 + x) / 100 + j * (100 + x) / 100 == s) {
if (max < i * (100 ... | fn solution() {
loop {
let mut buf = String::new();
io::stdin().read_line(&mut buf).ok();
let mut iter = buf.split_whitespace().map(|n| usize::from_str(n).unwrap());
let (x, y, s) = (
iter.next().unwrap(),
iter.next().unwrap(),
iter.next().unwrap()... | easy |
0408 | This year in Equestria was a year of plenty, so Applejack has decided to build some new apple storages. According to the advice of the farm designers, she chose to build two storages with non-zero area: one in the shape of a square and another one in the shape of a rectangle (which possibly can be a square as well).App... | int solution() {
int frec[100001] = {0};
char temp[2];
long long int n = 0;
long long int flag4 = 0;
long long int flag2 = 0;
scanf("%lld", &n);
long long int max = 0;
for (long long int i = 0; i < n; i++) {
long long int tmp = 0;
scanf("%lld", &tmp);
flag4 -= frec[tmp] / 4;
flag2 -= fre... | 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: usize = {
let mut buf = String::new();
reader.read_line(&mut buf).unwrap();
b... | medium |
0409 | <span class="lang-en">
<p>Score: <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Mr. Infinity has a string <var>S</var> consisting of digits from <code>1</code> to <code>9</code>. Each time the date changes, this string changes as follows:</p>
<ul>
<li>Each occurrence of <code>2</c... | int solution() {
char s[101];
long n;
scanf("%s %ld", s, &n);
int i = 0;
while (s[i] == '1' && i < n - 1) {
i++;
}
printf("%c\n", s[i]);
return 0;
} | fn solution() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
let sb: Vec<char> = s.trim().chars().collect();
let mut ns = String::new();
std::io::stdin().read_line(&mut ns).unwrap();
let k: usize = ns.trim().parse().unwrap();
let mut i: usize = 0;
while i < k ... | easy |
0410 | There are three cells on an infinite 2-dimensional grid, labeled $$$A$$$, $$$B$$$, and $$$F$$$. Find the length of the shortest path from $$$A$$$ to $$$B$$$ if: in one move you can go to any of the four adjacent cells sharing a side; visiting the cell $$$F$$$ is forbidden (it is an obstacle). | int solution() {
int t;
int ansar[10005];
scanf("%d", &t);
int start[2];
int end[2];
int obstacle[2];
for (int y = 0; y < t; y++) {
scanf("%d %d", &start[0], &start[1]);
scanf("%d %d", &end[0], &end[1]);
scanf("%d %d", &obstacle[0], &obstacle[1]);
int ansx = end[0] < start[0] ? start[0] - ... | fn solution() {
let (i, o) = (io::stdin(), io::stdout());
let mut o = bw::new(o.lock());
let mut i = i.lock().lines().skip(1);
while let Some(_) = i.next() {
if let [(ax, ay), (bx, by), (fx, fy)] = (0..3)
.map(|_| {
i.next()
.unwrap()
... | medium |
0411 | Theofanis really likes sequences of positive integers, thus his teacher (Yeltsa Kcir) gave him a problem about a sequence that consists of only special numbers.Let's call a positive number special if it can be written as a sum of different non-negative powers of $$$n$$$. For example, for $$$n = 4$$$ number $$$17$$$ is ... | int solution() {
int t = 0;
scanf("%d", &t);
while (t--) {
int n;
int k;
scanf("%d %d", &n, &k);
long long sum = 0;
long long p = 1;
while (k > 0) {
if (k % 2 == 1) {
sum = (sum + p) % 1000000007;
}
k /= 2;
p = p * n % 1000000007;
}
sum = sum % 1000... | 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 t: usize = it.next().unwrap().parse().unwrap();
let mut out = String::new();
let m = i64::pow(10, 9) + 7;
for _ in 1..=t {
l... | easy |
0412 | A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $$$0$$$ are not allowed).Let's cons... | int solution() {
const int N = 110;
int n;
int m;
scanf("%d %d", &n, &m);
char str[N];
int k;
int a[N][N];
int c[N][N];
int dist[N][N];
int t = 0;
int i;
int j;
for (i = 1; i <= n; i++) {
scanf("%s", str);
for (j = 0; j < m; j++) {
if (str[j] == '*') {
a[i][j + 1] = 1;
... | fn solution() {
let input_handle = io::stdin();
let input_line = &mut String::new();
input_handle.read_line(input_line).unwrap();
let mut input_parts = input_line
.split_whitespace()
.map(|token| token.parse::<usize>().unwrap());
let n = input_parts.next().unwrap();
let m = input... | easy |
0413 | You are given a string $$$s$$$ of length $$$n$$$ consisting only of the characters 0 and 1.You perform the following operation until the string becomes empty: choose some consecutive substring of equal characters, erase it from the string and glue the remaining two parts together (any of them can be empty) in the same ... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
int a;
int b;
scanf("%d %d %d", &n, &a, &b);
char *s = malloc(sizeof(char) * (n + 1));
scanf("%s", s);
s[n] = '\0';
int cost = a * n;
if (b >= 0) {
cost += b * n;
} else {
int num_o_groups = 0;
... | fn solution() {
let mut line = {
let mut lines = std::io::stdin().lines();
move || lines.next().unwrap().unwrap()
};
for _ in 0..line().parse().unwrap() {
let (n, a, b) = {
let line = line();
let mut line = line.split_whitespace().map(|x| x.parse::<i32>().unwr... | medium |
0414 | A penguin Rocher has $$$n$$$ sticks. He has exactly one stick with length $$$i$$$ for all $$$1 \le i \le n$$$.He can connect some sticks. If he connects two sticks that have lengths $$$a$$$ and $$$b$$$, he gets one stick with length $$$a + b$$$. Two sticks, that were used in the operation disappear from his set and the... | int solution() {
int tests = 0;
scanf("%d", &tests);
while (tests--) {
int n = 0;
scanf("%d", &n);
printf("%d\n", (n / 2) + (n % 2));
}
return 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 n: usize = lines.next().unwrap().unwrap().parse().unwrap();
println!("{}", (n - 1) / 2 + 1);
}
} | medium |
0415 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>A</var> cards, each of which has an integer <var>1</var> written on it. Similarly, we also have <var>B</var> cards with <var>0</var>s and <var>C</var> cards with <var>-1</var>s.</p>
<p>We w... | int solution() {
long long int A = 0;
long long int B = 0;
long long int C = 0;
long long int K = 0;
scanf("%lld %lld %lld %lld", &A, &B, &C, &K);
if (A <= K && K <= A + B) {
printf("%lld", A);
} else if (K < A) {
printf("%lld", K);
} else {
printf("%lld", A - (K - A - B));
}
return 0... | fn solution() {
let mut line = String::new();
io::stdin().read_line(&mut line).unwrap();
let nums: Vec<i32> = line
.split_whitespace()
.map(|x| x.parse().unwrap())
.collect();
let (mut a, b, _, mut k) = (nums[0], nums[1], nums[2], nums[3]);
if k >= a {
k -= a;
} ... | medium |
0416 | A Pythagorean triple is a triple of integer numbers $$$(a, b, c)$$$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $$$a$$$, $$$b$$$ and $$$c$$$, respectively. An example of the Pythagorean triple is $$$(3, 4, 5)$$$.Vasya studies ... | int solution(void) {
int T;
int N;
scanf("%d", &T);
while (T--) {
scanf("%d", &N);
int i = 1;
while (2 * i * i + 2 * i + 1 <= N) {
i++;
}
printf("%d\n", i - 1);
}
} | fn solution() {
use std::io::{self, Write};
let (stdin, stdout) = (io::stdin(), io::stdout());
let mut sc = cf_scanner::Scanner::new(stdin.lock());
let mut out = io::BufWriter::new(stdout.lock());
let n: usize = sc.next();
let queries: Vec<i64> = (0..n).map(|_| sc.next()).collect();
let mu... | hard |
0417 | Madoka as a child was an extremely capricious girl, and one of her favorite pranks was drawing on her wall. According to Madoka's memories, the wall was a table of $$$n$$$ rows and $$$m$$$ columns, consisting only of zeroes and ones. The coordinate of the cell in the $$$i$$$-th row and the $$$j$$$-th column ($$$1 \le i... | int solution(void) {
static char M[101][101];
int t;
int n;
int m;
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%s", M[i] + 1);
}
if (M[1][1] == '1') {
puts("-1");
continue;
}
printf("%d\n", n * m);
for (int i = n; ... | 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 tests = input.token();
for _ in 0..tests {
let (n, m): (usize, usize) = (input.token(), input.token());
let a: Vec<Vec... | medium |
0418 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an array <var>A</var> of length <var>N</var>.
Your task is to divide it into several contiguous subarrays.
Here, all subarrays obtained must be sorted in either non-decreasing or non-incre... | int solution() {
int n;
int ans = 0;
int a[100001];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i < n; i++) {
while (i < n - 1 && a[i] == a[i + 1]) {
i++;
}
if (i < n - 1 && a[i] < a[i + 1]) {
while (i < n - 1 && a[i] <= a[i + 1]) {
... | fn solution() {
let _N: usize = {
let mut line: String = String::new();
std::io::stdin().read_line(&mut line).unwrap();
line.trim().parse().unwrap()
};
let A: Vec<i64> = {
let mut line: String = String::new();
std::io::stdin().read_line(&mut line).unwrap();
li... | hard |
0419 | Initially, you have the array $$$a$$$ consisting of one element $$$1$$$ ($$$a = [1]$$$).In one move, you can do one of the following things: Increase some (single) element of $$$a$$$ by $$$1$$$ (choose some $$$i$$$ from $$$1$$$ to the current length of $$$a$$$ and increase $$$a_i$$$ by one); Append the copy of some (... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int root = sqrt(n);
if (root * root >= n) {
printf("%d\n", (2 * root) - 2);
} else if ((root + 1) * root >= n) {
printf("%d\n", (2 * root) - 1);
} else {
printf("%d\n", 2 * root);
}
}
} | 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 n = String::new();
io::stdin().read_line(&mut n).unwrap();
let n = n.trim().parse::<i32>().unwrap();
let mut ans = 10000... | hard |
0420 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>AtCoDeer the deer is seeing a quick report of election results on TV.
Two candidates are standing for the election: Takahashi and Aoki.
The report shows the ratio of the current numbers of votes the two... | int solution() {
int n;
scanf("%d", &n);
long long int t[n];
long long int a[n];
for (int i = 0; i < n; i++) {
scanf("%lld%lld", &t[i], &a[i]);
}
long long int tz = t[0];
long long int az = a[0];
for (int i = 1; i < n; i++) {
long long int r = tz / t[i];
long long int s = az / a[i];
lo... | fn solution() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
let n: usize = s.trim().parse().unwrap();
let mut x: usize = 1;
let mut a: usize = 0;
let mut b: usize = 0;
for _ in 0..n {
let mut s = String::new();
std::io::stdin().read_line(&mut s).u... | hard |
0421 | Homer has two friends Alice and Bob. Both of them are string fans. One day, Alice and Bob decide to play a game on a string $$$s = s_1 s_2 \dots s_n$$$ of length $$$n$$$ consisting of lowercase English letters. They move in turns alternatively and Alice makes the first move.In a move, a player must choose an index $$$i... | int solution(void) {
int tc = 1;
scanf("%d", &tc);
while (tc--) {
char str[50];
scanf("%s", str);
for (int i = 0; str[i]; i++) {
if (i % 2) {
if (str[i] == 'z') {
str[i] = 'y';
} else {
str[i] = 'z';
}
} else {
if (str[i] == 'a') {
... | fn solution() {
let k = std::io::stdin()
.lock()
.lines()
.next()
.unwrap()
.unwrap()
.parse::<i32>()
.unwrap();
for _ele in 0..k {
let mut kstr = String::new();
std::io::stdin().read_line(&mut kstr).unwrap();
let kstr = kstr.trim()... | easy |
0422 | There is a sheet of paper that can be represented with a grid of size $$$n \times m$$$: $$$n$$$ rows and $$$m$$$ columns of cells. All cells are colored in white initially.$$$q$$$ operations have been applied to the sheet. The $$$i$$$-th of them can be described as follows: $$$x_i$$$ $$$y_i$$$ — choose one of $$$k$$$... | int solution() {
int t = 0;
int nm[2] = {};
long long k = 0LL;
int q = 0;
int xy[200000][2] = {};
int res = 0;
long long mod_num = 998244353;
int colored[2][200000] = {};
res = scanf("%d", &t);
while (t > 0) {
long long ans = 1LL;
int colored_cnt[2] = {};
res = scanf("%d", nm);
r... | fn solution() {
let stdin = stdin();
let mut stdin = stdin.lock();
let mut buf = String::new();
stdin.read_to_string(&mut buf).unwrap();
let input = &mut buf
.split_ascii_whitespace()
.map(|s| s.parse::<u32>().unwrap());
let mut input = || input.next().unwrap();
let nn = i... | medium |
0423 | Phoenix is playing with a new puzzle, which consists of $$$n$$$ identical puzzle pieces. Each puzzle piece is a right isosceles triangle as shown below. A puzzle piece The goal of the puzzle is to create a square using the $$$n$$$ pieces. He is allowed to rotate and move the pieces around, but none of them can overl... | int solution() {
int n;
scanf("%d", &n);
int a[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
int c;
for (int i = 0; i < n; i++) {
c = 0;
for (int j = 1; j < 100000; j++) {
if ((a[i] == 2 * j * j) || (a[i] == 4 * j * j)) {
c += 1;
break;
}
if ((a[i] <... | fn solution() {
let mut t = String::new();
io::stdin().read_line(&mut t).unwrap();
let t: usize = t.trim().parse().unwrap();
let mut n = String::new();
'test: for _t in 0..t {
n.clear();
io::stdin().read_line(&mut n).unwrap();
let mut n: u64 = n.trim().parse().unwrap();
... | hard |
0424 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has an empty sequence <var>a</var>.</p>
<p>He will perform <var>N</var> operations on this sequence.</p>
<p>In the <var>i</var>-th operation, he chooses an integer <var>j</var> satisfying <var>1 \... | int solution() {
int n;
scanf("%d", &n);
int a[n];
int b[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
a[i]--;
if (a[i] > i) {
printf("-1\n");
return 0;
}
}
for (int i = 0; i < n; i++) {
for (int j = i; j > a[i]; j--) {
b[j] = b[j - 1];
}
b[a[i]] = a[i... | fn solution() {
use std::io::Read;
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).unwrap();
let mut iter = buf.split_whitespace();
let n: usize = iter.next().unwrap().parse::<usize>().unwrap();
let mut b: Vec<usize> = (&mut iter)
.take(n)
.map(|x| x.parse... | medium |
0425 | You are given two positive integers $$$n$$$ and $$$s$$$. Find the maximum possible median of an array of $$$n$$$ non-negative integers (not necessarily distinct), such that the sum of its elements is equal to $$$s$$$.A median of an array of integers of length $$$m$$$ is the number standing on the $$$\lceil {\frac{m}{2}... | int solution() {
int t = 0;
scanf("%d", &t);
int n[t];
int s[t];
int mid;
for (int i = 0; i < t; i++) {
scanf("%d%d", &n[i], &s[i]);
}
for (int i = 0; i < t; i++) {
mid = (s[i] / (n[i] / 2 + 1));
printf("%d\n", mid);
}
} | fn solution() {
let stdin = std::io::stdin();
let mut string = String::new();
stdin.read_line(&mut string).unwrap();
for _ in 0..string.trim().parse::<u128>().unwrap() {
string.clear();
stdin.read_line(&mut string).unwrap();
let (num, sum) = {
let mut s = string.trim(... | hard |
0426 | There are two sisters Alice and Betty. You have $$$n$$$ candies. You want to distribute these $$$n$$$ candies between two sisters in such a way that: Alice will get $$$a$$$ ($$$a > 0$$$) candies; Betty will get $$$b$$$ ($$$b > 0$$$) candies; each sister will get some integer number of candies; Alice will get ... | int solution() {
int n;
scanf("%d", &n);
int arr[n];
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
int temp = arr[i];
arr[i] = temp - (temp / 2) - 1;
}
for (int i = 0; i < n; i++) {
printf("%d\n", arr[i]);
}
return 0;
} | fn solution() {
let mut cases = String::new();
io::stdin().read_line(&mut cases).expect("no input");
let cases: u32 = cases.trim().parse().expect("nan");
for _ in 0..cases {
let mut line = String::new();
io::stdin().read_line(&mut line).expect("bad line");
let first: u32 = li... | medium |
0427 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a positive integer <var>X</var>.
Find the largest <em>perfect power</em> that is at most <var>X</var>.
Here, a perfect power is an integer that can be represented as <var>b^p</var>, where ... | int solution() {
double a = 1;
double b = 2;
int X = 0;
int MAX = 0;
scanf("%d", &X);
if (X != 1) {
for (a = 2; 2 * a < X; a++) {
for (b = 2; pow(a, b) <= X; b++) {
if (pow(a, b) > MAX) {
MAX = (int)pow(a, b);
}
}
}
} else {
MAX = X;
}
printf("%d", ... | fn solution() {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).ok();
let vec: Vec<&str> = buf.split_whitespace().collect();
let a: i32 = vec[0].parse().unwrap();
let x: [i32; 41] = [
1, 4, 8, 9, 16, 25, 27, 32, 36, 49, 64, 81, 100, 121, 125, 128, 144, 169, 196, 216, 225,
... | hard |
0428 | Erelong Leha was bored by calculating of the greatest common divisor of two factorials. Therefore he decided to solve some crosswords. It's well known that it is a very interesting occupation though it can be very difficult from time to time. In the course of solving one of the crosswords, Leha had to solve a simple ta... | int solution(void) {
int n = 0;
int m = 0;
int i = 0;
int j = 0;
int match = 0;
int max = 0;
int pos = 0;
char s[1001] = {
0,
};
char t[1001] = {
0,
};
scanf("%d %d", &n, &m);
scanf("%s", s);
scanf("%s", t);
for (i = 0; i <= m - n; i++) {
match = 0;
for (j = 0; j < n;... | fn solution() {
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
let mut iter = input.split_whitespace();
let n: usize = iter.next().unwrap().parse().unwrap();
let m: usize = iter.next().unwrap().parse().unwrap();
let mut ans: Option<usize> = None;
let mut s = ... | medium |
0429 | Casimir has a string $$$s$$$ which consists of capital Latin letters 'A', 'B', and 'C' only. Each turn he can choose to do one of the two following actions: he can either erase exactly one letter 'A' and exactly one letter 'B' from arbitrary places of the string (these letters don't have to be adjacent); or he can er... | int solution() {
int n = 0;
scanf("%d", &n);
while (n--) {
char c[60];
scanf("%s", c);
int sum1 = 0;
int sum2 = 0;
for (int i = 0; i < 60; i++) {
if (c[i] == 'A' || c[i] == 'C') {
sum1 += 1;
}
if (c[i] == 'B') {
sum2 += 1;
}
if (c[i] == '\0') {
... | fn solution() {
let mut out = BufWriter::new(io::stdout().lock());
io::stdin().lines().skip(1).flatten().for_each(|s| {
match s.chars().fold((0usize, 0usize), |(b, len), c| match c {
'B' => (b.wrapping_add(2), len.wrapping_add(1)),
_ => (b, len.wrapping_add(1)),
}) {
... | medium |
0430 | Armstrong number | int solution(int x) {
int n = 0;
int temp = x;
int sum = 0;
while (temp) {
n++;
temp /= 10;
}
temp = x;
while (temp) {
int r = temp % 10;
int p = 1;
for (int i = 0; i < n; i++) {
p *= r;
}
sum += p;
temp /= 10;
}
return (sum == x);
}
| fn solution(number: u32) -> bool {
let mut digits: Vec<u32> = Vec::new();
let mut num: u32 = number;
loop {
digits.push(num % 10);
num /= 10;
if num == 0 {
break;
}
}
let sum_nth_power_of_digits: u32 = digits
.iter()
.map(|digit| digit.po... | medium |
0431 | Luckily, Serval got onto the right bus, and he came to the kindergarten on time. After coming to kindergarten, he found the toy bricks very funny.He has a special interest to create difficult problems for others to solve. This time, with many $$$1 \times 1 \times 1$$$ toy bricks, he builds up a 3-dimensional object. We... | int solution() {
int n;
int m;
int h;
scanf("%d %d %d", &n, &m, &h);
int f_arr[m];
int l_arr[n];
int arr[n][m];
for (int i = 0; i < m; i++) {
scanf("%d", &f_arr[i]);
}
for (int i = 0; i < n; i++) {
scanf("%d", &l_arr[i]);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) ... | 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 m = get!(usize);
let _h = get!(usize);
let mut front = ve... | medium |
0432 | You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible.Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in mult... | int solution() {
int n;
int k;
int m;
scanf("%d%d%d", &n, &k, &m);
int a[n][2];
int b[m];
for (int i = 0; i < m; i++) {
b[i] = 0;
}
for (int i = 0; i < n; i++) {
scanf("%d", &a[i][0]);
a[i][1] = a[i][0] % m;
b[a[i][1]]++;
}
int j;
for (j = 0; j < m; j++) {
if (b[j] >= k) {
... | fn solution() {
let mut reader = io::BufReader::new(io::stdin());
let mut s = String::new();
reader.read_line(&mut s).unwrap();
let input: Vec<i32> = s
.trim_end()
.split_whitespace()
.map(|x| x.parse().unwrap())
.collect();
let _N = input[0];
let K = input[1];
... | medium |
0433 | <h1>すごろくと駒 (Sugoroku and Pieces)</h1>
<!-- 時間制限 : 2sec / メモリ制限 : 256MB -->
<h2> 問題文</h2>
<p>
JOI 君はすごろくを持っている.このすごろくは <var>2019</var> 個のマスが横一列に並んだ形をしている.これらのマスには,左端のスタートマスから右端のゴールマスへと順に <var>1</var> から <var>2019</var> までの番号がついている.
</p>
<p>
現在このすごろくの上には,<var>N</var> 個の駒が置かれている.これらの駒には,スタートに近い順に <var>1</var> から <var... | int solution() {
int n;
int m;
int x[201];
int a[201];
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &x[i]);
}
scanf("%d", &m);
for (int i = 1; i <= m; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
if (j == a[i]) {
... | fn solution() {
let mut buf = String::new();
let stdin = io::stdin();
let mut lock = stdin.lock();
lock.read_to_string(&mut buf);
let mut iter = buf.split_whitespace();
let n: usize = iter.next().unwrap().parse().unwrap();
let mut x: Vec<usize> = iter
.by_ref()
.take(n)
... | easy |
0434 | <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> balls. The <var>i</var>-th ball has an integer <var>A_i</var> written on it.<br/>
For each <var>k=1, 2, ..., N</var>, solve the following problem and print the answer. </p>
<ul>
<... | int solution() {
int n;
scanf("%d", &n);
long long a[n];
long long set[200001] = {0};
for (int i = 0; i < n; i++) {
scanf("%lld", &a[i]);
set[a[i]]++;
}
long long sum = 0;
for (int i = 1; i <= n; i++) {
sum += (set[i] * (set[i] - 1) / 2);
}
for (int i = 0; i < n; i++) {
printf("%lld\... | fn solution() {
let mut st = String::new();
stdin().read_line(&mut st).unwrap();
let mut st = String::new();
stdin().read_line(&mut st).unwrap();
let a: Vec<String> = st
.split_whitespace()
.map(|x| x.parse::<String>().unwrap())
.collect();
let mut dic: HashMap<&String, ... | hard |
0435 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Find the maximum possible sum of the digits (in base <var>10</var>) of a positive integer not greater than <var>N</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><... | int solution() {
char s[17];
bool is9 = true;
scanf("%s", s);
int len = strlen(s);
for (int i = 1; i < len; i++) {
if (s[i] != '9') {
is9 = false;
break;
}
}
if (is9) {
printf("%d\n", s[0] - '0' + (9 * len) - 9);
} else {
printf("%d\n", s[0] - '0' - 1 + (9 * len) - 9);
}
... | 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 m = n;
let mut o = 0;
let mut p = 0;
while m > 9 {
o += m % 10;
m /= 10;
... | medium |
0436 | The robot is placed in the top left corner of a grid, consisting of $$$n$$$ rows and $$$m$$$ columns, in a cell $$$(1, 1)$$$.In one step, it can move into a cell, adjacent by a side to the current one: $$$(x, y) \rightarrow (x, y + 1)$$$; $$$(x, y) \rightarrow (x + 1, y)$$$; $$$(x, y) \rightarrow (x, y - 1)$$$; $$... | int solution() {
int numSets = 0;
scanf("%d", &numSets);
for (int currentSet = 0; currentSet < numSets; ++currentSet) {
int width = 0;
int height = 0;
int laserX = 0;
int laserY = 0;
int laserRadius = 0;
scanf("%d %d %d %d %d", &width, &height, &laserX, &laserY, &laserRadius);
int to... | fn solution() {
let t: usize = {
let mut line: String = String::new();
std::io::stdin().read_line(&mut line).unwrap();
line.trim().parse().unwrap()
};
for _tests in 0..t {
let (n, m, sx, sy, d): (i64, i64, i64, i64, i64) = {
let mut line: String = String::new();
... | hard |
0437 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke loves puzzles.</p>
<p>Today, he is working on a puzzle using <code>S</code>- and <code>c</code>-shaped pieces.
In this puzzle, you can combine two <code>c</code>-shaped pieces into one <code>S</co... | int solution(void) {
unsigned long long N = 0;
unsigned long long M = 0;
unsigned long long sum = 0;
unsigned long long hen = 0;
scanf("%llu %llu", &N, &M);
if (M >= 4 && (N * 2 <= M - 4)) {
hen += (M - N * 2) / 4;
M -= hen * 2;
N += hen;
};
if (N <= M / 2) {
sum += N;
} else {
su... | fn solution() {
use std::io;
let mut input = String::new();
let _ = io::stdin().read_line(&mut input);
let input_nums = input
.split_whitespace()
.map(|x| x.parse::<usize>().unwrap())
.collect::<Vec<_>>();
let n = input_nums[0];
let m = input_nums[1];
if n * 2 >= m {
... | medium |
0438 | <h1>ポイントカード (Point Card)</h1>
<h2>問題</h2>
<p>
JOI 商店街ではポイントカードのサービスを行っている.各ポイントカードには 2N 個のマスがある.商品を購入すると,くじを引くことができ,結果によって「当たり」か「はずれ」の印がマスに押される.同じマスに印が 2 回押されることはない.2N 個のマスのうち N 個以上のマスに当たりの印が書かれたポイントカードは,景品と交換することができる.
また,ポイントカードの印は,1 マスにつき 1 円で書き換えてもらうことができる.
</p>
<p>
JOI 君は 2N 個のマスが全て埋まっているポイントカードを M 枚持っている.ポイントカー... | int solution(void) {
int a = 0;
int b = 0;
int c = 0;
int sum = 0;
int max = 0;
int n = 0;
int m = 0;
scanf("%d %d", &n, &m);
for (int i = 0; i < m; i++) {
scanf("%d %d", &a, &b);
c = n - a;
if (c > 0) {
sum += c;
}
if (c > max) {
max = c;
}
}
printf("%d\n", sum... | fn solution() {
let input = {
let mut buf = vec![];
stdin().read_to_end(&mut buf);
unsafe { String::from_utf8_unchecked(buf) }
};
let mut tuples = input.split('\n').map(|l| {
let mut iter = l.split(' ').map(|s| s.parse::<usize>().unwrap());
(iter.next().unwrap(), it... | easy |
0439 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> students in a school.</p>
<p>We will divide these students into some groups, and in each group they will discuss some themes.</p>
<p>You think that groups consisting of two or les... | int solution() {
int N = 0;
scanf("%d", &N);
printf("%d\n", N / 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 n: usize = itr.next().unwrap().parse().unwrap();
println!("{}", n / 3);
} | easy |
0440 | For years, the Day of city N was held in the most rainy day of summer. New mayor decided to break this tradition and select a not-so-rainy day for the celebration. The mayor knows the weather forecast for the $$$n$$$ days of summer. On the $$$i$$$-th day, $$$a_i$$$ millimeters of rain will fall. All values $$$a_i$$$ ar... | int solution() {
long long int n;
long long int x;
long long int y;
scanf("%lld %lld %lld", &n, &x, &y);
long long int arr[n + 1][3];
for (int i = 1; i <= n; i++) {
arr[i][0] = 0;
arr[i][2] = 1;
arr[i][1] = 1;
}
for (int i = 1; i <= n; i++) {
scanf("%lld", &arr[i][0]);
for (int j = 1... | fn solution() {
let (n, x, y) = {
let mut line = String::new();
stdin().read_line(&mut line).unwrap();
let mut iter = line.split_whitespace();
(
iter.next().unwrap().parse::<isize>().unwrap(),
iter.next().unwrap().parse::<isize>().unwrap(),
iter.ne... | medium |
0441 | You have given an array $$$a$$$ of length $$$n$$$ and an integer $$$x$$$ to a brand new robot. What the robot does is the following: it iterates over the elements of the array, let the current element be $$$q$$$. If $$$q$$$ is divisible by $$$x$$$, the robot adds $$$x$$$ copies of the integer $$$\frac{q}{x}$$$ to the e... | int solution() {
int t;
int n;
int k;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
long long int flag = 0;
long long int sum = 0;
scanf("%d%d", &n, &k);
long long int a[n];
long long int c[100000] = {0};
long long int b[n];
for (int j = 0; j < n; j++) {
scanf("%lld", &a[j])... | fn solution() {
let k = std::io::stdin()
.lock()
.lines()
.next()
.unwrap()
.unwrap()
.parse::<i128>()
.unwrap();
'rest: for _ls in 0..k {
let mut l = String::new();
std::io::stdin().read_line(&mut l).unwrap();
let l = l
... | medium |
0442 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given three strings <var>A</var>, <var>B</var> and <var>C</var>. Check whether they form a <em>word chain</em>.</p>
<p>More formally, determine whether both of the following are true:</p>
<ul>
<... | int solution() {
char A[10];
char B[10];
char C[10];
int con = 0;
scanf("%s %s %s", A, B, C);
for (int i = 1; i <= 10; i++) {
if (A[i] == '\0' && A[i - 1] == B[0]) {
con++;
}
if (B[i] == '\0' && B[i - 1] == C[0]) {
con++;
}
}
if (con == 2) {
printf("YES");
} else {
... | fn solution() {
let mut buf = String::new();
io::stdin().read_line(&mut buf).expect("");
let iter = buf.split_whitespace();
let mut v: Vec<Vec<char>> = Vec::new();
for i in iter {
v.push(i.chars().collect::<Vec<char>>());
}
let a = v[0].clone();
let b = v[1].clone();
let c = ... | medium |
0443 | You are given an array $$$a_1, a_2, \ldots, a_n$$$ of positive integers. A good pair is a pair of indices $$$(i, j)$$$ with $$$1 \leq i, j \leq n$$$ such that, for all $$$1 \leq k \leq n$$$, the following equality holds:$$$$$$ |a_i - a_k| + |a_k - a_j| = |a_i - a_j|, $$$$$$ where $$$|x|$$$ denotes the absolute value of... | int solution() {
int t;
scanf("%d", &t);
if (t > 1000 || t < 0) {
return 0;
}
int n[t];
int **a = malloc(sizeof(int *) * t);
for (int i = 0; i < t; i++) {
scanf("%d", &n[i]);
if (n[i] > 100000 || n[i] < 1) {
return 0;
}
a[i] = malloc(sizeof(int) * n[i]);
for (int j = 0; j < 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 a: Vec<u64> = lines
.next()
.unwrap(... | hard |
0444 | Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.Recently, she was presented with an array $$$a$$$ of the size of $$$10^9$$$ elements that is filled as follows: $$$a_1 = -1$$$ $$$a_2 = 2$$$ $$$a_3 = -3$$$ $$$a_4 = 4$$$ $$$a_5 = -5$$$ An... | int solution() {
long long int n = 0;
long long int l = 0;
long long int r = 0;
long long int ans = 0;
scanf("%lld", &n);
while (n--) {
scanf("%lld %lld", &l, &r);
if (l == r) {
if (l % 2 == 1) {
printf("%lld\n", -l);
} else if (l % 2 == 0) {
printf("%lld\n", r);
}
... | fn solution() -> std::io::Result<()> {
let mut contents = String::new();
std::io::stdin().read_line(&mut contents)?;
let contents: Vec<&str> = contents.split("\r\n").collect();
let contents: &str = contents[0];
let q: u32 = contents.parse().unwrap();
for _i in 0..q {
let mut contents = S... | medium |
0445 | For some time the program of rounding numbers that had been developed by the Codeforces participants during one of the previous rounds, helped the citizens of Far Far Away to convert numbers into a more easily readable format. However, as time went by, the economy of the Far Far Away developed and the scale of operatio... | int solution() {
char str[101];
char minus = 0;
scanf("%s", str);
if (str[0] == '-') {
minus = 1;
}
char integerStr[101];
int integerLen = 0;
for (int i = minus; str[i] != '.' && str[i]; ++i) {
integerStr[integerLen++] = str[i];
}
int tail = 2;
char fractionalStr[tail];
int fractionalLen... | fn solution() {
let stdin = io::stdin();
let mut s = String::new();
stdin.read_line(&mut s).unwrap();
s = s.trim().to_string();
let minus = s.contains('-');
let mut r = String::new();
if minus {
r.push(')');
s = s.get(1..).unwrap().to_string();
}
let mut frac = "0... | easy |
0446 | Polycarp is reading a book consisting of $$$n$$$ pages numbered from $$$1$$$ to $$$n$$$. Every time he finishes the page with the number divisible by $$$m$$$, he writes down the last digit of this page number. For example, if $$$n=15$$$ and $$$m=5$$$, pages divisible by $$$m$$$ are $$$5, 10, 15$$$. Their last digits ar... | int solution(void) {
int q;
int mids = 0;
scanf("%d", &q);
long long int a[q][3];
long long int c;
for (int i = 0; i < q; i++) {
scanf("%lld %lld", &a[i][0], &a[i][1]);
}
for (int i = 0; i < q; i++) {
mids = 0;
a[i][2] = 0;
c = a[i][0] / a[i][1];
for (int j = 1; j <= 10; j++) {
... | fn solution() {
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("failed to read input");
let q = input.trim().parse::<u16>().unwrap();
for _ in 0..q {
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expe... | medium |
0447 | A map of some object is a rectangular field consisting of n rows and n columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly k islands appear on the map. We will call a set of sand cells to be island if it is possible to get from each of them to each ... | int solution() {
int n;
int k;
int c = 0;
int i = 0;
int j = 0;
scanf("%d %d", &n, &k);
int a[n][n];
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
a[i][j] = 0;
}
}
i = 0, j = 0;
while (c != k && i < n) {
a[i][j] = 1;
j += 2;
if (j >= n && a[i][0] == 0) {
j = 0... | fn solution() {
let inputstatus = 1;
let mut buf = String::new();
let filename = "inputrust.txt";
if inputstatus == 0 {
let mut f = File::open(filename).expect("file not found");
f.read_to_string(&mut buf)
.expect("something went wrong reading the file");
} else {
... | medium |
0448 | You are given a function $$$f$$$ written in some basic language. The function accepts an integer value, which is immediately written into some variable $$$x$$$. $$$x$$$ is an integer variable and can be assigned values from $$$0$$$ to $$$2^{32}-1$$$. The function contains three types of commands: for $$$n$$$ — for loo... | int solution() {
long long int32max = 4294967296 - 1;
int ofc = 0;
int i;
int n;
scanf("%d", &n);
long long arr[n];
int index = 0;
long long mult = 1;
int fnum[n];
int fnumindex = 0;
for (i = 0; i < n; i++) {
arr[i] = 0;
}
for (i = 0; i < n; i++) {
char inp[10];
scanf(" %s", inp);
... | fn solution() {
let mut line = String::new();
io::stdin().read_line(&mut line).unwrap();
let t: i64 = line.trim().parse::<i64>().expect("error");
let mut x = 0i64;
let mut state: Vec<i64> = Vec::new();
let num_iter = 1i64;
state.push(num_iter);
for _ in 0..t {
line.clear();
... | hard |
0449 | Valera is a collector. Once he wanted to expand his collection with exactly one antique item.Valera knows n sellers of antiques, the i-th of them auctioned ki items. Currently the auction price of the j-th object of the i-th seller is sij. Valera gets on well with each of the n sellers. He is perfectly sure that if he ... | int solution(void) {
int n;
int net;
scanf("%d %d", &n, &net);
int a[n];
int d[n];
int count = 0;
int **ptr = (int **)malloc(n * sizeof(int *));
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
ptr[i] = (int *)malloc(a[i] * sizeof(int));
for (int j = 0; j < a[i]; j++) {
scanf("%d", &p... | fn solution() {
let mut s = String::new();
io::stdin().read_line(&mut s).unwrap();
let a: Vec<i32> = s.split_whitespace().map(|x| x.parse().unwrap()).collect();
let n = a[0];
let v = a[1];
let mut sellers: Vec<Vec<i32>> = vec![];
for _ in 0..n {
let mut s = String::new();
i... | hard |
0450 | Monocarp is planning to host a martial arts tournament. There will be three divisions based on weight: lightweight, middleweight and heavyweight. The winner of each division will be determined by a single elimination system.In particular, that implies that the number of participants in each division should be a power o... | int solution() {
int n = 0;
scanf("%d", &n);
for (int n1 = 0; n1 < n; n1++) {
int m = 0;
int *a = malloc(1000000);
int *b = malloc(1000000);
scanf("\n%d", &m);
for (int m1 = 0; m1 <= m; m1++) {
a[m1] = 0;
}
for (int m1 = 0; m1 < m; m1++) {
int k = 0;
scanf("%d", &k);... | fn solution() {
let stdin = stdin();
let stdout = stdout();
let stdin = stdin.lock();
let stdout = stdout.lock();
let mut stdout = BufWriter::new(stdout);
let mut stdin = stdin.lines();
let mut read = || stdin.next().unwrap().unwrap();
let nn: usize = read().parse().unwrap_or_default(... | hard |
0451 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2,... | int solution() {
int n;
int c1 = 0;
int c2 = 0;
int c3 = 0;
int mino = 0;
scanf("%d", &n);
int a[n];
int one1[n];
int duo2[n];
int tre3[n];
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i] == 1) {
one1[c1++] = i;
} else if (a[i] == 2) {
duo2[c2++] = i;
} else... | 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 students = buf
.split_whitespace()
.map(|str| str.trim().parse::<u32>().unwrap());
let mut p = Vec::with_capacity(500... | hard |
0452 | <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> dice arranged in a line from left to right. The <var>i</var>-th die from the left shows <var>p_i</var> numbers from <var>1</var> to <var>p_i</var> with equal probability when thrown... | int solution() {
int N;
int K;
scanf("%d%d", &N, &K);
double p[N];
double sum_E = 0;
double ans = 0;
for (int i = 0; i < N; i++) {
scanf("%lf", &p[i]);
p[i] = ((p[i] * (p[i] + 1)) / 2) / p[i];
}
for (int i = 0; i < K; i++) {
sum_E += p[i];
}
if (N == K) {
printf("%.12f", sum_E);
... | fn solution() {
let mut buf = String::new();
let (n, k): (usize, usize) = {
std::io::stdin().read_line(&mut buf).unwrap();
let words: Vec<usize> = buf.split_whitespace().map(|w| w.parse().unwrap()).collect();
(words[0], words[1])
};
let ps: Vec<f64> = {
buf.clear();
... | hard |
0453 | Patrick likes to play baseball, but sometimes he will spend so many hours hitting home runs that his mind starts to get foggy! Patrick is sure that his scores across $$$n$$$ sessions follow the identity permutation (ie. in the first game he scores $$$1$$$ point, in the second game he scores $$$2$$$ points and so on). H... | int solution() {
int t;
int n;
int i;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
int a[n + 1];
int c = 0;
int r = 0;
int f = 0;
int p = 0;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (i > 0) {
if (a[i] > a[i - 1] && a[i] == i + 1 && p > 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();
let mut out = Vec::new();
for _ in 0..t {
let n: usize = itr.next().unwrap().parse().unwrap();
... | medium |
0454 | You're given an array $$$a$$$ of $$$n$$$ integers, such that $$$a_1 + a_2 + \cdots + a_n = 0$$$.In one operation, you can choose two different indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$), decrement $$$a_i$$$ by one and increment $$$a_j$$$ by one. If $$$i < j$$$ this operation is free, otherwise it costs one... | int solution(void) {
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]);
}
long long cur = 0;
for (int i = 0; i < n; i++) {
cur = cur + a[i];
if (cur < 0) {
cur = 0;
}
}
printf... | fn solution() {
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
let t: u32 = input.trim().parse().unwrap();
input.clear();
let mut mx: i64;
let mut count: i64;
for _ in 0..t {
let mut q;
let mut input = String::new();
io::stdin().read_line(... | hard |
0455 | Let $$$a$$$ and $$$b$$$ be two arrays of lengths $$$n$$$ and $$$m$$$, respectively, with no elements in common. We can define a new array $$$\mathrm{merge}(a,b)$$$ of length $$$n+m$$$ recursively as follows: If one of the arrays is empty, the result is the other array. That is, $$$\mathrm{merge}(\emptyset,b)=b$$$ and ... | int solution() {
int tests;
scanf("%d", &tests);
for (int t = 0; t < tests; ++t) {
int n;
scanf("%d", &n);
int p[2 * n];
int idx[(2 * n) + 1];
bool seen[(2 * n) + 1];
bool sol[(2 * n) + 1];
for (int i = 0; i < 2 * n; ++i) {
scanf("%d", p + i);
idx[p[i]] = i;
seen[p[i]... | fn solution() {
let stdout = io::stdout();
let mut output = BufWriter::new(stdout.lock());
let mut stdin = io::stdin();
let mut input_str = String::new();
stdin.read_to_string(&mut input_str).unwrap();
let mut input_iter = input_str.split_whitespace();
let test_cases: usize = read!();
... | medium |
0456 | You have a sequence of $$$n$$$ colored blocks. The color of the $$$i$$$-th block is $$$c_i$$$, an integer between $$$1$$$ and $$$n$$$.You will place the blocks down in sequence on an infinite coordinate grid in the following way. Initially, you place block $$$1$$$ at $$$(0, 0)$$$. For $$$2 \le i \le n$$$, if the $$$... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int d;
scanf("%d", &d);
int arr[d];
for (int i = 0; i < d; i++) {
scanf("%d", &arr[i]);
}
int finalans[d + 1];
for (int i = 0; i < d + 1; i++) {
finalans[i] = 0;
}
int index[d + 1];
for (int i = 0; i < d + 1... | fn solution() {
let lines = std::io::stdin().lines().skip(2).step_by(2);
for line in lines {
let line = line.unwrap();
let c = line
.split_whitespace()
.map(|x| x.parse::<usize>().unwrap())
.collect::<Vec<_>>();
let n = c.len();
let mut res ... | medium |
0457 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Given is a positive integer <var>N</var>. Consider repeatedly applying the operation below on <var>N</var>:</p>
<ul>
<li>First, choose a positive integer <var>z</var> satisfying all of the conditions b... | int solution() {
long long int n = 0;
int counter = 0;
int tmp_counter = 0;
scanf("%lld", &n);
for (long long int i = 2; n != 1;) {
tmp_counter = 0;
if (i > pow(n, 0.5)) {
counter += 1;
break;
}
while ((n % i) == 0) {
n = n / i;
tmp_counter++;
}
for (int i ... | fn solution() {
let mut is = String::new();
stdin().read_line(&mut is).ok();
let mut n = is.trim().parse::<usize>().unwrap();
let mut map = HashMap::new();
let mut i = 2;
while i * i <= n {
while n % i == 0 {
*map.entry(i).or_insert(0) += 1;
n /= i;
}
... | medium |
0458 | There is a toy building consisting of $$$n$$$ towers. Each tower consists of several cubes standing on each other. The $$$i$$$-th tower consists of $$$h_i$$$ cubes, so it has height $$$h_i$$$.Let's define operation slice on some height $$$H$$$ as following: for each tower $$$i$$$, if its height is greater than $$$H$$$,... | int solution(void) {
long long int n;
long long int k;
long long int min = 200001;
long long int max = 0;
long long int aux;
long long int aux2;
long long int total = 0;
long long int *v;
scanf("%lld %lld", &n, &k);
v = malloc(sizeof(long long int) * 200001);
for (long long int j = 0; j <= 200... | 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 k = get!();
let mut hs = vec![];
for _ in 0..n {
let h... | medium |
0459 | <H1>X Cubic</H1>
<p>
Write a program which calculates the cube of a given integer <var>x</var>.
</p>
<H2>Input</H2>
<p>
An integer <var>x</var> is given in a line.
</p>
<H2>Output</H2>
<p>
Print the cube of <var>x</var> in a line.
</p>
<h2>Constraints</h2>
<ul>
<li> 1 ≤ <var>x</var> ≤ 100</li>
</ul>
<H... | int solution() {
int x = 0;
scanf("%d", &x);
if (x > 0 && x < 101) {
x = x * x * x;
printf("%d\n", x);
}
return 0;
} | fn solution() {
let stdin = io::stdin();
let mut buf = String::new();
let _ = stdin.read_line(&mut buf);
let x: i64 = i64::from_str(buf.trim()).unwrap();
println!("{}", x.pow(3));
} | medium |
0460 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have two permutations <var>P</var> and <var>Q</var> of size <var>N</var> (that is, <var>P</var> and <var>Q</var> are both rearrangements of <var>(1,~2,~...,~N)</var>).</p>
<p>There are <var>N!</var> ... | int solution(void) {
int n;
int p[8 + 3];
int q[8 + 3];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &p[i]);
}
for (int i = 0; i < n; i++) {
scanf("%d", &q[i]);
}
int num_p = 0;
int num_q = 0;
for (int i = 0; i < n; i++) {
int temp = 0;
for (int j = i + 1; j < n; j+... | 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 p: Vec<_> = s
.by_ref()
.take(n)
.map(|a| a.parse::<i32>().unwrap() - 1... | medium |
0461 | Vova is playing a computer game. There are in total $$$n$$$ turns in the game and Vova really wants to play all of them. The initial charge of his laptop battery (i.e. the charge before the start of the game) is $$$k$$$.During each turn Vova can choose what to do: If the current charge of his laptop battery is strict... | int solution() {
long long int t;
long long int k;
long long int n;
long long int a;
long long int b;
long long int m;
long long int i;
long long int x;
long long int low;
long long int high;
long long int mid;
long long int l;
scanf("%lld", &t);
for (m = 1; m <= t; m++) {
scanf("%lld %l... | fn solution() -> io::Result<()> {
let stdin = io::stdin();
let mut input = String::new();
stdin.read_line(&mut input)?;
let q: u32 = input.trim().parse().expect("read error");
for _ in 1..q + 1 {
let mut input = String::new();
stdin.read_line(&mut input)?;
let mut iter = in... | easy |
0462 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Joisino the magical girl has decided to turn every single digit that exists on this world into <var>1</var>.</p>
<p>Rewriting a digit <var>i</var> with <var>j</var> <var>(0≤i,j≤9)</var> costs <var>c_{i,... | int solution() {
int h;
int w;
scanf("%d%d", &h, &w);
int c[10][10];
int a[h][w];
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
scanf("%d", &c[i][j]);
}
}
long long ans = 0;
for (int k = 0; k < 10; k++) {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; ... | fn solution() {
let mut s: String = String::new();
std::io::stdin().read_to_string(&mut s).ok();
let mut itr = s.split_whitespace();
let h: usize = itr.next().unwrap().parse().unwrap();
let w: usize = itr.next().unwrap().parse().unwrap();
let mut dp: Vec<Vec<u64>> = (0..10)
.map(|_| {
... | easy |
0463 | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | int solution(void) {
int n = 0;
int final = 0;
int PVT_surity[3];
scanf("%d", &n);
while (n > 0) {
for (int i = 0; i < 3; i++) {
scanf("%d", &PVT_surity[i]);
}
if (PVT_surity[0] + PVT_surity[1] + PVT_surity[2] >= 2) {
final++;
}
n--;
}
printf("%d", final);
return 0;
} | fn solution() -> Result<(), Box<dyn std::error::Error>> {
let mut input = String::new();
io::stdin().read_line(&mut input)?;
let amount = input.trim().to_string().parse::<usize>()?;
let mut result = 0;
for _ in 0..amount {
let mut vecs = String::new();
io::stdin().read_line(&mut vec... | medium |
0464 | Vasya, like many others, likes to participate in a variety of sweepstakes and lotteries. Now he collects wrappings from a famous chocolate bar "Jupiter". According to the sweepstake rules, each wrapping has an integer written on it — the number of points that the participant adds to his score as he buys the bar. After ... | int solution(void) {
long long prizes[5] = {0};
long long pi[50];
int n;
scanf("%i", &n);
int i;
int j;
for (i = 0; i < n; i++) {
scanf("%lld", &pi[i]);
}
int costs[5];
for (i = 0; i < 5; i++) {
scanf("%i", &costs[i]);
}
long long ps = 0;
for (i = 0; i < n; i++) {
ps += pi[i];
... | fn solution() {
let stdin = io::stdin();
let mut lines = stdin.lock().lines();
let _n = lines.next().unwrap().unwrap().parse::<usize>().unwrap();
let winnings: Vec<_> = lines
.next()
.unwrap()
.unwrap()
.split(" ")
.map(|s| s.parse::<u64>().unwrap())
.coll... | medium |
0465 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given nonnegative integers <var>a</var> and <var>b</var> (<var>a ≤ b</var>), and a positive integer <var>x</var>.
Among the integers between <var>a</var> and <var>b</var>, inclusive, how many ar... | int solution() {
long long a;
long long b;
long long x;
long long ans1;
long long ans2;
scanf("%lld%lld%lld", &a, &b, &x);
ans1 = (a - 1) / x;
ans2 = b / x;
if (b < x) {
if (a == 0) {
puts("1");
} else {
puts("0");
}
return 0;
}
if (a == 0 && x != 1) {
ans2++;
}
... | fn solution() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
let v: Vec<usize> = s.split_whitespace().map(|x| x.parse().unwrap()).collect();
println!(
"{}",
v[1] / v[2] - v[0] / v[2] + (if v[0].is_multiple_of(v[2]) { 1 } else { 0 })
);
} | hard |
0466 | You are given a string $$$s$$$. You have to determine whether it is possible to build the string $$$s$$$ out of strings aa, aaa, bb and/or bbb by concatenating them. You can use the strings aa, aaa, bb and/or bbb any number of times and in any order.For example: aaaabbb can be built as aa $$$+$$$ aa $$$+$$$ bbb; bbaa... | int solution() {
int t;
scanf("%d", &t);
char s[51];
while (t--) {
scanf("%s", s);
int ans = 1;
int n = strlen(s);
if (n == 1) {
printf("No\n");
continue;
}
if (s[0] != s[1]) {
ans = 0;
}
for (int i = 1; i < n - 1 && ans == 1; i++) {
if (s[i] != s[i - 1] &... | fn solution() {
let mut s = String::new();
io::stdin().read_line(&mut s).expect("Failed to read t");
let mut t: usize = s.trim().parse().expect("t is not a number");
while t != 0 {
let mut s = String::new();
io::stdin().read_line(&mut s).expect("Failed to read s");
let s = s.trim... | easy |
0467 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has decided to construct a string that starts with <code>A</code> and ends with <code>Z</code>, by taking out a substring of a string <var>s</var> (that is, a consecutive part of <var>s</var>).</p... | int solution(void) {
char s[300000];
int strat_a = 0;
int strat_z = 0;
bool flag = true;
fgets(s, sizeof(s), stdin);
for (int i = 0; s[i] != '\n'; i++) {
if (s[i] == 'A' && flag == true) {
strat_a = i;
flag = false;
}
if (s[i] == 'Z' && flag == false) {
strat_z = i;
}
}
... | fn solution() {
let mut s = String::new();
io::stdin().read_line(&mut s).ok();
let mut f = false;
let mut now = 0;
let mut res = 0;
for c in s.trim().chars() {
if !f && c == 'A' {
f = true;
}
if f {
now += 1;
}
if f && c == 'Z' {... | easy |
0468 | Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n... | int solution() {
char s[100000];
int sum[100000];
int m;
int l;
int r;
sum[0] = 0;
for (int i = 0;; i++) {
scanf("%c", &s[i]);
if (s[i] != '.' && s[i] != '#') {
break;
}
if (i > 0) {
if (s[i - 1] == s[i]) {
sum[i] = sum[i - 1] + 1;
} else {
sum[i] = sum... | fn solution() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
let s: Vec<char> = s.chars().collect();
let mut t = String::new();
std::io::stdin().read_line(&mut t).unwrap();
let n: usize = t.trim().parse().unwrap();
let mut count = vec![0];
let mut c = s[0];
... | hard |
0469 | You are given two integers $$$a$$$ and $$$b$$$. Print $$$a+b$$$. | int solution() {
int n;
scanf("%d", &n);
int numbers[n][2];
for (int i = 0; i < n; i++) {
scanf("%d %d", &numbers[i][0], &numbers[i][1]);
}
for (int i = 0; i < n; i++) {
printf("%d\n", numbers[i][0] + numbers[i][1]);
}
return 0;
} | fn solution() {
let mut cases = String::new();
io::stdin()
.read_line(&mut cases)
.expect("Unable to read number of cases");
let cases: u32 = cases
.trim()
.parse()
.expect("Unable to parse number of cases");
for _ in 0..cases {
let mut val = String::new(... | hard |
0470 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Takahashi is a teacher responsible for a class of <var>N</var> students.</p>
<p>The students are given distinct student numbers from <var>1</var> to <var>N</var>.</p>
<p>Today, all the students entered... | int solution() {
int N;
int i;
scanf("%d", &N);
int(*A) = (int(*))malloc(100010 * sizeof(int));
int(*B) = (int(*))malloc(100010 * sizeof(int));
for (i = 1; i <= N; i++) {
scanf("%d", &A[i]);
B[A[i]] = i;
}
for (i = 1; i <= N; i++) {
printf("%d ", B[i]);
}
free(A);
free(B);
return 0;... | fn solution() {
let _n: i64 = {
let mut line = String::new();
std::io::stdin().read_line(&mut line).unwrap();
line.trim().parse().unwrap()
};
let mut a: Vec<(i64, i64)> = {
let mut line = String::new();
std::io::stdin().read_line(&mut line).unwrap();
let ret =... | hard |
0471 | One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of w... | int solution() {
long n;
long t;
int m = 0;
int c = 0;
scanf("%ld", &n);
int a[n];
int b[n];
long long h;
long long s = 0;
for (long i = 0; i < n; i++) {
scanf("%d %d", &a[i], &b[i]);
s = s + a[i];
if (b[i] > m) {
m = b[i];
t = i;
}
}
for (long i = 0; i < n; i++) {
... | fn solution() {
let mut n = String::new();
io::stdin().read_line(&mut n).expect("Failed to read line!");
let n = n.trim().parse::<u32>().expect("Type a number, please!");
let mut w: [u8; 200000] = [0; 200000];
let mut h: [u16; 2] = [0; 2];
let mut full_w: u32 = 0;
let mut biggest_heigh... | medium |
0472 | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of ... | int solution() {
int calories[4];
char str[100001];
int i = 0;
int count = 0;
scanf("%d %d %d %d", &calories[0], &calories[1], &calories[2], &calories[3]);
scanf("%s", str);
if (calories[0] == '0' && calories[1] == '0' && calories[2] == '0' &&
calories[3] == '0') {
printf("0");
return 0;
}... | fn solution() {
let mut input: String = String::new();
std::io::stdin()
.read_line(&mut input)
.expect("INPUT::read line failed");
let mut input = input.trim().split(' ');
let one: i32 = input.next().unwrap().parse::<i32>().unwrap();
let two: i32 = input.next().unwrap().parse::<i32>... | medium |
0473 | The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.One needs exactly di years to rise from rank i to rank i + 1. Reaching a certain rank i having not reached all the previous i - 1 ranks is impossible.Vasya has ju... | int solution() {
int h_rank = 0;
int i = 0;
int now = 0;
int after = 0;
int left = 0;
scanf("%d", &h_rank);
int time_arr[h_rank - 1];
for (i = 0; i < h_rank - 1; i++) {
scanf("%d", &time_arr[i]);
}
scanf("%d %d", &now, &after);
for (i = now - 1; i < after - 1; i++) {
left += time_arr[i... | fn solution() {
let mut buf = String::new();
let mut n: usize = 0;
let reader = io::stdin();
reader.read_line(&mut buf);
n = buf.trim().parse().expect(" ");
let mut v = vec![0; n - 1];
let mut buf2 = String::new();
reader.read_line(&mut buf2);
let it = buf2.trim().split(" ");
le... | hard |
0474 | You are given a permutation $$$a$$$ of size $$$n$$$ and you should perform $$$n$$$ operations on it. In the $$$i$$$-th operation, you can choose a non-empty suffix of $$$a$$$ and increase all of its elements by $$$i$$$. How can we perform the operations to minimize the number of inversions in the final array?Note that ... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int a;
int n;
scanf("%d", &n);
int perm[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a);
perm[n - a] = i + 1;
}
for (int i = 0; i < n; i++) {
printf("%d ", perm[i]);
}
printf("\n");
}
} | fn solution() {
let stdin = std::io::stdin();
let stdin_lock = stdin.lock();
let mut line_iter = stdin_lock.lines();
let t = line_iter
.next()
.unwrap()
.unwrap()
.as_str()
.parse::<usize>()
.unwrap();
for _ in 0..t {
let n = line_iter.next().... | easy |
0475 | Petya organized a strange birthday party. He invited $$$n$$$ friends and assigned an integer $$$k_i$$$ to the $$$i$$$-th of them. Now Petya would like to give a present to each of them. In the nearby shop there are $$$m$$$ unique presents available, the $$$j$$$-th present costs $$$c_j$$$ dollars ($$$1 \le c_1 \le c_2 \... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
int m;
long long sum = 0;
scanf("%d%d", &n, &m);
long long k[n];
long long c[m + 1];
long long f[m + 1];
for (long long i = 0; i <= m; i++) {
f[i] = 0;
}
for (long long i = 0; i < n; i++) {
scanf("%ll... | fn solution() {
use std::io::{self, Write};
let (stdin, stdout) = (io::stdin(), io::stdout());
let mut sc = cf_scanner::Scanner::new(stdin.lock());
let mut out = io::BufWriter::new(stdout.lock());
let t: usize = sc.next();
for _ in 0..t {
let n: usize = sc.next();
let m: usize ... | hard |
0476 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have weather records at AtCoder Town for some consecutive three days. A string of length <var>3</var>, <var>S</var>, represents the records - if the <var>i</var>-th character is <code>S</code>, it me... | int solution() {
char s[3];
scanf("%s", s);
if (s[0] == 'S' && s[1] == 'S' && s[2] == 'S') {
printf("0");
}
if (s[0] == 'S' && s[1] == 'S' && s[2] == 'R') {
printf("1");
}
if (s[0] == 'S' && s[1] == 'R' && s[2] == 'S') {
printf("1");
}
if (s[0] == 'R' && s[1] == 'S' && s[2] == 'S') {
... | fn solution() {
let mut buf = String::new();
io::stdin().read_line(&mut buf).expect("");
let s = buf.trim();
if s == "RRR" {
println!("3");
} else if s == "RRS" || s == "SRR" {
println!("2");
} else if s == "RSS" || s == "SRS" || s == "SSR" || s == "RSR" {
println!("1");
... | easy |
0477 | Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than... | int solution() {
int k;
scanf("%d", &k);
while (k--) {
int n;
int m;
scanf("%d %d", &n, &m);
int array[n];
int curr = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &array[i]);
}
for (long long int i = n - 1; i >= 0; i--) {
if (array[i] <= curr) {
array[i] = 1;
... | fn solution() {
let stdout = std::io::stdout();
let mut writer = std::io::BufWriter::new(stdout.lock());
input! {
name = reader,
tests: usize
}
for _ in 0..tests {
input! {
use reader,
n: usize,
q: u32,
a: [u32; n]
... | hard |
0478 | Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it.Gildong tries so hard to satisfy the customers that he even memorized all customers' preferred temperature ranges! Looking through the reservation list, he wants to satisfy all custome... | int solution() {
int n;
scanf("%d", &n);
while (n--) {
int a;
int t0;
scanf("%d %d", &a, &t0);
int s = 0;
int min = t0;
int max = t0;
int k = 0;
while (a--) {
int s1;
int mi;
int ma;
scanf("%d %d %d", &s1, &mi, &ma);
min = min - (s1 - s);
max = m... | 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 = buffer
.split_whitespace()
.map(|x| x.parse::<i64>().expect("convert to number"))
.collect::... | medium |
0479 | Kawashiro Nitori is a girl who loves competitive programming.One day she found a string and an integer. As an advanced problem setter, she quickly thought of a problem.Given a string $$$s$$$ and a parameter $$$k$$$, you need to check if there exist $$$k+1$$$ non-empty strings $$$a_1,a_2...,a_{k+1}$$$, such that $$$$$$s... | int solution() {
int t;
scanf("%d", &t);
for (int i = 0; i < t; ++i) {
int N;
int K;
scanf("%d %d", &N, &K);
char string[200];
scanf("%s", string);
int k = 0;
int j = N - 1;
int l = -1;
while ((N % 2 == 0 && k < N / 2 - 1) || (N % 2 == 1 && k < N / 2)) {
if (string[... | fn solution() {
use std::io::Read;
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).unwrap();
let mut itr = buf.split_whitespace();
use std::io::Write;
let out = std::io::stdout();
let mut out = std::io::BufWriter::new(out.lock());
let t: usize = scan!(usize);... | medium |
0480 | You are given an array $$$a_1, a_2, \dots , a_n$$$ consisting of integers from $$$0$$$ to $$$9$$$. A subarray $$$a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$$$ is good if the sum of elements of this subarray is equal to the length of this subarray ($$$\sum\limits_{i=l}^{r} a_i = r - l + 1$$$).For example, if $$$a = [1,... | int solution() {
int tests;
scanf("%d", &tests);
for (int i = 0; i < tests; ++i) {
int32_t n;
scanf("%" SCNd32, &n);
char *s = (char *)malloc(n + 1);
int32_t *sum_cnt = (int32_t *)calloc(n * 9, sizeof(int32_t));
int32_t *negative_sum_cnt = (int32_t *)calloc(n * 9, sizeof(int32_t));
sum_cnt... | 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 |
0481 | Johnny has recently found an ancient, broken computer. The machine has only one register, which allows one to put in there one variable. Then in one operation, you can shift its bits left or right by at most three positions. The right shift is forbidden if it cuts off some ones. So, in fact, in one operation, you can m... | int solution(void) {
int T;
scanf("%d", &T);
while (T--) {
unsigned long long int a;
unsigned long long int b;
scanf("%llu %llu", &a, &b);
int count = 0;
while (8 * a <= b) {
a *= 8, count++;
}
while (4 * a <= b) {
a *= 4, count++;
}
while (2 * a <= b) {
a *= ... | 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();
let mut out = Vec::new();
for _ in 0..t {
let mut a: u64 = itr.next().unwrap().parse().unwrap();
... | medium |
0482 | Berland Music is a music streaming service built specifically to support Berland local artist. Its developers are currently working on a song recommendation module.So imagine Monocarp got recommended $$$n$$$ songs, numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th song had its predicted rating equal to $$$p_i$$$, where ... | int solution(void) {
int t = 0;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int a[n];
int b[n];
int p;
int cnt = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &p);
p--;
a[p] = i;
}
char s[n + 1];
scanf("%s", s);
for (int i = 0; i < n; i+... | fn solution() {
let (i, o) = (io::stdin(), io::stdout());
let mut o = bw::new(o.lock());
let mut i = i.lock().lines().skip(1);
while let Some(_) = i.next() {
let p = i
.next()
.unwrap()
.unwrap()
.split(' ')
.map(|w| w.parse::<u32>().un... | hard |
0483 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Today is August <var>24</var>, one of the five Product Days in a year.</p>
<p>A date <var>m</var>-<var>d</var> (<var>m</var> is the month, <var>d</var> is the date) is called a Product Day when <var>d</... | int solution(void) {
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
int f = 0;
int i = 0;
int j = 0;
scanf("%d", &a);
scanf("%d", &b);
for (i = 1; i <= a; i++) {
for (j = 1; j <= b; j++) {
d = j % 10;
e = j / 10;
f = d * e;
if (d >= 2 && e >= 2 && f == i) {
... | fn solution() {
let mut s: String = String::new();
stdin().read_to_string(&mut s).ok();
let mut itr = s.split_whitespace();
let m: usize = itr.next().unwrap().parse().unwrap();
let d: usize = itr.next().unwrap().parse().unwrap();
let mut ans = 0;
for i in 1..m + 1 {
for j in 1..d + 1... | easy |
0484 | Let $$$LCM(x, y)$$$ be the minimum positive integer that is divisible by both $$$x$$$ and $$$y$$$. For example, $$$LCM(13, 37) = 481$$$, $$$LCM(9, 6) = 18$$$.You are given two integers $$$l$$$ and $$$r$$$. Find two integers $$$x$$$ and $$$y$$$ such that $$$l \le x < y \le r$$$ and $$$l \le LCM(x, y) \le r$$$. | int solution(void) {
int linenum;
scanf("%d", &linenum);
int l[linenum];
int r[linenum];
for (int i = 0; i < linenum; i++) {
getchar();
scanf("%d %d", &l[i], &r[i]);
}
for (int i = 0; i < linenum; i++) {
if (l[i] * 2 > r[i]) {
printf("-1 -1");
} else {
printf("%d %d", l[i],... | fn solution() {
let stdin = std::io::stdin();
let mut line = String::new();
stdin.read_line(&mut line).unwrap();
let ntc: i32 = line.trim().parse().unwrap();
for _ in 0..ntc {
line.clear();
stdin.read_line(&mut line).unwrap();
let a: Vec<i32> = line
.split_whitesp... | medium |
0485 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Find the number of ways to choose a pair of an even number and an odd number from the positive integers between <var>1</var> and <var>K</var> (inclusive). The order does not matter.</p>
</section>
</div... | int solution(void) {
int K = 0;
scanf("%d", &K);
printf("%d", K / 2 * (K - K / 2));
return 0;
} | fn solution() {
let reader = io::stdin();
let mut reader = BufReader::new(reader.lock());
let mut s = String::new();
let _ = reader.read_line(&mut s);
let k: u32 = s.trim().parse().unwrap();
let tmp = k / 2;
println!(
"{}",
if k.is_multiple_of(2) {
tmp * tmp
... | medium |
0486 | Gnome sort | void solution(int *numbers, int size) {
int pos = 0;
while (pos < size) {
if (numbers[pos] >= numbers[pos - 1]) {
pos++;
} else {
int tmp = numbers[pos - 1];
numbers[pos - 1] = numbers[pos];
numbers[pos] = tmp;
pos--;
if (pos == 0) {
pos = 1;
}
}
}
}
| fn solution<T>(arr: &[T]) -> Vec<T>
where
T: cmp::PartialEq + cmp::PartialOrd + Clone,
{
let mut arr = arr.to_vec();
let mut i: usize = 1;
let mut j: usize = 2;
while i < arr.len() {
if arr[i - 1] < arr[i] {
i = j;
j = i + 1;
} else {
arr.swap(i -... | medium |
0487 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are a total of <var>A + B</var> cats and dogs.
Among them, <var>A</var> are known to be cats, but the remaining <var>B</var> are not known to be either cats or dogs.</p>
<p>Determine if it is poss... | int solution() {
int a = 0;
int b = 0;
int c = 0;
scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &c);
if (a + b >= c) {
if (a <= c) {
printf("YES");
} else {
printf("NO");
}
} else {
printf("NO");
}
return 0;
} | fn solution() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
let input: Vec<i32> = s
.split_whitespace()
.map(|x| x.parse::<i32>().unwrap())
.collect();
let mut state = 0;
let lefta = input[2] - input[0];
if lefta >= 0 && lefta <= input[1] {
... | medium |
0488 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has a fair <var>N</var>-sided die that shows the integers from <var>1</var> to <var>N</var> with equal probability and a fair coin. He will play the following game with them:</p>
<ol>
<li>Throw th... | int solution(void) {
double N = 0;
int K = 0;
int count = 1;
double answer = 0;
double temp = 1.0;
int temp2 = 0;
scanf("%lf %d", &N, &K);
double kaku[100000] = {0};
for (int i = 1; i <= N; i++) {
temp2 = i;
while (1) {
if (temp2 >= K) {
for (int j = 1; j < count; j++) {
... | fn solution() {
let text = {
use std::io::Read;
let mut s = String::new();
std::io::stdin().read_to_string(&mut s).unwrap();
s
};
let mut iter = text.split_whitespace();
let num: u64 = iter.next().unwrap().parse().unwrap();
let goal: u64 = iter.next().unwrap().parse(... | hard |
0489 | A ticket is a string consisting of six digits. A ticket is considered lucky if the sum of the first three digits is equal to the sum of the last three digits. Given a ticket, output if it is lucky or not. Note that a ticket can have leading zeroes. | int solution() {
int tickets = 0;
scanf("%d\n", &tickets);
char t[6];
int sum_f = 0;
int sum_l = 0;
while (tickets != 0) {
for (int i = 0; i < 3; i++) {
scanf("%c", &t[i]);
sum_f = sum_f + (t[i] - 48);
}
for (int i = 3; i < 6; i++) {
scanf("%c\n", &t[i]);
sum_l = sum_l + ... | fn solution() {
let mut input_t = String::new();
std::io::stdin()
.read_line(&mut input_t)
.expect("Can't read line");
let t: i32 = input_t.trim().parse().expect("Can't parse input to i32");
println!();
for _ in 0..t {
let mut input_line = String::new();
std::io::st... | hard |
0490 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><var>N</var> hotels are located on a straight line. The coordinate of the <var>i</var>-th hotel <var>(1 \leq i \leq N)</var> is <var>x_i</var>.</p>
<p>Tak the traveler has the following two personal pri... | int solution() {
long N;
long L;
long Q;
long x[100001];
long i;
long j;
long k;
long a;
long b;
long tmp;
long move[100001];
long move100[100001];
long right;
long ans[100001] = {0};
scanf("%ld", &N);
for (i = 1; i <= N; i++) {
scanf("%ld", &x[i]);
}
scanf("%ld", &L);
right ... | fn solution() {
input! {
n: usize,
v: [usize; n],
l: usize,
q: usize,
qs: [(usize1, usize1); q]
}
let mut p = 1;
while 1 << p < n - 1 {
p += 1;
}
p += 1;
let mut tab = vec![vec![0; p]; n];
for i in 0..p {
tab[n - 1][i] = n - 1;
... | medium |
0491 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given two positive integers <var>A</var> and <var>B</var>. Compare the magnitudes of these numbers.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≤ A, B ... | int solution() {
int len1 = 0;
int len2 = 0;
char s1[101];
char s2[101];
scanf("%s %s", s1, s2);
while (s1[len1]) {
len1++;
}
while (s2[len2]) {
len2++;
}
if (len1 > len2 || (len1 == len2 && strcmp(s1, s2) > 0)) {
printf("GREATER\n");
} else if (strcmp(s1, s2) == 0) {
printf("EQU... | fn solution() {
let mut buf = String::new();
io::stdin().read_line(&mut buf).expect("");
let a = buf.trim().chars().collect::<Vec<char>>();
let mut buf = String::new();
io::stdin().read_line(&mut buf).expect("");
let b = buf.trim().chars().collect::<Vec<char>>();
if a.len() > b.len() {
... | easy |
0492 | Omkar has received a message from Anton saying "Your story for problem A is confusing. Just make a formal statement." Because of this, Omkar gives you an array $$$a = [a_1, a_2, \ldots, a_n]$$$ of $$$n$$$ distinct integers. An array $$$b = [b_1, b_2, \ldots, b_k]$$$ is called nice if for any two distinct elements $$$b_... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int arr[n];
int f = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
if (arr[i] < 0) {
f = 1;
}
}
if (f) {
printf("NO\n");
} else {
printf("YES\n");
prin... | 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();
... | medium |
0493 | Ashish and Vivek play a game on a matrix consisting of $$$n$$$ rows and $$$m$$$ columns, where they take turns claiming cells. Unclaimed cells are represented by $$$0$$$, while claimed cells are represented by $$$1$$$. The initial state of the matrix is given. There can be some claimed cells in the initial state.In eac... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int r;
int c;
scanf("%d %d", &r, &c);
int a[r][c];
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
scanf("%d", &a[i][j]);
}
}
int ans = 0;
for (int i = 0, k = 0; i < r && k < c;) {
int x ... | fn solution() {
let cases = {
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("failed to read input");
input.trim().parse::<u8>().expect("invalid input")
};
for _ in 0..cases {
let (n, m) = {
let mut input = Stri... | medium |
0494 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Fennec and Snuke are playing a board game.</p>
<p>On the board, there are <var>N</var> cells numbered <var>1</var> through <var>N</var>, and <var>N-1</var> roads, each connecting two cells. Cell <var>a_... | int solution(void) {
int n;
scanf("%d", &n);
int m = 0;
int head[n * 2];
int next[n * 2];
int to[n * 2];
int a;
int b;
int post[n];
int count;
bool visited[n];
for (int i = 0; i < n; i++) {
head[i] = -1;
}
for (int i = 0; i < n - 1; i++) {
scanf("%d%d", &a, &b);
a--;
b--;
... | fn solution() {
let stdin = io::stdin();
let mut buf = String::new();
stdin
.read_line(&mut buf)
.expect("ERROR Can't read array size");
let n: usize = buf.trim().parse().unwrap();
let mut graph: Vec<Vec<usize>> = Vec::with_capacity(n);
for _ in 0..n {
graph.push(Vec::new... | easy |
0495 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You have written <var>N</var> problems to hold programming contests.
The <var>i</var>-th problem will have a score of <var>P_i</var> points if used in a contest.</p>
<p>With these problems, you would li... | int solution(void) {
int n;
int a;
int b;
int p[101];
int cnt1 = 0;
int cnt2 = 0;
int cnt3 = 0;
int ans = 0;
;
scanf("%d%d%d", &n, &a, &b);
for (int cnt = 1; cnt <= n; cnt++) {
scanf("%d", &p[cnt]);
if (p[cnt] <= a) {
cnt1++;
} else if (p[cnt] < b || p[cnt] <= b) {
cnt2++... | fn solution() {
let mut buf = String::new();
let handle = std::io::stdin();
let _n: usize = {
handle.read_line(&mut buf).unwrap();
let tmp = buf.trim().parse().unwrap();
buf.clear();
tmp
};
let info: Vec<usize> = {
handle.read_line(&mut buf).unwrap();
... | hard |
0496 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>A Hitachi string is a concatenation of one or more copies of the string <code>hi</code>.</p>
<p>For example, <code>hi</code> and <code>hihi</code> are Hitachi strings, while <code>ha</code> and <code>h... | int solution(void) {
char s[10];
int c = 1;
int i = 0;
scanf("%s", s);
while (s[i]) {
if (!((i % 2 == 0 && s[i] == 'h') || (i % 2 == 1 && s[i] == 'i'))) {
c = 0;
break;
}
i++;
}
if (c == 1 && i % 2 == 0) {
printf("Yes\n");
} else {
printf("No\n");
}
return 0;
} | fn solution() {
let mut target_str = String::new();
io::stdin().read_line(&mut target_str).unwrap();
let target_str = target_str.trim();
let mut count: usize = 0;
loop {
match target_str.chars().nth(count) {
Some('h') => match target_str.chars().nth(count + 1) {
... | easy |
0497 | Returning back to problem solving, Gildong is now studying about palindromes. He learned that a palindrome is a string that is the same as its reverse. For example, strings "pop", "noon", "x", and "kkkkkk" are palindromes, while strings "moon", "tv", and "abab" are not. An empty string is also a palindrome.Gildong love... | int solution() {
char re[110][55];
int tt[110] = {0};
int y[110][2] = {0};
int n;
int m;
int k = 0;
scanf("%d %d%*c", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%s", re[i]);
}
for (int i = 1; i <= n - 1; i++) {
if (tt[i] == 0) {
for (int j = i + 1; j <= n; j++) {
if (tt[j] ... | fn solution() {
let mut line = String::new();
io::stdin().read_line(&mut line).unwrap();
let mut pieces = line.split_whitespace();
let n: u32 = pieces.next().unwrap().parse().unwrap();
let _m: u32 = pieces.next().unwrap().parse().unwrap();
let mut strings = Vec::new();
for _ in 0..n {
... | hard |
0498 | A telephone number is a sequence of exactly 11 digits, where the first digit is 8. For example, the sequence 80011223388 is a telephone number, but the sequences 70011223388 and 80000011223388 are not.You are given a string $$$s$$$ of length $$$n$$$, consisting of digits.In one operation you can delete any character fr... | int solution() {
int t;
scanf("%d", &t);
int a[t];
char s[t][101];
for (int i = 0; i < t; i++) {
scanf("%d", &a[i]);
getchar();
scanf("%s", s[i]);
}
int flag = 1;
for (int i = 0; i < t; i++) {
flag = 1;
for (int j = 0; j < a[i] - 10; j++) {
if (s[i][j] == '8') {
printf(... | fn solution() {
use std::io::{self, Read};
let mut b = String::new();
io::stdin().read_to_string(&mut b).unwrap();
let a = b.split_whitespace().skip(1).collect::<Vec<_>>();
for j in a.as_slice().chunks(2) {
let i = j[1];
match i.find('8') {
Some(idx) => {
... | easy |
0499 | There are $$$n$$$ points on the plane, $$$(x_1,y_1), (x_2,y_2), \ldots, (x_n,y_n)$$$.You need to place an isosceles triangle with two sides on the coordinate axis to cover all points (a point is covered if it lies inside the triangle or on the side of the triangle). Calculate the minimum length of the shorter side of t... | int solution() {
int arr[100000][3];
int max = 0;
int n = 0;
int i = 0;
int j = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
for (j = 0; j < 2; j++) {
scanf("%d", &arr[i][j]);
}
}
for (i = 0; i < n; i++) {
arr[i][2] = arr[i][0] + arr[i][1];
}
max = arr[0][2];
for (i = 0; i < 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::<u32>().unwrap())
.collect();
let n = arr[0] as usize;
... | medium |
0500 | <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> Snuke Cats numbered <var>1, 2, \ldots, N</var>, where <var>N</var> is <strong>even</strong>.</p>
<p>Each Snuke Cat wears a red scarf, on which his favorite non-negative integer is... | int solution(void) {
int n = 0;
int xa = 0;
int a[200000] = {0};
int i = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
xa ^= a[i];
}
for (i = 0; i < n; i++) {
printf("%d ", a[i] ^ xa);
}
return 0;
} | fn solution() {
let _n = {
let mut buf = String::new();
stdin().read_line(&mut buf).unwrap();
buf.split_whitespace()
.next()
.unwrap()
.parse::<i64>()
.unwrap()
};
let a: Vec<i64> = {
let mut buf = String::new();
stdin()... | medium |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.