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 |
|---|---|---|---|---|
1301 | The only difference between the two versions is that this version asks the maximal possible answer.Homer likes arrays a lot. Today he is painting an array $$$a_1, a_2, \dots, a_n$$$ with two kinds of colors, white and black. A painting assignment for $$$a_1, a_2, \dots, a_n$$$ is described by an array $$$b_1, b_2, \dot... | int solution() {
int n;
scanf("%d", &n);
int a[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
int last1 = -1;
int last2 = -1;
int ans = n;
for (int i = 0; i < n - 1; i++) {
if (a[i] != last1 && a[i] != last2) {
if (a[i + 1] == last1) {
last1 = a[i];
} else {
... | fn solution() {
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 mut array: Vec<usize> = vec![0; n + 1];
for i in 1..=n {
array[i] = sc.next();
}
... | hard |
1302 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>A balance scale tips to the left if <var>L>R</var>, where <var>L</var> is the total weight of the masses on the left pan and <var>R</var> is the total weight of the masses on the right pan. Similarly... | int solution() {
int A = 0;
int B = 0;
int C = 0;
int D = 0;
scanf("%d %d %d %d\n", &A, &B, &C, &D);
if (A + B > C + D) {
printf("Left");
} else if (A + B == C + D) {
printf("Balanced");
} else {
printf("Right");
}
return 0;
} | fn solution() {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).ok();
let q: Vec<i32> = buf.split_whitespace().map(|x| x.parse().unwrap()).collect();
match (q[0] + q[1]).cmp(&(q[2] + q[3])) {
Ordering::Greater => println!("Left"),
Ordering::Equal => println!("Balanced... | easy |
1303 | Two T-shirt sizes are given: $$$a$$$ and $$$b$$$. The T-shirt size is either a string M or a string consisting of several (possibly zero) characters X and one of the characters S or L.For example, strings M, XXL, S, XXXXXXXS could be the size of some T-shirts. And the strings XM, LL, SX are not sizes.The letter M stand... | int solution(void) {
int t;
scanf("%d", &t);
while (t--) {
char a[51];
char b[51];
scanf("%s %s", a, b);
if (((a[0] == 'L' || a[strlen(a) - 1] == 'L') && b[0] == 'M') ||
(a[0] == 'M' && (b[0] == 'S' || b[strlen(b) - 1] == 'S')) ||
(a[strlen(a) - 1] == 'L' && b[strlen(b) - 1] ==... | fn solution() {
let t: usize = {
let mut line: String = String::new();
std::io::stdin().read_line(&mut line).unwrap();
line.trim().parse().unwrap()
};
for _ in 0..t {
let (a, b): (Vec<char>, Vec<char>) = {
let mut line: String = String::new();
std::io... | easy |
1304 | <span class="lang-en">
<p>Score: <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p><font color="red"><strong>This is an interactive task.</strong></font></p>
<p>We have <var>2N</var> balls arranged in a row, numbered <var>1, 2, 3, ..., 2N</var> from left to right, where <var>N</var> i... | int solution() {
int n;
scanf("%d", &n);
char ans[102];
int i;
int j;
for (i = 0; i < 2 * n; i++) {
ans[i] = '?';
}
int r;
int b;
int c;
int min;
int mid;
int max;
char minc;
char res[16];
printf("?");
for (i = 0; i < n; i++) {
printf(" %d", i + 1);
}
printf("\n");
fflush... | fn solution() {
let N: usize = {
let mut line: String = String::new();
std::io::stdin().read_line(&mut line).unwrap();
line.trim().parse().unwrap()
};
println!(
"? {}",
(1..(N + 1))
.map(|i| i.to_string())
.collect::<Vec<_>>()
.joi... | easy |
1305 | <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> points in a <var>D</var>-dimensional space.</p>
<p>The coordinates of the <var>i</var>-th point are <var>(X_{i1}, X_{i2}, ..., X_{iD})</var>.</p>
<p>The distance between two point... | int solution() {
int N = 0;
int D = 0;
int i = 0;
int j = 0;
int ans = 0;
int count = 0;
double ansd = 0.0;
int X[11][10] = {0};
scanf("%d %d", &N, &D);
for (i = 0; i < N; i++) {
for (j = 0; j < D; j++) {
scanf("%d", &X[i][j]);
}
}
for (j = 0; j < D; j++) {
X[N][j] = X[0][j];
... | fn solution() {
let (N, D): (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(),
... | medium |
1306 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We will buy a product for <var>N</var> yen (the currency of Japan) at a shop.</p>
<p>If we use only <var>1000</var>-yen bills to pay the price, how much change will we receive?</p>
<p>Assume we use the ... | int solution(void) {
int N = 0;
scanf("%d", &N);
for (int i = 0; i < 10; i++) {
if (((1000 * i) < N) && (N <= (1000 * (i + 1)))) {
printf("%d", (1000 * (i + 1)) - N);
}
}
return 0;
} | fn solution() {
let mut line = String::new();
stdin().read_line(&mut line).ok();
let n: i32 = line.trim().parse().ok().unwrap();
println!(
"{}",
if n % 1000 == 0 {
0
} else {
(n / 1000 + 1) * 1000 - n
}
);
} | medium |
1307 | Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all n dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito'... | int solution() {
int s;
int n;
int flag = 0;
scanf("%d%d", &s, &n);
int a[n][2];
for (int i = 0; i < n; i++) {
scanf("%d%d", &a[i][0], &a[i][1]);
}
for (int i = 0; i < n; i++) {
for (int k = 0; k < n; k++) {
if (s > a[k][0] && a[k][0] != 0) {
s += a[k][1];
a[k][0] = 0;
... | fn solution() {
let mut line = String::new();
stdin().read_line(&mut line).unwrap();
let words: Vec<i32> = line
.split_whitespace()
.map(|x| x.parse().unwrap())
.collect();
let mut s = words[0];
let n = words[1];
let mut dragons = Vec::<Vec<i32>>::new();
for _ in ... | hard |
1308 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In <em>K-city</em>, there are <var>n</var> streets running east-west, and <var>m</var> streets running north-south. Each street running east-west and each street running north-south cross each other. We... | int solution() {
int m = 0;
int n = 0;
if (scanf("%d %d", &n, &m) && n >= 2 && n <= 100 && m >= 2 && m <= 100) {
printf("%d", (n - 1) * (m - 1));
} else {
return 0;
}
return 0;
} | fn solution() {
let mut line = String::new();
io::stdin().read_line(&mut line).ok();
let v: Vec<u16> = line
.split_whitespace()
.map(|n| n.parse().unwrap())
.collect();
let n = v[0];
let m = v[1];
println!("{}", (n - 1) * (m - 1));
} | medium |
1309 | In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?).A group of soldiers is effective if and only if their names a... | int solution() {
int n;
int k;
unsigned char str[4];
unsigned char ans[51];
scanf("%d %d", &n, &k);
for (int i = 0; i < n; ++i) {
ans[i] = i + 1;
}
for (int i = 0; i < n - k + 1; ++i) {
scanf("%s", str);
if (str[0] == 'N') {
ans[i + k - 1] = ans[i];
}
}
for (int i = 0; i < n; +... | fn solution() {
let mut soldiers = vec![];
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
let mut input = input.split_whitespace();
let n = input.next().unwrap().parse::<usize>().unwrap();
let k = input.next().unwrap().parse::<usize>().unwrap();
let mut in... | medium |
1310 | Monocarp is playing a computer game. In this game, his character fights different monsters.A fight between a character and a monster goes as follows. Suppose the character initially has health $$$h_C$$$ and attack $$$d_C$$$; the monster initially has health $$$h_M$$$ and attack $$$d_M$$$. The fight consists of several ... | int solution() {
int t;
long long int d;
long long int e;
scanf("%d", &t);
long long int hc[t];
long long int dc[t];
long long int hm[t];
long long int dm[t];
long long int k[t];
long long int w[t];
long long int a[t];
int i;
int j;
int flag[t];
for (i = 0; i < t; i++) {
flag[i] = 0;
... | fn solution() {
let mut line = String::new();
let stdin = io::stdin();
let mut stdin = stdin.lock();
stdin.read_line(&mut line).unwrap();
let t: usize = line.trim().parse().unwrap();
let stdout = io::stdout();
let handle = stdout.lock();
let mut buffer = BufWriter::with_capacity(65536, ... | medium |
1311 | You are given a positive integer $$$x$$$. Check whether the number $$$x$$$ is representable as the sum of the cubes of two positive integers.Formally, you need to check if there are two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b$$$) such that $$$a^3+b^3=x$$$.For example, if $$$x = 35$$$, then the numbers $$$a=2$$$ and... | int solution() {
int t = 0;
int yes = 0;
long long int k = 0;
long long int j = 0;
long long int s = 0;
long long int n = 0;
long long int i = 0;
long long int last = 0;
scanf("%d", &t);
while (t-- > 0) {
i = 1;
yes = 0;
scanf("%lld", &n);
while ((i * i * i) < n) {
i++;
}
... | fn solution() {
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 cubes: BTreeSet<i64> = (1..10001_i64).map(|i| i * i * i).collect();
let tc: usize = sc.next();
for _ in 0..tc {
le... | hard |
1312 | Today, Marin is at a cosplay exhibition and is preparing for a group photoshoot!For the group picture, the cosplayers form a horizontal line. A group picture is considered beautiful if for every contiguous segment of at least $$$2$$$ cosplayers, the number of males does not exceed the number of females (obviously).Curr... | int solution() {
int t;
int l = 0;
int ans = 0;
scanf("%d", &t);
int arr[t];
char *p[t];
for (int i = 0; i < t; i++) {
scanf("%d", &arr[i]);
p[i] = (char *)calloc(arr[i] + 1, sizeof(char));
scanf("%s", p[i]);
}
for (int i = 0; i < t; i++) {
l = strlen(p[i]);
ans = 0;
for (int j... | fn solution() {
let mut qntcasos = String::new();
io::stdin().read_line(&mut qntcasos).unwrap();
let qntcasos: u32 = qntcasos.trim().parse().unwrap();
for _i in 0..qntcasos {
let mut casoatual = String::new();
let mut casoatualnumero = String::new();
io::stdin().read_line(&mut ... | medium |
1313 | <H1>問題 1: 平均点 (Average Score)
</H1>
<br/>
<h2>問題</h2>
<p>
JOI 高校の授業には,太郎君,次郎君,三郎君,四郎君,花子さんの 5 人の生徒が参加した.
</p>
<p>
この授業では,期末試験を実施した.期末試験は,5 人全員が受験した.期末試験の点数が 40 点以上の生徒は,期末試験の点数がそのまま成績になった.期末試験の点数が 40 点未満の生徒は全員,補習を受け,成績が 40 点になった.
</p>
<p>
5 人の生徒の期末試験の点数が与えられたとき,5 人の成績の平均点を計算するプログラムを作成せよ.
</p>
<h2> 入力</h2>
<p>
入力は 5... | int solution() {
int a = 0;
int ans = 0;
int i = 0;
for (i = 0; i < 5; i++) {
scanf("%d", &a);
if (a <= 40) {
a = 40;
}
ans += a;
}
printf("%d\n", ans / 5);
return 0;
} | fn solution() {
let input = {
let mut buf = vec![];
stdin().read_to_end(&mut buf);
unsafe { String::from_utf8_unchecked(buf) }
};
let lines = input.split('\n');
let avg = lines
.take(5)
.map(|l| {
let score = l.parse().unwrap();
if score <... | easy |
1314 | Mishka wants to buy some food in the nearby shop. Initially, he has $$$s$$$ burles on his card. Mishka can perform the following operation any number of times (possibly, zero): choose some positive integer number $$$1 \le x \le s$$$, buy food that costs exactly $$$x$$$ burles and obtain $$$\lfloor\frac{x}{10}\rfloor$$$... | int solution() {
int snum;
int s[10000];
scanf("%d", &snum);
for (int i = 0; i < snum; i++) {
scanf("%d", &s[i]);
}
for (int i = 0; i < snum; i++) {
int x = s[i];
do {
x = x + s[i] / 10;
s[i] = s[i] - s[i] / 10 * 10 + s[i] / 10;
} while (s[i] / 10 > 0);
printf("%d\n", x);... | fn solution() {
let mut line = String::new();
io::stdin().read_line(&mut line).unwrap();
let t: u32 = line.trim().parse().unwrap();
for _ in 0..t {
let mut line = String::new();
io::stdin().read_line(&mut line).unwrap();
let mut coins: u32 = line.trim().parse().unwrap();
... | medium |
1315 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are <var>1</var>-digit positive integers <var>a</var> and <var>b</var>. Consider these two strings: the concatenation of <var>b</var> copies of the digit <var>a</var>, and the concatenation of <va... | int solution(void) {
int a = 0;
scanf("%d", &a);
int b = 0;
scanf("%d", &b);
int ans = 0;
if (a <= b) {
for (int i = 0; i < b; i++) {
ans = ans + a * pow(10, i);
}
printf("%d", ans);
} else {
for (int i = 0; i < a; i++) {
ans = ans + b * pow(10, i);
}
printf("%d", an... | fn solution() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
let ab: Vec<i32> = s.split_whitespace().map(|w| w.parse().unwrap()).collect();
if ab[0] < ab[1] {
for _ in 0..ab[1] {
print!("{}", ab[0]);
}
} else {
for _ in 0..ab[0] {
... | hard |
1316 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is an integer sequence <var>A</var> of length <var>N</var> whose values are unknown.</p>
<p>Given is an integer sequence <var>B</var> of length <var>N-1</var> which is known to satisfy the followi... | int solution() {
int N;
int ans = 0;
scanf("%d", &N);
int B[N - 1];
for (int i = 0; i < N - 1; i++) {
scanf("%d", &B[i]);
}
if (N > 2) {
for (int i = 0; i < N - 1; i++) {
if ((B[i] > B[i + 1]) && (i < N - 2)) {
ans += B[i + 1];
}
if ((B[i] <= B[i + 1]) && (i < N - 2)) {
... | fn solution() {
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).unwrap();
let mut iter = buf.split_whitespace();
let n: usize = iter.next().unwrap().parse().unwrap();
let mut b: Vec<usize> = vec![];
for _ in 0..(n - 1) {
b.push(iter.next().unwrap().parse().unwrap... | medium |
1317 | There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought $$$n$$$ packets with inflatable balloons, where $$$i$$$-th of them has exactly $$$a_i$$$ bal... | int solution() {
int n;
scanf("%d", &n);
int a[n + 1];
int sum = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
sum += a[i];
}
if (n == 1 || (n == 2 && a[0] == a[1])) {
printf("-1\n");
return 0;
}
if (sum - a[0] == a[0]) {
printf("2\n1 2\n");
} else {
printf("1\n1\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 input_strs = buffer
.split_whitespace()
.map(|x| x.parse::<i64>().unwrap())
.collect::<Vec<i64>>();
let _n = input_s... | medium |
1318 | Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains $$$26$$$ buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunctioning. To check which buttons need replacement, Polycarp pressed... | int solution(void) {
unsigned short test_cases;
scanf("%hu\n", &test_cases);
const unsigned short SIZE = 26;
bool button_states[SIZE];
for (unsigned short i = 0; i < test_cases; ++i) {
memset(button_states, false, sizeof(button_states));
const unsigned short MAX_LENGTH = 500;
char str[MAX_LENGTH... | fn solution() {
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("failed to read input");
let t = input.trim().parse::<u8>().unwrap();
for _ in 0..t {
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expec... | medium |
1319 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> balls in a row.
Initially, the <var>i</var>-th ball from the left has the integer <var>A_i</var> written on it.</p>
<p>When Snuke cast a spell, the following happens:</p>
<ul>
<l... | int solution() {
int N;
int M;
int i;
int j;
int ans = 0;
int old;
int new;
scanf("%d%d", &N, &M);
int *A = (int *)malloc(sizeof(int) * N);
int *Anum = (int *)malloc(sizeof(int) * N);
int *B = (int *)malloc(sizeof(int) * N * 2);
int *X = (int *)malloc(sizeof(int) * M);
int *Y = (int *)malloc(s... | fn solution() {
input! {
n: usize,
m: usize,
mut v: [usize; n],
xy: [(usize1, usize); m]
}
let mut cnt = vec![0; n + 1];
let mut ds = vec![0; n];
for &a in &v {
if cnt[a] < a {
ds[a - cnt[a] - 1] += 1;
}
cnt[a] += 1;
}
let m... | medium |
1320 | Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy... | int solution() {
int t;
long long int n;
long long int k;
long long int done;
long long int path;
long long int h;
scanf("%d%*c", &t);
while (t > 0) {
scanf("%lld %lld%*c", &n, &k);
done = 1;
n -= 1;
h = 0;
path = 1;
while (n > 0) {
if (2 * path <= k && 2 * path <= done) {
... | 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();
for _case in 1..=t {
let n: u64 = it.next().unwrap(... | medium |
1321 | Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choos... | int solution(void) {
int t = 0;
scanf("%d", &t);
while (t--) {
int n = 0;
scanf("%d", &n);
int arr[n];
int res[n];
int tmp = 0;
int r = 0;
for (int i = 0; i < n; i++) {
scanf("%d", arr + i);
}
res[r++] = arr[0];
for (int i = 1; i < (n - 1); i++) {
if ((arr[... | 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 ss: Vec<usize> = lines
.next()
.unwra... | easy |
1322 | <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> slimes lining up in a row.
Initially, the <var>i</var>-th slime from the left has a size of <var>a_i</var>.</p>
<p>Taro is trying to combine all the slimes into a larger slime.
He... | int solution() {
int n;
scanf("%d", &n);
long long a[n];
long long dp[n][n];
for (int i = 0; i < n; ++i) {
scanf("%lld", a + i), dp[i][i] = 0;
}
for (int d = 1; d < n; ++d) {
for (int l = 0; l <= n - 1 - d; ++l) {
dp[l][l + d] = 1000000000000000000;
for (int m = l; m < l + d; ++m) {
... | fn solution() {
input! {
n: usize,
v: [usize; n]
}
let mut tab: Vec<Vec<usize>> = vec![vec![usize::max_value(); n]; n];
let mut ps: Vec<usize> = v
.iter()
.clone()
.scan(0, |ac, x| {
*ac += *x;
Some(*ac)
})
.collect();
p... | medium |
1323 | Dima's got a staircase that consists of n stairs. The first stair is at height a1, the second one is at a2, the last one is at an (1 ≤ a1 ≤ a2 ≤ ... ≤ an). Dima decided to play with the staircase, so he is throwing rectangular boxes at the staircase from above. The i-th box has width wi and height hi. Dima throws each ... | int solution() {
int n;
int m;
int i;
int w;
int h;
double max = 0;
scanf("%d", &n);
int v[n];
for (i = 0; i < n; i++) {
scanf("%d", &v[i]);
}
scanf("%d", &m);
for (i = 0; i < m; i++) {
scanf("%d %d", &w, &h);
if (max > v[w - 1]) {
max = max;
} else {
max = v[w... | fn solution() {
let mut buffer = String::new();
io::stdin().read_line(&mut buffer);
buffer = String::new();
io::stdin().read_line(&mut buffer);
let a: Vec<i64> = buffer
.split_whitespace()
.filter_map(|str| str.parse::<i64>().ok())
.collect();
buffer = String::new();
... | medium |
1324 | One day, Vogons wanted to build a new hyperspace highway through a distant system with $$$n$$$ planets. The $$$i$$$-th planet is on the orbit $$$a_i$$$, there could be multiple planets on the same orbit. It's a pity that all the planets are on the way and need to be destructed.Vogons have two machines to do that. The ... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
int c;
int count = 0;
scanf("%d %d", &n, &c);
int b[101];
for (int i = 0; i < 101; i++) {
b[i] = 0;
}
int a[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
b[a[i]]++;
}
for (int i =... | 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 line1 = line_iter.next... | medium |
1325 | Sayaka Saeki is a member of the student council, which has $$$n$$$ other members (excluding Sayaka). The $$$i$$$-th member has a height of $$$a_i$$$ millimeters.It's the end of the school year and Sayaka wants to take a picture of all other members of the student council. Being the hard-working and perfectionist girl a... | int solution() {
int t = 0;
scanf("%d", &t);
while (t--) {
int n = 0;
scanf("%d", &n);
int a[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
int odd = 0;
int even = 0;
int o[n];
int e[n];
for (int i = 0; i < n; i++) {
o[i] = 0;
e[i] = 0;
}
... | fn solution() {
let mut line = String::new();
stdin().read_line(&mut line).unwrap();
let t: i64 = line.trim().parse().unwrap();
for _ in 0..t {
let mut line = String::new();
stdin().read_line(&mut line).unwrap();
let _n: i64 = line.trim().parse().unwrap();
let mut line ... | medium |
1326 | You are given four positive integers $$$n$$$, $$$m$$$, $$$a$$$, $$$b$$$ ($$$1 \le b \le n \le 50$$$; $$$1 \le a \le m \le 50$$$). Find any such rectangular matrix of size $$$n \times m$$$ that satisfies all of the following conditions: each row of the matrix contains exactly $$$a$$$ ones; each column of the matrix co... | int solution() {
int t;
int m;
int n;
int i;
int b;
int a;
int j;
int count;
scanf("%d", &t);
while (t--) {
scanf("%d%d%d%d", &n, &m, &a, &b);
if (n * a != m * b) {
printf("NO\n");
continue;
}
printf("YES\n");
int aa[51][51];
i = -1;
while (++i < n) {
j ... | 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();
... | easy |
1327 | Ania has a large integer $$$S$$$. Its decimal representation has length $$$n$$$ and doesn't contain any leading zeroes. Ania is allowed to change at most $$$k$$$ digits of $$$S$$$. She wants to do it in such a way that $$$S$$$ still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania ... | int solution() {
int n;
int k;
scanf("%d %d", &n, &k);
char num[n];
scanf("%s", num);
if (n == 1 && k >= 1) {
printf("%c\n", '0');
return 0;
} else {
if (num[0] != '1' && k > 0) {
num[0] = '1';
k--;
}
int y = 1;
while (k > 0 && y <= n - 1) {
if (num[y] != '0') {
... | fn solution() {
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("failed to read input");
let mut input_iter = input.split_whitespace();
let _n = input_iter.next();
let mut k = input_iter.next().unwrap().parse::<usize>().unwrap();
let mut input = String:... | medium |
1328 | Recently, Norge found a string $$$s = s_1 s_2 \ldots s_n$$$ consisting of $$$n$$$ lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string $$$s$$$. Yes, all $$$\frac{n (n + 1)}{2}$$$ of them!A substring of $$$s$$$ is a non-empty string $$$x = s[a \ldots b] = s... | int solution() {
int n;
int k;
scanf("%d %d", &n, &k);
char c;
scanf("%c", &c);
char input[n];
int chars[26];
for (int i = 0; i < 26; i++) {
chars[i] = 0;
}
for (int i = 0; i < n; i++) {
scanf("%c", &c);
input[i] = c;
}
scanf("%c", &c);
for (int i = 0; i < k; i++) {
scanf("%c"... | fn solution() {
let mut str = String::new();
let _b1 = stdin().read_line(&mut str).unwrap();
let mut iter = str.split_whitespace();
let m: i64 = iter.next().unwrap().parse().unwrap();
let _n: i64 = iter.next().unwrap().parse().unwrap();
let mut test_string = String::new();
let _b1 = stdin()... | hard |
1329 | Polycarp remembered the $$$2020$$$-th year, and he is happy with the arrival of the new $$$2021$$$-th year. To remember such a wonderful moment, Polycarp wants to represent the number $$$n$$$ as the sum of a certain number of $$$2020$$$ and a certain number of $$$2021$$$.For example, if: $$$n=4041$$$, then the number... | int solution() {
int n = 0;
int num = 0;
scanf("%d", &n);
while (n--) {
scanf("%d", &num);
int a = num / 2020;
int b = num % 2020;
if (a >= b) {
printf("YES\n");
} else {
printf("NO\n");
}
}
return 0;
} | fn solution() {
let stdin = std::io::stdin();
let mut hash = HashSet::new();
hash.insert(0u64);
let mut producables = HashSet::new();
let mut a = 0;
while a <= 1_000_000 {
let mut b = 0;
while a + b <= 1_000_000 {
producables.insert(a + b);
b += 2021;
... | medium |
1330 | There is a bookshelf which can fit $$$n$$$ books. The $$$i$$$-th position of bookshelf is $$$a_i = 1$$$ if there is a book on this position and $$$a_i = 0$$$ otherwise. It is guaranteed that there is at least one book on the bookshelf.In one move, you can choose some contiguous segment $$$[l; r]$$$ consisting of books ... | int solution() {
int t = 0;
scanf("%d%*c", &t);
for (int i = 0; i < t; i++) {
int n = 0;
scanf("%d%*c", &n);
int startCounting = 0;
int tempSum = 0;
int res = 0;
for (int j = 0; j < n; j++) {
int temp = 0;
scanf("%d%*c", &temp);
if (temp == 0) {
tempSum++;
}... | fn solution() {
let mut input = "".split_ascii_whitespace();
let mut read = || loop {
if let Some(word) = input.next() {
break word;
}
input = {
let mut input = "".to_owned();
io::stdin().read_line(&mut input).unwrap();
if input.is_empty() ... | medium |
1331 | <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> weights indexed <var>1</var> to <var>N</var>. The mass of the weight indexed <var>i</var> is <var>W_i</var>.</p>
<p>We will divide these weights into two groups: the weights with i... | int solution() {
int n = 0;
int total = 0;
int s1 = 0;
int s2 = 0;
int s3 = 0;
int w[100];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &w[i]);
total = w[i] + total;
}
int ans = total;
for (int i = 0; i < n; i++) {
s1 = s1 + w[i];
s2 = total - s1;
s3 = abs(s2 - s1... | fn solution() {
let n: usize = {
let mut n = String::new();
io::stdin().read_line(&mut n).unwrap();
n.trim_end().to_owned().trim().parse().unwrap()
};
let mut buf = String::new();
io::stdin().read_line(&mut buf).unwrap();
let w: Vec<i32> = buf.split_whitespace().map(|s| s.pa... | medium |
1332 | You are given two strings $$$s$$$ and $$$t$$$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $$$1$$$. You can't choose a string if it is empty.For example: by applying a move to the string "where", the res... | int solution() {
char *A = malloc(sizeof(char) * 200005);
char *B = malloc(sizeof(char) * 200005);
scanf("%s %s", A, B);
int length_A = strlen(A);
int length_B = strlen(B);
int totalamt = length_A + length_B;
for (int index_A = length_A - 1, index_B = length_B - 1;
index_A >= 0 && index_B >= 0;) {
... | fn solution() {
let mut stdin = String::new();
std::io::Read::read_to_string(&mut std::io::stdin(), &mut stdin).unwrap();
let mut stdin = stdin.split_whitespace();
let mut get = || stdin.next().unwrap();
let s = get().as_bytes();
let t = get().as_bytes();
let mut i = s.len() - 1;
let mu... | medium |
1333 | You are given a digital clock with $$$n$$$ digits. Each digit shows an integer from $$$0$$$ to $$$9$$$, so the whole clock shows an integer from $$$0$$$ to $$$10^n-1$$$. The clock will show leading zeroes if the number is smaller than $$$10^{n-1}$$$.You want the clock to show $$$0$$$ with as few operations as possible.... | int solution() {
int tc;
scanf("%d", &tc);
for (int i = 0; i < tc; i++) {
int n;
scanf("%d", &n);
int arr[n];
for (int j = 0; j < n; j++) {
scanf("%1d", &arr[j]);
}
int sum = 0;
for (int j = 0; j < n; j++) {
if (j == n - 1 && arr[j] > 0) {
sum += arr[j];
} el... | fn solution() {
let stdin = stdin();
let mut string = String::new();
stdin.read_line(&mut string).unwrap();
for _ in 0..string.trim().parse::<usize>().unwrap() {
string.clear();
stdin.read_line(&mut string).unwrap();
string.clear();
stdin.read_line(&mut string).unwrap();
... | hard |
1334 | <h3><U>The Balance of the World</U></h3>
<!-- end en only -->
<div> <!-- please enclose each h3 level section with div -->
<!-- begin en only -->
<p>
The world should be finely balanced. Positive vs. negative,
light vs. shadow, and left vs. right brackets.
Your mission is to write a program that judges whether a s... | int solution(void) {
char s[128];
char stack[128];
while (fgets(s, 128, stdin)) {
int n = strlen(s) - 1;
char *p = strchr(s, '\n');
int i;
int ok = 1;
int sp = 0;
if (p) {
*p = 0;
}
if (*s == '.' && n == 1) {
break;
}
for (i = 0; i < n; ++i) {
switch (s[i... | fn solution() {
let stdin = io::stdin();
for line in stdin.lock().lines() {
let chars: Vec<char> = line.unwrap().chars().collect();
if chars[0] == '.' && chars.len() <= 1 {
return;
}
let mut stack: Vec<char> = Vec::new();
for char in chars {
if ... | easy |
1335 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Caracal is fighting with a monster.</p>
<p>The <em>health</em> of the monster is <var>H</var>.</p>
<p>Caracal can attack by choosing one monster. When a monster is attacked, depending on that monster's ... | int solution() {
unsigned long n = 0;
unsigned long r = 1;
scanf("%lu", &n);
while (n != 0) {
n >>= 1;
r <<= 1;
}
printf("%lu", r - 1);
} | fn solution() {
let mut buf = String::new();
let stdin = std::io::stdin();
stdin.lock().read_to_string(&mut buf).unwrap();
let mut iter = buf.split_whitespace();
let h = iter.next().unwrap().parse::<usize>().unwrap();
let mut ans = 0_usize;
for i in (0..41).rev() {
if (h & 1 << i) !... | hard |
1336 | You are given two arrays of integers $$$a_1,\ldots,a_n$$$ and $$$b_1,\ldots,b_m$$$.Your task is to find a non-empty array $$$c_1,\ldots,c_k$$$ that is a subsequence of $$$a_1,\ldots,a_n$$$, and also a subsequence of $$$b_1,\ldots,b_m$$$. If there are multiple answers, find one of the smallest possible length. If there ... | int solution() {
int tc;
scanf("%d", &tc);
while (tc--) {
int a;
int b;
scanf("%d %d", &a, &b);
int input1[a];
int input2[b];
int ctr1[1005] = {0};
int ctr2[1005] = {0};
for (int i = 0; i < a; i++) {
scanf("%d", &input1[i]);
ctr1[input1[i]]++;
}
for (int i = 0; ... | fn solution() {
let stdin = std::io::stdin();
let mut line: String = String::new();
stdin.read_line(&mut line).unwrap();
let ntc: i32 = line.trim().parse().unwrap();
for _ in 0..ntc {
stdin.read_line(&mut line).unwrap();
line.clear();
stdin.read_line(&mut line).unwrap();
... | medium |
1337 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ ... | int solution() {
int N;
scanf("%d", &N);
while (N--) {
int n;
int m;
scanf("%d %d", &n, &m);
int a[n][m];
int goodness = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
scanf("%d", &a[i][j]);
if (a[i][j] > 4 ||
(a[i][j] == 4 && (i == 0 || i ... | fn solution() {
let stdin = io::stdin();
let mut lines = stdin.lock().lines();
let t: usize = lines.next().unwrap().unwrap().parse().unwrap();
for _ in 0..t {
let xs: Vec<usize> = lines
.next()
.unwrap()
.unwrap()
.split(' ')
.map(|x| x... | medium |
1338 | Shohag has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He can perform the following operation any number of times (possibly, zero): Select any positive integer $$$k$$$ (it can be different in different operations). Choose any position in the sequence (possibly the beginning or end of the sequence, or in between ... | int solution() {
int c = 0;
int d = 0;
int n;
int x = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &x);
int a[x + 1];
for (int j = 1; j < x + 1; j++) {
scanf("%d", &a[j]);
if (a[j] > j && (j + c < a[j])) {
d = a[j] - (j + c);
c = c + d;
}
}... | fn solution() {
let mut nn = String::new();
stdin().read_line(&mut nn).unwrap();
let mut n: u32 = nn.trim().parse().unwrap();
while n > 0 {
let mut _numberofe = String::new();
stdin().read_line(&mut _numberofe).unwrap();
let _numberofe: usize = _numberofe.trim().parse().unwrap();... | medium |
1339 | In an ICPC contest, balloons are distributed as follows: Whenever a team solves a problem, that team gets a balloon. The first team to solve a problem gets an additional balloon. A contest has 26 problems, labelled $$$\textsf{A}$$$, $$$\textsf{B}$$$, $$$\textsf{C}$$$, ..., $$$\textsf{Z}$$$. You are given the order ... | int solution(void) {
int test_cases = 0;
int problems = 0;
int index = 0;
int counting = 0;
int letter[26] = {0};
scanf("%d", &test_cases);
for (int i = 0; i < test_cases; i++) {
scanf("%d", &problems);
char ara[problems + 1];
scanf("%s", ara);
for (int j = 0; j < problems; j++) {
in... | fn solution() {
let mut input = String::new();
io::stdin().read_line(&mut input).expect("input err");
let t: i32 = input.trim().parse().expect("input is not i32");
for _ in 0..t {
input.clear();
io::stdin().read_line(&mut input).expect("input err");
let n: usize = input.trim().pa... | medium |
1340 | You are a given an array $$$a$$$ of length $$$n$$$. Find a subarray $$$a[l..r]$$$ with length at least $$$k$$$ with the largest median.A median in an array of length $$$n$$$ is an element which occupies position number $$$\lfloor \frac{n + 1}{2} \rfloor$$$ after we sort the elements in non-decreasing order. For example... | int solution() {
int n;
int k;
int l;
int r;
int median;
int min;
int max;
int *a;
int *b;
scanf("%d%d", &n, &k);
a = malloc(n * sizeof(int));
b = malloc(n * sizeof(int));
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
l = 1;
r = n + 1;
while (l + 1 < r) {
median = (l +... | fn solution() -> std::io::Result<()> {
use std::io::Read;
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf)?;
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 (n, k) = ... | medium |
1341 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is a string <var>S</var>. Each character in <var>S</var> is either a digit (<code>0</code>, ..., <code>9</code>) or <code>?</code>.</p>
<p>Among the integers obtained by replacing each occurrence ... | int solution(void) {
char s[100001];
scanf("%s", s);
int s_len = strlen(s);
long reminder_divided_by_13[13] = {0};
reminder_divided_by_13[0] = 1;
const int mod = 1000000007;
long digit = 1;
for (int i = s_len - 1; i >= 0; i--) {
long next_reminder[13] = {0};
if (s[i] == '?') {
for (... | fn solution() {
let mut stdin = String::new();
std::io::Read::read_to_string(&mut std::io::stdin(), &mut stdin).unwrap();
let mut stdin = stdin.split_whitespace();
let mut get = || stdin.next().unwrap();
let s = get().as_bytes();
let mut dp = vec![0; 13];
let n = s.len();
if s[n - 1] ==... | easy |
1342 | <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> rectangular plate materials made of special metal called AtCoder Alloy.
The dimensions of the <var>i</var>-th material are <var>A_i \times B_i</var> (<var>A_i</var> vertically and... | int solution(void) {
int i = 0;
int n = 0;
int h = 0;
int w = 0;
int a = 0;
int b = 0;
int c = 0;
scanf("%d %d %d", &n, &h, &w);
for (i = 0; i < n; i++) {
scanf("%d %d", &a, &b);
if (a >= h && b >= w) {
c++;
}
}
printf("%d\n", c);
return 0;
} | fn solution() {
let mut buf = String::new();
let handle = std::io::stdin();
handle.read_line(&mut buf).unwrap();
let info: Vec<usize> = buf.split_whitespace().map(|a| a.parse().unwrap()).collect();
let (n, h, w) = (info[0], info[1], info[2]);
buf.clear();
let mut count = 0;
for _i in 0.... | easy |
1343 | You have an image file of size $$$2 \times 2$$$, consisting of $$$4$$$ pixels. Each pixel can have one of $$$26$$$ different colors, denoted by lowercase Latin letters.You want to recolor some of the pixels of the image so that all $$$4$$$ pixels have the same color. In one move, you can choose no more than two pixels ... | int solution() {
int numSets = 0;
scanf("%d", &numSets);
char image[4];
for (int currentSet = 0; currentSet < numSets; ++currentSet) {
getchar();
image[0] = getchar();
int numDifferentColors = 1;
image[1] = getchar();
getchar();
if (image[1] != image[0]) {
++numDifferentColors;... | fn solution() {
let stdin = std::io::stdin();
let mut s = String::new();
stdin.read_line(&mut s).unwrap();
let i: u32 = s.trim().parse().unwrap();
s.clear();
for _ in 0..i {
let mut h = HashSet::new();
for _ in 0..2 {
stdin.read_line(&mut s).unwrap();
}
... | hard |
1344 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Joisino is working as a receptionist at a theater.</p>
<p>The theater has <var>100000</var> seats, numbered from <var>1</var> to <var>100000</var>.</p>
<p>According to her memo, <var>N</var> groups of a... | int solution() {
int x = 0;
int i = 0;
int total = 0;
scanf("%d", &x);
for (i = 0; i < x; i++) {
int start = 0;
int end = 0;
scanf("%d %d", &start, &end);
total = total + (end - start + 1);
}
printf("%d\n", total);
return 0;
} | fn solution() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).ok();
let n: i32 = s.trim().parse().ok().unwrap();
let mut ans: i32 = 0;
for _i in 0..n {
let mut t = String::new();
std::io::stdin().read_line(&mut t).ok();
let v: Vec<i32> = t
.split_w... | medium |
1345 | You are given an array $$$a$$$ consisting of $$$n$$$ integers.You can remove at most one element from this array. Thus, the final length of the array is $$$n-1$$$ or $$$n$$$.Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array.Recall that the contig... | int solution() {
int n;
int flg = 0;
int max = 0;
scanf("%d", &n);
int arr[3][n];
if (n >= 1) {
scanf("%d", &arr[0][0]);
arr[1][0] = arr[2][0] = 1;
max = 1;
}
if (n >= 2) {
scanf("%d", &arr[0][1]);
if (arr[0][1] > arr[0][0]) {
arr[1][1] = arr[2][1] = 2;
max = 2;
} els... | fn solution() {
let mut str = String::new();
let _b1 = stdin().read_line(&mut str).unwrap();
let n: usize = str.trim().parse().unwrap();
str.clear();
let _b1 = stdin().read_line(&mut str).unwrap();
let mut iter = str.split_whitespace();
let mut arr: Vec<i64> = Vec::new();
loop {
... | medium |
1346 | You are given two integers $$$n$$$ and $$$k$$$. Your task is to find if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers or not.You have to answer $$$t$$$ independent test cases. | int solution() {
int tc;
scanf("%d", &tc);
while (tc--) {
long long int n;
long long int k;
scanf("%lld %lld", &n, &k);
if (k * k <= n && n % 2 == 0) {
if (k % 2 == 0) {
printf("YES\n");
} else {
printf("NO\n");
}
} else if (k * k <= n && n % 2 != 0) {
... | fn solution() {
let mut buf = String::new();
let t = {
stdin().read_line(&mut buf).unwrap();
buf.trim().parse::<i64>().unwrap()
};
for _ in 0..t {
buf.clear();
stdin().read_line(&mut buf).unwrap();
let line: Vec<i64> = buf
.split_whitespace()
... | medium |
1347 | <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> rabbits, numbered <var>1</var> through <var>N</var>.</p>
<p>The <var>i</var>-th (<var>1≤i≤N</var>) rabbit likes rabbit <var>a_i</var>.
Note that no rabbit can like itself, that is... | int solution(void) {
int N;
scanf("%d", &N);
int a[100000];
for (int i = 0; i < N; i++) {
scanf("%d", &a[i]);
}
int pairs = 0;
for (int i = 0; i < N; i++) {
if (a[a[i] - 1] == i + 1) {
pairs++;
}
}
pairs = pairs / 2;
printf("%d", pairs);
return 0;
} | fn solution() {
let mut s = String::new();
io::stdin().read_line(&mut s).ok();
let mut s = String::new();
io::stdin().read_line(&mut s).ok();
let xs: Vec<usize> = s.trim().split(' ').map(|x| x.parse().unwrap()).collect();
let mut res = 0;
for (i, &x) in xs.iter().enumerate() {
if ... | medium |
1348 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In this problem, we use the <var>24</var>-hour clock.</p>
<p>Takahashi gets up exactly at the time <var>H_1</var> : <var>M_1</var> and goes to bed exactly at the time <var>H_2</var> : <var>M_2</var>. (S... | int solution() {
int H1 = 0;
int M1 = 0;
int H2 = 0;
int M2 = 0;
int K = 0;
int T = 0;
scanf("%d %d %d %d %d", &H1, &M1, &H2, &M2, &K);
T = (60 * H2 + M2 - K) - (60 * H1 + M1);
printf("%d", T);
return 0;
} | fn solution() {
let mut is = String::new();
stdin().read_line(&mut is).ok();
let mut itr = is.split_whitespace().map(|e| e.parse().unwrap());
let h1: usize = itr.next().unwrap();
let m1: usize = itr.next().unwrap();
let h2: usize = itr.next().unwrap();
let m2: usize = itr.next().unwrap();
... | easy |
1349 | Xenia the beginner programmer has a sequence a, consisting of 2n non-negative integers: a1, a2, ..., a2n. Xenia is currently studying bit operations. To better understand how they work, Xenia decided to calculate some value v for a.Namely, it takes several iterations to calculate value v. At the first iteration, Xenia ... | int solution() {
double n;
int m;
int i;
int j;
int f = 0;
int x;
int p;
int b;
scanf("%lf %d", &n, &m);
x = (int)pow(2, n);
int tree[2 * x];
for (i = x; i < 2 * x; i++) {
scanf("%d", &tree[i]);
}
for (i = x, f = 0; i > 1; i = i / 2) {
for (j = i; j < 2 * i; j = j + 2) {
if (f ... | fn solution() {
let mut s = String::new();
let cin = stdin();
cin.read_line(&mut s).unwrap();
let p = s
.split_whitespace()
.map(|x| x.parse::<u32>().unwrap())
.collect::<Vec<_>>();
let m = p[1];
s.clear();
cin.read_line(&mut s).unwrap();
let a = s
.spli... | medium |
1350 | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.Rules of the game are very simple: at first number of rounds n is defined. In ... | int solution()
{
int n = 0;
scanf("%d", &n);
int m[100];
int c[100];
int a = 0;
int b = 0;
int i = 1;
for (i = 1; i <= n; i++) {
scanf("%d %d", &m[i], &c[i]);
if (m[i] > c[i] && m[i] != c[i]) {
a++;
}
if (m[i] < c[i] && m[i] != c[i]) {
b++;
}
}
if (a > b) {
pri... | fn solution() {
let mut n = String::new();
io::stdin().read_line(&mut n).expect("read error");
let n: usize = n.trim().parse().expect("parse error");
let mut score: isize = 0;
for _i in 0..n {
let mut t = String::new();
io::stdin().read_line(&mut t).expect("read error");
... | easy |
1351 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>The postal code in Atcoder Kingdom is <var>A+B+1</var> characters long, its <var>(A+1)</var>-th character is a hyphen <code>-</code>, and the other characters are digits from <code>0</code> through <cod... | int solution() {
int A;
int B;
int ans = 1;
scanf("%d%d", &A, &B);
char S[A + B + 2];
for (int i = 0; i < A + B + 2; i++) {
scanf("%c", &S[i]);
}
for (int i = 1; i < A + B + 2; i++) {
if ((i < A) && !(S[i] >= 48 && S[i] <= 57)) {
ans = 0;
break;
}
if (i == A + 1 && !(S[A +... | fn solution() {
let mut ab = String::new();
io::stdin().read_line(&mut ab).expect("error");
let vec: Vec<_> = ab.split_whitespace().collect();
let a: usize = vec[0].parse().unwrap();
let b: usize = vec[1].parse().unwrap();
let mut s = String::new();
io::stdin().read_line(&mut s).expect("err... | medium |
1352 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes:</p>
<ul>
<li>Red boxes, each containing <var>R</var> red balls</li>
<li>Green boxes, each... | int solution(void) {
int r[3];
int n;
scanf("%d%d%d%d", &r[0], &r[1], &r[2], &n);
int i;
int dp[n + 1];
for (i = 0; i < n + 1; i++) {
dp[i] = 0;
}
dp[0] = 1;
int j;
for (i = 0; i < 3; i++) {
for (j = r[i]; j <= n; j++) {
dp[j] = dp[j] + dp[j - r[i]];
}
}
printf("%d\n", dp[n])... | fn solution() {
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).unwrap();
let mut iter = buf.split_whitespace();
let r: i64 = iter.next().unwrap().parse().unwrap();
let g: i64 = iter.next().unwrap().parse().unwrap();
let b: i64 = iter.next().unwrap().parse().unwrap();... | hard |
1353 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an integer sequence of length <var>N</var>, <var>a_1,a_2,...,a_N</var>.</p>
<p>For each <var>1≤i≤N</var>, you have three choices: add <var>1</var> to <var>a_i</var>, subtract <var>1</var> ... | int solution() {
int n = 0;
scanf("%d\n", &n);
int *a = (int *)calloc(100001, sizeof(int));
int buf = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &buf);
if (buf > 0) {
a[buf - 1]++;
a[buf]++;
a[buf + 1]++;
} else {
a[buf]++;
a[buf + 1]++;
}
}
int max = 0;
f... | fn solution() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
let a: Vec<usize> = s.split_whitespace().map(|x| x.parse().unwrap()).collect();
let mut h: HashMap<usize, usize> = HashMap::new();
... | medium |
1354 | A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$.... | int solution(void) {
int t = 0;
scanf("%d", &t);
while (t--) {
int n = 0;
int x = 0;
scanf("%d", &n);
int arr[51] = {0};
for (int i = 0; i < n * 2; i++) {
scanf("%d", &x);
if (arr[x] == 0) {
arr[x] += 1;
printf("%d ", x);
}
}
printf("\n");
}
... | fn solution() {
let t: usize = {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
buf.trim_end().parse().unwrap()
};
for _ in 0..t {
let n: usize = {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap()... | hard |
1355 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Let <var>{\rm comb}(n,r)</var> be the number of ways to choose <var>r</var> objects from among <var>n</var> objects, disregarding order.
From <var>n</var> non-negative integers <var>a_1, a_2, ..., a_n</... | int solution(void) {
int i = 0;
int j = 0;
int n;
scanf("%d", &n);
int t[100000];
int max = 0;
int scn = 0;
for (; i < n; i++) {
scanf("%d", &t[i]);
if (t[i] > max) {
max = t[i];
}
}
for (; j < n; j++) {
if (abs(t[j] - (max / 2)) < abs(scn - (max / 2))) {
scn = t[j];
... | 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 a: Vec<i64> = (0..n)
.map(|_| itr.next().unwrap().parse().unwrap())
.collect();
a.sor... | medium |
1356 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>For an integer <var>n</var> not less than <var>0</var>, let us define <var>f(n)</var> as follows:</p>
<ul>
<li><var>f(n) = 1</var> (if <var>n < 2</var>)</li>
<li><var>f(n) = n f(n-2)</var> (if <var>n... | int solution(void) {
long long int n = 0;
long long int ans = 0;
long long int count = 1;
scanf("%lld", &n);
if (n % 2 != 0) {
printf("0\n");
} else {
int under = 10;
while (1) {
if (under * count > n) {
break;
}
ans += n / (under * count);
count *= 5;
}
... | fn solution() {
let n: u64 = {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
s.trim_end().parse().unwrap()
};
println!("{}", {
let mut ans: u64 = 0;
let mut t: u64 = 10;
while n >= t {
ans += n / t;
t *= 5;
... | easy |
1357 | Alice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one).Players take turns, Alice is first. Each player during his or her turn has to move the chip 1, 2 or k cells to the left (so, if the chip... | int solution() {
int t;
int n;
int k;
scanf("%d", &t);
while (t > 0) {
t--;
scanf("%d %d", &n, &k);
if (n < k) {
if (n % 3) {
printf("Alice\n");
} else {
printf("Bob\n");
}
} else {
if (k % 3 == 0) {
n %= k + 1;
if (n == k || n % 3) {
... | fn solution() {
let mut s = String::new();
stdin()
.read_line(&mut s)
.expect("Did not enter a correct string");
if let Some('\n') = s.chars().next_back() {
s.pop();
}
if let Some('\r') = s.chars().next_back() {
s.pop();
}
let mut i = s.parse::<i32>().unwrap()... | easy |
1358 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>The window of Takahashi's room has a width of <var>A</var>. There are two curtains hung over the window, each of which has a horizontal length of <var>B</var>. (Vertically, the curtains are long enough ... | int solution(void) {
int a = 0;
int b = 0;
scanf("%d %d", &a, &b);
if (a - 2 * b > 0) {
printf("%d", a - (2 * b));
} else {
printf("0");
}
} | fn solution() {
let mut buf = String::new();
io::stdin().read_line(&mut buf).ok();
let mut nums = buf.split_whitespace().map(|n| i32::from_str(n).unwrap());
let (A, B) = (nums.next().unwrap(), nums.next().unwrap());
let ans = A - 2 * B;
println!("{}", i32::max(0, ans));
} | medium |
1359 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Find the largest square number not exceeding <var>N</var>. Here, a <em>square number</em> is an integer that can be represented as the square of an integer.</p>
</section>
</div>
<div class="part">
<sec... | int solution(void) {
int n = 0;
int a = 0;
scanf("%d", &n);
a = sqrt(n);
n = a * a;
printf("%d\n", n);
} | fn solution() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).ok();
let n: i32 = s.trim().parse().ok().unwrap();
let mut k = 0;
let mut ans = 1;
while k * k <= n {
ans = k * k;
k += 1;
}
println!("{}", ans);
} | medium |
1360 | Polycarp is sad — New Year is coming in few days but there is still no snow in his city. To bring himself New Year mood, he decided to decorate his house with some garlands.The local store introduced a new service this year, called "Build your own garland". So you can buy some red, green and blue lamps, provide them an... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int a[3];
for (int i = 0; i <= 2; i++) {
scanf("%d", &a[i]);
}
if ((a[0] + a[1] + 1) >= a[2] && (a[1] + a[2] + 1) >= a[0] &&
(a[0] + a[2] + 1) >= a[1]) {
printf("Yes\n");
} else {
printf("No\n");
}
}
retur... | fn solution() {
outset! { buf }
input! {
t: usize,
rgb: [(usize, usize, usize); t],
}
for x in rgb.iter() {
let mut v = [x.0, x.1, x.2];
v.sort();
if v[2] - 1 <= v[0] + v[1] {
output!(buf, "Yes\n");
} else {
output!(buf, "No\n");
... | medium |
1361 | <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> squares arranged in a row from left to right. The height of the <var>i</var>-th square from the left is <var>H_i</var>.</p>
<p>For each square, you will perform either of the foll... | int solution() {
int n;
scanf("%d", &n);
long long h[n + 1];
h[0] = 0;
for (int i = 1; i <= n; i++) {
scanf("%lld", &h[i]);
}
int flg = 0;
for (int i = 1; i < n; i++) {
if (h[i - 1] <= h[i] && h[i] <= h[i + 1]) {
if (h[i - 1] < h[i] && h[i] == h[i + 1]) {
h[i]--;
}
} el... | fn solution() {
let stdin = std::io::stdin();
let mut buf = String::new();
stdin.read_line(&mut buf).ok();
let _n: i32 = buf.trim().parse().unwrap();
buf.clear();
stdin.read_line(&mut buf).ok();
let hs: Vec<i32> = buf.split_whitespace().map(|w| w.parse().unwrap()).collect();
let mut l... | medium |
1362 | <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> locked treasure boxes, numbered <var>1</var> to <var>N</var>.</p>
<p>A shop sells <var>M</var> keys. The <var>i</var>-th key is sold for <var>a_i</var> yen (the currency of Japan), ... | int solution(void) {
int n;
int m;
int i;
int j;
int tmp;
int big = 1000000;
scanf("%d %d", &n, &m);
int com = pow(2, n);
int a[m];
int b[m];
int c[m][12];
int dp[com];
for (i = 0; i < com; i++) {
dp[i] = big;
}
for (i = 0; i < m; i++) {
scanf("%d %d", &a[i], &b[i]);
for (j = ... | fn solution() {
let (n, m) = {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
let mut it = buf.split_whitespace();
let n: u32 = it.next().unwrap().parse().unwrap();
let m: usize = it.next().unwrap().parse().unwrap();
(n, m)
};
let ... | medium |
1363 | You are given an array $$$a$$$ consisting of $$$n$$$ integer numbers.You have to color this array in $$$k$$$ colors in such a way that: Each element of the array should be colored in some color; For each $$$i$$$ from $$$1$$$ to $$$k$$$ there should be at least one element colored in the $$$i$$$-th color in the array... | int solution() {
int n;
int k;
scanf("%d%d", &n, &k);
int a[n];
int cnt = 0;
int hash[10000] = {0};
int max = 0;
int color[10000] = {0};
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
hash[a[i]]++;
if (hash[a[i]] > max) {
max = hash[a[i]];
}
}
int q = 1;
int temp = 1;
... | fn solution() {
let (_n, k): (usize, usize) = {
let mut read_buf = String::new();
io::stdin().read_line(&mut read_buf).unwrap();
let mut read_buf = read_buf.split_whitespace();
(
read_buf.next().unwrap().parse().unwrap(),
read_buf.next().unwrap().parse().unwra... | medium |
1364 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> people standing on the <var>x</var>-axis.
Let the coordinate of Person <var>i</var> be <var>x_i</var>.
For every <var>i</var>, <var>x_i</var> is an integer between <var>0</var> an... | int solution() {
int i;
int u;
int w;
int D;
int N;
int M;
scanf("%d %d", &N, &M);
list **adj = (list **)malloc(sizeof(list *) * (N + 1));
list *d = (list *)malloc(sizeof(list) * M * 2);
for (i = 0; i < M; i++) {
scanf("%d %d %d", &u, &w, &D);
d[i * 2].v = w;
d[(i * 2) + 1].v = u;
d[... | fn solution() {
let mut s: String = String::new();
stdin().read_to_string(&mut s).ok();
let mut itr = s.split_whitespace();
let n: usize = itr.next().unwrap().parse().unwrap();
let m: usize = itr.next().unwrap().parse().unwrap();
let mut g = vec![Vec::new(); n];
for _ in 0..m {
let ... | hard |
1365 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is an image with a height of <var>H</var> pixels and a width of <var>W</var> pixels. Each of the pixels is represented by either <code>.</code> or <code>*</code>. The character representing the pi... | int solution() {
int H;
int W = 0;
scanf("%d %d", &H, &W);
char C[2 * H][W];
for (int i = 0; i < H; i++) {
scanf("%s", C[i]);
printf("%s\n", C[i]);
printf("%s\n", C[i]);
}
return 0;
} | 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();
for _ in 0..v[0] {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
println!("{}\n{}", s.... | hard |
1366 | <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>Breadth First Search</H1>
<... | int solution() {
int n;
scanf("%d", &n);
int g[102][102];
int d[102];
int i;
int j;
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
g[i][j] = 0;
}
d[i] = -1;
}
int u;
int k;
for (i = 0; i < n; i++) {
scanf("%d %d", &u, &k);
for (j = 0; j < k; j++) {
int v... | fn solution() {
let mut buf = String::new();
let _ = std::io::stdin().read_line(&mut buf).ok();
let n: usize = buf.trim().parse().unwrap();
let mut g = Vec::new();
for _ in 0..n {
let mut buf = String::new();
let _ = std::io::stdin().read_line(&mut buf).ok();
let mut buf = bu... | medium |
1367 | A flower shop has got n bouquets, and the i-th bouquet consists of ai flowers. Vasya, the manager of the shop, decided to make large bouquets from these bouquets. Vasya thinks that a bouquet is large if it is made of two or more initial bouquets, and there is a constraint: the total number of flowers in a large bouquet... | int solution() {
int count = 0;
scanf("%d", &count);
int inp = 0;
int first = 0;
int second = 0;
for (int i = 0; i < count; i++) {
scanf("%d", &inp);
if (inp % 2) {
first++;
} else {
second++;
}
}
int answer = 0;
if (first > second) {
answer = second + (first - second) ... | fn solution() {
let mut n = String::new();
std::io::stdin()
.read_line(&mut n)
.expect("Reading n error!");
let n: u32 = n.trim().parse().expect("Error while parsing!");
let mut arr = String::new();
std::io::stdin()
.read_line(&mut arr)
.expect("Reading arr error!"... | medium |
1368 | Polycarp has recently got himself a new job. He now earns so much that his old wallet can't even store all the money he has.Berland bills somehow come in lots of different sizes. However, all of them are shaped as rectangles (possibly squares). All wallets are also produced in form of rectangles (possibly squares).A bi... | int solution() {
int n;
scanf("%d", &n);
int max_x = -1;
int max_y = -1;
while (n--) {
char c = getchar();
int a;
int b;
scanf("%c %d %d", &c, &a, &b);
int temp = a < b ? a : b;
b = a > b ? a : b;
a = temp;
if (c == '+') {
if (a > max_x) {
max_x = a;
}
... | fn solution() -> io::Result<()> {
let mut input = String::new();
io::stdin().read_to_string(&mut input)?;
let mut output = String::with_capacity(input.len());
let mut tokens = input.split_whitespace();
let _ = tokens.next().unwrap().parse::<usize>().unwrap();
let mut max_min = 0;
let mut... | easy |
1369 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Two students of AtCoder Kindergarten are fighting over candy packs.</p>
<p>There are three candy packs, each of which contains <var>a</var>, <var>b</var>, and <var>c</var> candies, respectively.</p>
<p>... | int solution() {
int a = 0;
int b = 0;
int c = 0;
scanf("%d %d %d", &a, &b, &c);
if (a + b == c || a + c == b || b + c == a) {
printf("Yes\n");
} else {
printf("No\n");
}
return 0;
} | fn solution() {
let mut s = String::new();
io::stdin().read_line(&mut s).ok();
let mut xs: Vec<u64> = s.trim().split(' ').map(|x| x.parse().unwrap()).collect();
xs.sort();
println!("{}", if xs[0] + xs[1] == xs[2] { "Yes" } else { "No" });
} | medium |
1370 | Comb sort | void solution(int *numbers, int size) {
const SHRINK = 1.3 int gap = size;
while (gap > 1) {
gap = gap / SHRINK;
int i = 0;
while ((i + gap) < size) {
if (numbers[i] > numbers[i + gap]) {
int tmp = numbers[i];
numbers[i] = numbers[i + gap];
numbers[i + gap] = tmp;
}
... | fn solution<T: Ord>(arr: &mut [T]) {
let mut gap = arr.len();
let shrink = 1.3;
let mut sorted = false;
while !sorted {
gap = (gap as f32 / shrink).floor() as usize;
if gap <= 1 {
gap = 1;
sorted = true;
}
for i in 0..arr.len() - gap {
... | medium |
1371 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is a sequence of <var>N</var> integers <var>A_1, \ldots, A_N</var>.</p>
<p>Find the (multiplicative) inverse of the sum of the inverses of these numbers, <var>\frac{1}{\frac{1}{A_1} + \ldots + \fr... | int solution() {
int num = 0;
int i = 0;
double sum = 0.0;
double ans = 0.0;
scanf("%d", &num);
int yoshio[num];
for (i = 0; i < num; i++) {
scanf("%d", &yoshio[i]);
sum += 1 / (double)yoshio[i];
}
ans = 1 / sum;
printf("%lf\n", ans);
return 0;
} | fn solution() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).ok();
let vec_str: Vec<String> = s.split_whitespace().map(|x| x.to_string()).collect();
let _N = vec_str[0].parse::<i32>().unwrap();
let mut s = String::new();
std::io::stdin().read_line(&mut s).ok();
let vec_str:... | hard |
1372 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You've come to your favorite store Infinitesco to buy some ice tea.</p>
<p>The store sells ice tea in bottles of different volumes at different costs.
Specifically, a <var>0.25</var>-liter bottle costs ... | int solution(void) {
long long int q;
long long int h;
long long int s;
long long int d;
long long int n;
scanf("%lld %lld %lld %lld", &q, &h, &s, &d);
scanf("%lld", &n);
long long int cost = 0;
long long int count = 0;
if (q * 8 < h * 4 && q * 8 < s * 2 && q * 8 < d) {
count = n / 0.25;
n -... | fn solution() {
let (Q, H, S, D): (i64, i64, i64, i64) = {
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().unwra... | easy |
1373 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In this problem, we only consider strings consisting of lowercase English letters.</p>
<p>Strings <var>s</var> and <var>t</var> are said to be <strong>isomorphic</strong> when the following conditions a... | int solution(void) {
int n;
scanf("%d", &n);
int generate[n];
for (int i = 0; i < n; i++) {
generate[i] = 0;
}
int max[n];
while (1) {
for (int i = 0; i < n; i++) {
max[0] = 0;
if (i != 0 && generate[i] > max[i - 1]) {
max[i] = generate[i];
} else {
max[i] = max[... | fn solution() {
input! {
n: usize,
};
let mut s = vec![0; n];
loop {
for c in s.iter() {
print!("{}", (*c + b'a') as char);
}
println!();
let mut change = false;
for i in (1..n).rev() {
if s[i] == s[..i].iter().max().unwrap() + 1 {
... | medium |
1374 | Pigeonhole sort | void solution(int arr[], int size) {
int i, j, min = arr[0], max = arr[0], range;
for (i = 1; i < size; i++) {
if (arr[i] < min)
min = arr[i];
if (arr[i] > max)
max = arr[i];
}
range = max - min + 1;
int *holes = (int *)malloc(sizeof(int) * range);
for (i = 0; i < range; i++) {
hol... | fn solution(array: &mut [i32]) {
if let (Some(min), Some(max)) = (array.iter().min(), array.iter().max()) {
let holes_range: usize = (max - min + 1) as usize;
let mut holes = vec![0; holes_range];
let mut holes_repeat = vec![0; holes_range];
for i in array.iter() {
let in... | easy |
1375 | <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> people. The name of the <var>i</var>-th person is <var>S_i</var>.</p>
<p>We would like to choose three people so that the following conditions are met:</p>
<ul>
<li>The name of ev... | int solution(void) {
int num;
long long int m = 0;
long long int a = 0;
long long int r = 0;
long long int c = 0;
long long int h = 0;
long long int ans = 0;
long long int mix[10];
char name[100000][11];
scanf("%d", &num);
for (int i = 0; i < num; i++) {
scanf("%s", name[i]);
switch (nam... | fn solution() {
let mut buf: String = String::new();
io::stdin().read_line(&mut buf).unwrap();
let n = buf.trim().parse::<usize>().unwrap();
let mut map: HashMap<char, i64> = HashMap::new();
for _ in 0..n {
let mut buf = String::new();
io::stdin().read_line(&mut buf).unwrap();
... | medium |
1376 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a circular pond with a perimeter of <var>K</var> meters, and <var>N</var> houses around them.</p>
<p>The <var>i</var>-th house is built at a distance of <var>A_i</var> meters from the northmost... | int solution(void) {
int K = 0;
int N = 0;
int max = 0;
scanf("%d %d", &K, &N);
int A[N];
int distance[N];
for (int i = 0; i < N; i++) {
scanf("%d", &A[i]);
if (i > 0) {
distance[i] = A[i] - A[i - 1];
}
if (distance[i] > max) {
max = distance[i];
}
}
distance[0] = ... | fn solution() {
let mut s = String::new();
let mut s2 = String::new();
io::stdin().read_line(&mut s).unwrap();
let s_spl: Vec<&str> = s.trim().split(' ').collect();
let k: i32 = s_spl[0].to_string().parse().unwrap();
let mut max = -1;
let mut a_first = -1;
let mut a_old = -1;
io::std... | medium |
1377 | One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered fr... | int solution(void) {
int n = 0;
int m = 0;
int count = 0;
int floors[100][200] = {{0}};
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m * 2; j++) {
scanf("%d", floors[i] + j);
if (j % 2 && floors[i][j - 1] + floors[i][j]) {
count++;
}
}
}
... | fn solution() {
let mut input = String::new();
std::io::stdin()
.read_to_string(&mut input)
.expect("input: read to string failed");
let vec = input
.lines()
.map(|line| line.split_whitespace())
.map(|item| {
item.map(|item| item.parse::<i32>().unwrap())
... | medium |
1378 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a string <var>S</var> consisting of lowercase English letters.
Another string <var>T</var> is initially empty.
Determine whether it is possible to obtain <var>S = T</var> by performing the... | int solution() {
char s[100050];
char temp[10];
scanf("%s", s);
int i = 0;
int end = strlen(s);
int isPosible = 1;
while (isPosible) {
if (i == end) {
break;
}
strncpy(temp, s + i, 5);
i += 5;
if (strcmp(temp, "dream") != 0 && strcmp(temp, "erase") != 0) {
isPosible = 0;
... | fn solution() {
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).ok();
let s = buf.trim();
let n = s.len();
let mut g = vec![Vec::new(); n];
let mut reach = vec![0; n + 1];
reach[0] = 1;
for &t in &["dream", "dreamer", "erase", "eraser"] {
for p in s.match_i... | medium |
1379 | Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab.After two hours of playing the game Vova has tracked the monster and analyzed its tactics. The Modcrab has h2 health points and an attack power of a2. Knowing that, Vova has d... | int solution() {
int map[10005];
int sum = 0;
int h1;
int a1;
int c1;
int h2;
int a2;
scanf("%d %d %d %d %d", &h1, &a1, &c1, &h2, &a2);
for (int i = 0;; i++) {
if (h1 > a2 && h2 > a1) {
map[sum] = 1;
h1 = h1 - a2;
h2 = h2 - a1;
sum++;
continue;
}
if (h1 <= a2... | 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()
.map(|x| x.parse::<usize>().unwrap());
let (mut h1, a1, c1, mut h2, a2) = (
it.next().unwrap(),
it.nex... | easy |
1380 | You talked to Polycarp and asked him a question. You know that when he wants to answer "yes", he repeats Yes many times in a row.Because of the noise, you only heard part of the answer — some substring of it. That is, if he answered YesYes, then you could hear esY, YesYes, sYes, e, but you couldn't Yess, YES or se.Dete... | int solution() {
int t = 0;
scanf("%d", &t);
int i = 0;
char s1[53] = "YesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesY";
char s2[1000][51] = {0};
char s3[1000][4] = {0};
for (i = 0; i < t; i++) {
scanf("%s", s2[i]);
if (strstr(s1, s2[i]) != NULL) {
strcpy(s3[i], "YES");
} else {
... | fn solution() {
let srch = "YesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYes";
let mut buf = BufWriter::new(io::stdout().lock());
io::stdin().lines().skip(1).flatten().for_each(|s| {
let ans = if sr... | medium |
1381 | Igor is in 11th grade. Tomorrow he will have to write an informatics test by the strictest teacher in the school, Pavel Denisovich. Igor knows how the test will be conducted: first of all, the teacher will give each student two positive integers $$$a$$$ and $$$b$$$ ($$$a < b$$$). After that, the student can apply an... | int solution() {
int t;
int a;
int b;
scanf("%d", &t);
while (t--) {
scanf("%d %d", &a, &b);
int a1 = 0;
int b1 = 1;
int a0 = a;
int b0 = b;
while ((a0 | b) != b) {
a1++;
a0++;
}
if (a0 != b) {
a1++;
}
while ((a | b0) != b0) {
b1++;
b0++;
... | fn solution() {
let stdin = io::stdin();
let mut lines = stdin.lock().lines();
let t: usize = lines.next().unwrap().unwrap().parse().unwrap();
for _ in 0..t {
let xs: Vec<usize> = lines
.next()
.unwrap()
.unwrap()
.split(' ')
.map(|x| x... | easy |
1382 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Print all the integers that satisfies the following in ascending order:</p>
<ul>
<li>Among the integers between <var>A</var> and <var>B</var> (inclusive), it is either within the <var>K</var> smallest i... | int solution(void) {
static int a;
static int b;
static int k;
scanf("%d%d%d", &a, &b, &k);
if (a + k - 1 < b - k + 1) {
for (int i = 0; i < k; i++) {
printf("%d\n", a + i);
}
for (int i = 0; i < k; i++) {
printf("%d\n", b - k + i + 1);
}
} else {
for (int i = a; i <=... | fn solution() {
let mut buff = String::new();
std::io::stdin().read_to_string(&mut buff).unwrap();
let mut iter = buff.split_whitespace();
let a: i32 = iter.next().unwrap().parse().unwrap();
let b: i32 = iter.next().unwrap().parse().unwrap();
let k: i32 = iter.next().unwrap().parse().unwrap();
... | easy |
1383 | <h1>椅子の総数</h1>
<p>
選手のみなさん、パソコン甲子園にようこそ。パソコン甲子園の本選は会津大学で行われ、会場内では
1つの机に1チームが割り当てられます。パソコン甲子園は1チーム2人なので、チーム数×2脚の椅子が必要です。大学では、他にも様々なイベントの会場設営で机と椅子を準備する機会がありますが、必要な机と椅子の数も様々です。そこで、あるイベントに対して準備する机の数と、机1つあたりに必要な椅子の数が与えられたとき、必要な椅子の総数を計算するプログラムを作成してください。
</p>
<h2>入力</h2>
<p>
入力は以下の形式で与えられる。
</p>
<pre>
<var>d</var> <var>c</v... | int solution() {
int d = 0;
int c = 0;
scanf("%d%d", &d, &c);
printf("%d\n", d * c);
return 0;
} | fn solution() {
let input = {
let mut buf = vec![];
stdin().read_to_end(&mut buf);
unsafe { String::from_utf8_unchecked(buf) }
};
let (d, c) = {
let mut iter = input.split_whitespace().map(|s| s.parse::<u32>().unwrap());
(iter.next().unwrap(), iter.next().unwrap())
... | easy |
1384 | You are given a long decimal number $$$a$$$ consisting of $$$n$$$ digits from $$$1$$$ to $$$9$$$. You also have a function $$$f$$$ that maps every digit from $$$1$$$ to $$$9$$$ to some (possibly the same) digit from $$$1$$$ to $$$9$$$.You can perform the following operation no more than once: choose a non-empty contigu... | int solution() {
int x;
char str[200007];
int n[11];
scanf("%d", &x);
scanf("%s", str);
for (int i = 0; i < 9; i++) {
scanf("%d", &n[i + 1]);
}
int flag = 0;
for (int i = 0; i < x; i++) {
if ((flag && str[i] - '0' <= n[str[i] - '0']) ||
(!flag && str[i] - '0' < n[str[i] - '0'])) {
... | 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 mut a = buffer
.trim()
.char... | hard |
1385 | There are three sticks with integer lengths $$$l_1, l_2$$$ and $$$l_3$$$.You are asked to break exactly one of them into two pieces in such a way that: both pieces have positive (strictly greater than $$$0$$$) integer length; the total length of the pieces is equal to the original length of the stick; it's possible... | int solution()
{
int t;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
int aa[3];
for (int j = 0; j < 3; j++) {
scanf("%d", &aa[j]);
}
if ((aa[0] != aa[1]) && (aa[0] != aa[2]) && (aa[1] != aa[2])) {
int max = -22;
for (int j = 0; j < 3; j++) {
if (aa[j] >= max) {
... | fn solution() {
let mut t = String::new();
io::stdin().read_line(&mut t).expect("read t");
let t: i32 = t.trim().parse().expect("parse t");
for _ in 0..t {
let mut l = String::new();
io::stdin().read_line(&mut l).expect("read l");
let l: Result<Vec<i32>, _> = l.trim().split(' ')... | medium |
1386 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>In Dwango Co., Ltd., there is a content distribution system named 'Dwango Media Cluster', and it is called 'DMC' for short.<br/>
The name 'DMC' sounds cool for Niwango-kun, so he starts to define DMC-n... | int solution() {
int l = 1000010;
int n;
int q;
int d[l];
long long m[l];
long long c[l];
long long x[l];
char s[l];
for (int i = 0; i < l; i++) {
d[i] = -1;
}
scanf("%d%s%d", &n, s, &q);
int j = 0;
for (int i = 1; i <= n; i++) {
m[i] = m[i - 1];
c[i] = c[i - 1];
x[i] = x[i - 1... | fn solution() {
let mut s = String::new();
use std::io::{Read, Write};
std::io::stdin().read_to_string(&mut s).unwrap();
let mut it = s.split_whitespace();
let _n: usize = it.next().unwrap().parse().unwrap();
let s: Vec<_> = it.next().unwrap().chars().collect();
let _q: usize = it.next().unw... | medium |
1387 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Given is a string <var>S</var>. Replace every character in <var>S</var> with <code>x</code> and print the result.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>S... | int solution() {
char S[200];
int i = 0;
scanf("%s", S);
while (S[i] != '\0') {
if (S[i] >= 'a' && S[i] <= 'z') {
S[i] = 'x';
}
i++;
}
printf("%s\n", S);
return 0;
} | fn solution() {
let mut buf = String::new();
io::stdin().read_line(&mut buf).expect("");
buf = buf.trim().to_string();
for _n in 0..buf.len() {
print!("x");
}
println!();
} | hard |
1388 | In order to celebrate Twice's 5th anniversary, Tzuyu and Sana decided to play a game.Tzuyu gave Sana two integers $$$a$$$ and $$$b$$$ and a really important quest.In order to complete the quest, Sana has to output the smallest possible value of ($$$a \oplus x$$$) + ($$$b \oplus x$$$) for any given $$$x$$$, where $$$\op... | int solution() {
int t = 0;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
int a = 0;
int b = 0;
int x = 0;
scanf("%d %d", &a, &b);
if (a == b) {
printf("0\n");
} else {
x = a ^ b;
printf("%d\n", x);
}
}
} | fn solution() {
let mut input = "".split_ascii_whitespace();
let mut read = || loop {
if let Some(word) = input.next() {
break word;
}
input = {
let mut input = "".to_owned();
io::stdin().read_line(&mut input).unwrap();
if input.is_empty() ... | medium |
1389 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke lives on an infinite two-dimensional plane. He is going on an <var>N</var>-day trip.
At the beginning of Day <var>1</var>, he is at home. His plan is described in a string <var>S</var> of length <... | int solution() {
char s[1111];
scanf("%s", s);
char *N = strchr(s, 'N');
char *S = strchr(s, 'S');
char *E = strchr(s, 'E');
char *W = strchr(s, 'W');
int ans = 0;
if ((N != 0 && S != 0) || (N == 0 && S == 0)) {
if ((E != 0 && W != 0) || (E == 0 && W == 0)) {
ans = 1;
}
}
puts(ans ? "Y... | fn solution() {
let mut stdin = io::stdin();
let mut lines = String::new();
let _ = stdin.read_to_string(&mut lines);
let vec = lines.lines().collect::<Vec<&str>>();
let s = vec[0];
let mut ncnt = 0;
let mut scnt = 0;
let mut ecnt = 0;
let mut wcnt = 0;
for i in s.chars() {
... | easy |
1390 | <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> stones, numbered <var>1, 2, \ldots, N</var>.
For each <var>i</var> (<var>1 \leq i \leq N</var>), the height of Stone <var>i</var> is <var>h_i</var>.</p>
<p>There is a frog who is ... | int solution() {
int N;
scanf("%d", &N);
int h[N];
int dp[N];
for (int i = 1; i <= N; i++) {
scanf("%d", &h[i]);
}
dp[0] = 0;
for (int i = 1; i <= N - 1; i++) {
dp[i] = dp[i - 1] + abs(h[i] - h[i + 1]);
if (i > 1) {
if (dp[i] > (dp[i - 2] + abs(h[i - 1] - h[i + 1]))) {
dp[i] =... | fn solution() {
let mut s: String = String::new();
std::io::stdin().read_to_string(&mut s).ok();
let mut itr = s.split_whitespace();
let n: usize = itr.next().unwrap().parse().unwrap();
let a: Vec<i64> = (0..n)
.map(|_| itr.next().unwrap().parse().unwrap())
.collect();
let mut d... | medium |
1391 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is a string <var>S</var> consisting of <code>L</code> and <code>R</code>.</p>
<p>Let <var>N</var> be the length of <var>S</var>. There are <var>N</var> squares arranged from left to right, and the... | int solution() {
char a[100000];
scanf("%s", a);
int cnt = 0;
while (a[cnt] != '\0') {
cnt++;
}
int b[100000] = {0};
for (int i = 0; i < cnt; i++) {
if (a[i] == 'R' && a[i + 1] == 'L') {
b[i]++;
b[i + 1]++;
int temp1 = 1;
int temp2 = 2;
while (a[i - temp1] == 'R' && (... | fn solution() {
let stdin = io::stdin();
let mut stdin = stdin.lock();
let s = {
let mut input = String::new();
stdin.read_line(&mut input).unwrap();
input.trim().to_string()
};
let vec = {
let mut vec = Vec::with_capacity(100_000);
let mut state = 'R';
... | easy |
1392 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Does <var>\sqrt{a} + \sqrt{b} < \sqrt{c}</var> hold?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq a, b, c \leq 10^9</var></li>
<li>All values in input a... | int solution() {
long a;
long b;
long c;
scanf("%ld %ld %ld", &a, &b, &c);
if (!((a >= 1 && a <= 1000000000) && (b >= 1 && b <= 1000000000) &&
(c >= 1 && c <= 1000000000))) {
printf("No");
return (0);
}
if (c - a - b < 0) {
if (4 * (a * b) < (c - a - b) * (c - a - b) * (-1)) {
pr... | fn solution() {
let mut s: String = String::new();
std::io::stdin().read_to_string(&mut s).ok();
let mut itr = s.split_whitespace();
let a: i64 = itr.next().unwrap().parse().unwrap();
let b: i64 = itr.next().unwrap().parse().unwrap();
let c: i64 = itr.next().unwrap().parse().unwrap();
let x ... | easy |
1393 | Recently a new building with a new layout was constructed in Monocarp's hometown. According to this new layout, the building consists of three types of apartments: three-room, five-room, and seven-room apartments. It's also known that each room of each apartment has exactly one window. In other words, a three-room apar... | int solution() {
int t;
scanf("%d", &t);
for (int m = 0; m < t; m++) {
int n;
int flag = 1;
scanf("%d", &n);
for (int i = 0; 3 * i <= n && flag; i++) {
for (int j = 0; 3 * i + 5 * j <= n && flag; j++) {
for (int k = 0; 3 * i + 5 * j + 7 * k <= n && flag; k++) {
if (3 * i + ... | fn solution() {
let mut str = String::new();
let _ = stdin().read_line(&mut str).unwrap();
let test: i64 = str.trim().parse().unwrap();
for _ in 0..test {
str.clear();
let _ = stdin().read_line(&mut str).unwrap();
let n: i64 = str.trim().parse().unwrap();
if n == 3 {
... | medium |
1394 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In Takahashi Kingdom, there is an archipelago of <var>N</var> islands, called Takahashi Islands.
For convenience, we will call them Island <var>1</var>, Island <var>2</var>, ..., Island <var>N</var>.</p... | int solution() {
int n;
int m;
scanf("%d%d", &n, &m);
int a[m];
int b[m];
int f[200001] = {0};
int s[200001] = {0};
for (int i = 0; i < m; i++) {
scanf("%d%d", &a[i], &b[i]);
if (a[i] == 1) {
f[b[i]] = 1;
}
if (b[i] == n) {
s[a[i]] = 1;
}
}
for (int i = 1; i <= n; i++... | 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();
let mut x: Vec<usize> = Vec::new();
let mut y: HashSet<usize> = HashSet::new();
for _ in 0..v[1] {
let mut s = String::n... | medium |
1395 | You are fighting with Zmei Gorynich — a ferocious monster from Slavic myths, a huge dragon-like reptile with multiple heads! Initially Zmei Gorynich has $$$x$$$ heads. You can deal $$$n$$$ types of blows. If you deal a blow of the $$$i$$$-th type, you decrease the number of Gorynich's heads by $$$min(d_i, curX)$$$, t... | int solution() {
int t;
int n;
int x;
int d;
int h;
scanf("%d", &t);
while (t--) {
int D = 0;
int max = 0;
scanf("%d%d", &n, &x);
for (int i = 0; i < n; i++) {
scanf("%d%d", &d, &h);
if (d > max) {
max = d;
}
if (d - h > D) {
D = d - h;
}
}... | 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 t = get!();
for _ in 0..t {
let n = get!();
let x = get!();
le... | easy |
1396 | Igor the analyst has adopted n little bunnies. As we all know, bunnies love carrots. Thus, Igor has bought a carrot to be shared between his bunnies. Igor wants to treat all the bunnies equally, and thus he wants to cut the carrot into n pieces of equal area. Formally, the carrot can be viewed as an isosceles triangle ... | int solution() {
double n;
double h;
scanf("%lf%lf", &n, &h);
for (int i = 1; i < n; i++) {
printf("%.12lf\n", sqrt(i / n) * h);
}
return 0;
} | fn solution() {
let (n, h): (f64, f64) = {
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
let mut it = input.split_whitespace().map(|k| k.parse().unwrap());
(it.next().unwrap(), it.next().unwrap())
};
for k in 1..n as usize {
let ans = h *... | easy |
1397 | The string $$$t_1t_2 \dots t_k$$$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.Here are some e... | int solution() {
int n = 0;
int i = 0;
long long int ans = 0;
char current = 0;
char s[524228];
char stroka_answer[32];
int m[524228];
int M = 0;
scanf("%d", &n);
scanf("%s", s);
for (i = 0; i < n; i++) {
if (s[i] != current) {
current = s[i];
M++;
m[M - 1] = 1;
} else {
... | fn solution() {
let stdin = io::stdin();
let mut lines = stdin
.lock()
.lines()
.map(|l| l.expect("stdin line exhausted"));
let n: usize = lines.next().and_then(|s| s.parse().ok()).expect("read n");
let mut s: Vec<_> = lines.next().expect("read s").bytes().collect();
assert_... | hard |
1398 | <span class="lang-en">
<p>Score: <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Takahashi became a pastry chef and opened a shop <em>La Confiserie d'ABC</em> to celebrate AtCoder Beginner Contest 100.</p>
<p>The shop sells <var>N</var> kinds of cakes.<br/>
Each kind of cake has thr... | int solution() {
int n;
int m;
scanf("%d%d", &n, &m);
long x;
long y;
long z;
long a[8][n];
long sum[8];
long ans = 0;
for (int i = 0; i < 8; i++) {
sum[i] = 0;
}
for (int i = 0; i < n; i++) {
scanf("%ld%ld%ld", &x, &y, &z);
a[0][i] = x + y + z;
a[1][i] = x + y - z;
a[2][i] =... | fn solution() {
let mut count_line = String::new();
std::io::stdin().read_line(&mut count_line).ok();
let mut count_it = count_line.split_whitespace();
let line_count: u32 = count_it.next().unwrap().parse().unwrap();
let amount: u32 = count_it.next().unwrap().parse().unwrap();
let values: Vec<(i... | hard |
1399 | You are given three integers $$$a \le b \le c$$$.In one move, you can add $$$+1$$$ or $$$-1$$$ to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation several times with one number. Note that you can... | int solution() {
int n;
scanf("%d", &n);
while (n--) {
int res = 90009;
int a;
int b;
int c;
int aa;
int bb;
int cc;
scanf("%d %d %d", &a, &b, &c);
for (int i = 1; i <= 10100; i++) {
for (int j = 1; i * j <= 10100; j++) {
for (int k = 1; i * j * k <= 10100; k++) {... | fn solution() {
let stdin = io::stdin();
let mut lines = stdin.lock().lines().map(|l| l.unwrap());
let t: u64 = lines.next().unwrap().trim().parse().unwrap();
for _ in 0..t {
let line = lines.next().unwrap();
let mut parts = line.split_whitespace();
let a: i64 = parts.next().unwr... | medium |
1400 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Let <var>f(n)</var> be the number of triples of integers <var>(x,y,z)</var> that satisfy both of the following conditions:</p>
<ul>
<li><var>1 \leq x,y,z</var></li>
<li><var>x^2 + y^2 + z^2 + xy + yz + ... | int solution(void) {
int datanum = 0;
int x = 0;
int y = 0;
int z = 0;
int n = 0;
int i = 0;
int count = 0;
scanf("%d", &datanum);
for (i = 1; i <= datanum; i++) {
count = 0;
for (x = 1; x < 99; x++) {
for (y = 1; y < 99; y++) {
for (z = 1; z < 99; z++) {
n = (x * x) ... | 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 memo = vec![0; 10010];
let mut x = 1;
while x * x <= n {
let mut y = 1;
while y *... | easy |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.