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 |
|---|---|---|---|---|
1101 | You work in the quality control department of technical support for a large company. Your job is to make sure all client issues have been resolved.Today you need to check a copy of a dialog between a client and a technical support manager. According to the rules of work, each message of the client must be followed by o... | int solution() {
int testcases;
scanf("%d", &testcases);
int number_of_messages[testcases];
int result[testcases];
for (int i = 0; i < testcases; i++) {
scanf("%d", &number_of_messages[i]);
char array[number_of_messages[i] + 1];
scanf("%s", array);
result[i] = 0;
for (int j = 0; j <... | fn solution() -> io::Result<()> {
let mut t = String::new();
io::stdin().read_line(&mut t)?;
let t = t.trim().parse::<i64>().unwrap();
for _ in 0..t {
let mut n = String::new();
io::stdin().read_line(&mut n)?;
let mut str = String::new();
io::stdin().read_line(&mut str)?... | easy |
1102 | Sasha is taking part in a programming competition. In one of the problems she should check if some rooted trees are isomorphic or not. She has never seen this problem before, but, being an experienced participant, she guessed that she should match trees to some sequences and then compare these sequences instead of tree... | int solution() {
int h;
int A[100005];
int i;
int j;
int flag = 0;
scanf("%d", &h);
for (i = 0; i <= h; i++) {
scanf("%d", &A[i]);
}
for (i = 0; i < h; i++) {
if (A[i] > 1 && A[i + 1] > 1) {
flag = 1;
}
}
if (flag == 0) {
printf("perfect\n");
} else {
printf("ambiguous\... | 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 h = get!(usize);
let mut tree = vec![0; h + 1];
let mut n = 0;
let mut flag = ... | easy |
1103 | Suppose you have two points $$$p = (x_p, y_p)$$$ and $$$q = (x_q, y_q)$$$. Let's denote the Manhattan distance between them as $$$d(p, q) = |x_p - x_q| + |y_p - y_q|$$$.Let's say that three points $$$p$$$, $$$q$$$, $$$r$$$ form a bad triple if $$$d(p, r) = d(p, q) + d(q, r)$$$.Let's say that an array $$$b_1, b_2, \dots... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
int result = 0;
int tempp = 0;
int tempn = 0;
scanf("%d", &n);
int arr[n];
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
result += n + (n - 1);
if (n > 2) {
for (int i = 2; i < n; i++) {
... | fn solution() {
let std_in = stdin();
let in_lock = std_in.lock();
let input = BufReader::new(in_lock);
let std_out = stdout();
let out_lock = std_out.lock();
let mut output = BufWriter::new(out_lock);
let mut lines = input.lines().map(|r| r.unwrap());
let s = lines.next().unwrap();
... | hard |
1104 | Every December, VK traditionally holds an event for its employees named "Secret Santa". Here's how it happens.$$$n$$$ employees numbered from $$$1$$$ to $$$n$$$ take part in the event. Each employee $$$i$$$ is assigned a different employee $$$b_i$$$, to which employee $$$i$$$ has to make a new year gift. Each employee ... | int solution() {
int T;
scanf("%d", &T);
while (T--) {
const int mx = 2e5 + 5;
int T;
int n;
int m;
int p[mx];
int ans[mx];
int tong[mx];
int q[mx];
scanf("%d", &n);
m = 0;
for (int i = 1; i <= n; i++) {
tong[i] = ans[i] = 0;
}
for (int i = 1; i <= n; i++)... | fn solution() {
let std_in = stdin();
let in_lock = std_in.lock();
let input = BufReader::new(in_lock);
let std_out = stdout();
let out_lock = std_out.lock();
let mut output = BufWriter::new(out_lock);
let mut lines = input.lines().map(|r| r.unwrap());
let s = lines.next().unwrap();
... | hard |
1105 | Hooray! Polycarp turned $$$n$$$ years old! The Technocup Team sincerely congratulates Polycarp!Polycarp celebrated all of his $$$n$$$ birthdays: from the $$$1$$$-th to the $$$n$$$-th. At the moment, he is wondering: how many times he turned beautiful number of years?According to Polycarp, a positive integer is beautifu... | int solution() {
int T;
scanf("%d", &T);
for (int i = 0; i < T; i++) {
int x;
scanf("%d", &x);
if (x < 10) {
printf("%d\n", x);
} else if (x >= 10 && x < 100) {
printf("%d\n", (9 + (x / 11)));
} else if (x >= 100 && x < 1000) {
printf("%d\n", (18 + (x / 111)));
} else i... | fn solution() {
let reader = &mut io::BufReader::new(io::stdin());
let writer = &mut io::BufWriter::new(io::stdout());
let mut buf = String::new();
reader.read_line(&mut buf).unwrap();
let t = buf.trim_end().parse::<usize>().unwrap();
for _i in 0..t {
buf.clear();
reader.read_l... | hard |
1106 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You have <var>A</var> <var>500</var>-yen coins, <var>B</var> <var>100</var>-yen coins and <var>C</var> <var>50</var>-yen coins (yen is the currency of Japan).
In how many ways can we select some of thes... | int solution() {
int a = 0;
int b = 0;
int c = 0;
int x = 0;
int count = 0;
scanf("%d %d %d %d", &a, &b, &c, &x);
for (int i = 0; i <= a; i++) {
for (int j = 0; j <= b; j++) {
for (int k = 0; k <= c; k++) {
if (x == 500 * i + 100 * j + 50 * k) {
count++;
}
}
... | fn solution() {
let mut nums: Vec<i32> = Vec::with_capacity(4);
for _ in 0..4 {
let mut buf: String = String::new();
io::stdin().read_line(&mut buf).unwrap();
nums.push(buf.trim().parse::<i32>().unwrap());
}
let x = nums[3];
let mut a = min(x / 500, nums[0]);
let mut cnt ... | medium |
1107 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a grid with <var>N</var> rows and <var>N</var> columns of squares. Let <var>(i,j)</var> be the square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left.</p>
<... | int solution(void) {
int n;
int c;
scanf("%d %d", &n, &c);
int d[c + 1][c + 1];
for (int i = 1; i <= c; i++) {
for (int j = 1; j <= c; j++) {
scanf("%d", &d[i][j]);
}
}
int k[n + 1][n + 1];
int waru1[31] = {0};
int waru2[31] = {0};
int waru0[31] = {0};
for (int i = 1; i <= n; i++) ... | fn solution() {
input! {
N: usize,
C: usize,
D: [[usize; C]; C],
c: [[usize1; N]; N],
}
let mut counts = vec![vec![0; 3]; C];
for x in 0..N {
for y in 0..N {
counts[c[x][y]][(x + y + 2) % 3] += 1;
}
}
let mut min = std::usize::MAX;
... | easy |
1108 | Ezzat has an array of $$$n$$$ integers (maybe negative). He wants to split it into two non-empty subsequences $$$a$$$ and $$$b$$$, such that every element from the array belongs to exactly one subsequence, and the value of $$$f(a) + f(b)$$$ is the maximum possible value, where $$$f(x)$$$ is the average of the subsequen... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
int max = -1000000001;
long long int sum = 0;
double avg = 0.0;
scanf("%d", &n);
int arr[n];
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
if (arr[i] > max) {
max = arr[i];
}
sum += arr[... | fn solution() {
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
let test_count: usize = input.trim().parse().unwrap();
for _test in 0..test_count {
input.clear();
std::io::stdin().read_line(&mut input).unwrap();
input.clear();
std::io::... | medium |
1109 | <span class="lang-en">
<p>Score: <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have two distinct integers <var>A</var> and <var>B</var>.</p>
<p>Print the integer <var>K</var> such that <var>|A - K| = |B - K|</var>.</p>
<p>If such an integer does not exist, print <code>IMPOSSIBLE... | int solution(void) {
long A = 0;
long B = 0;
long sa = 0;
scanf("%ld %ld", &A, &B);
sa = A + B;
if (sa < 0) {
sa *= -1;
}
if (sa % 2 != 0) {
printf("IMPOSSIBLE\n");
return 0;
}
printf("%ld\n", sa / 2);
return 0;
} | fn solution() {
let mut ab = String::new();
stdin().read_line(&mut ab).unwrap();
let mut ab: Vec<isize> = ab.split_whitespace().flat_map(str::parse).collect();
ab.sort();
let (a, b) = (ab[0], ab[1]);
if (b - a) % 2 == 0 {
println!("{}", a + (b - a) / 2);
} else {
println!("I... | easy |
1110 | <H1>Maximum Sum Sequence</H1>
<p>
Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence.
... | int solution(void) {
int max = -25000000;
int n = 0;
int sum = 0;
int i = 0;
int j = 0;
int k = 0;
while (1) {
scanf("%d", &n);
int a[n];
if (n == 0) {
break;
}
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (i = 0; i < n; i++) {
for (j = i; j < n; j++... | fn solution() {
loop {
let mut row = String::new();
io::stdin().read_line(&mut row).ok();
let row: usize = row.trim().parse().unwrap();
if row == 0 {
break;
}
let mut v: Vec<isize> = Vec::new();
for _ in 0..row {
let mut input = String... | hard |
1111 | You are given an array $$$a[0 \ldots n-1]$$$ of length $$$n$$$ which consists of non-negative integers. Note that array indices start from zero.An array is called good if the parity of each index matches the parity of the element at that index. More formally, an array is good if for all $$$i$$$ ($$$0 \le i \le n - 1$$$... | int solution(void) {
int t = 0;
scanf("%d", &t);
while (t--) {
int n = 0;
scanf("%d", &n);
int arr[n];
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
int odd = 0;
int eve = 0;
for (int i = 0; i < n; i++) {
if (i % 2 != arr[i] % 2) {
if (arr[i] % 2 == 0) ... | fn solution() {
let t: usize = {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
buf.trim_end().parse().unwrap()
};
for _ in 0..t {
let n: usize = {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap()... | easy |
1112 | <h1>ソーシャルゲーム (Social Game)</h1>
<!-- 時間制限 : 2sec / メモリ制限 : 256MB-->
<h2> 問題文</h2>
<p>
JOI 君は明日から新たにソーシャルゲームを始めることにした.
</p>
<p>
このソーシャルゲームでは,<var>1</var> 日につき <var>1</var> 回までログインすることができ,ログインするたびに <var>A</var> 枚のコインが得られる.
</p>
<p>
また,月曜日から日曜日まで <var>7</var> 日連続でログインすると,そのたびに,追加で <var>B</var> 枚のコインが得られる.
</p>
<p>
... | int solution() {
int a = 0;
int b = 0;
int c = 0;
int sum = 0;
int i = 0;
scanf("%d %d %d", &a, &b, &c);
while (sum < c) {
i++;
sum += a;
if ((i % 7) == 0) {
sum += b;
}
}
printf("%d\n", i);
return 0;
} | fn solution() {
let nums: Vec<i32> = {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
s.trim_end()
.to_owned()
.split(' ')
.map(|s| s.parse::<i32>().unwrap())
.collect()
};
let check1: i32 = nums[2] % (7 * nums[... | easy |
1113 | <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>.</p>
<p>Takahashi can insert the character <code>A</code> at any position in this string any number of times.</p>
<p>Can he change <var>S</var> into <code>AKIHABARA</... | int solution() {
char s[51];
scanf("%s", s);
int l = strlen(s);
if (l >= 10) {
printf("NO");
return 0;
}
if (l == 9 && strcmp(s, "AKIHABARA") == 0) {
printf("YES");
return 0;
}
if (l == 8 && (strcmp(s, "AKIHABAR") == 0 || strcmp(s, "AKIHABRA") == 0 ||
strcmp(s, "AKIHBARA... | fn solution() {
input!(s: String);
let vs = vec![
"AKIHABARA",
"KIHABARA",
"AKIHBARA",
"KIHBARA",
"AKIHABRA",
"KIHABRA",
"AKIHBRA",
"KIHBRA",
"AKIHABAR",
"KIHABAR",
"AKIHBAR",
"KIHBAR",
"AKIHABR",
"KI... | medium |
1114 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a string <var>S</var> of length <var>N</var> consisting of uppercase English letters.</p>
<p>How many times does <code>ABC</code> occur in <var>S</var> as contiguous subsequences (see Sample Inp... | int solution(void) {
int N = 0;
int count = 0;
scanf("%d", &N);
char S[N];
scanf("%s", S);
for (int i = 0; i < (N - 2); i++) {
if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') {
count++;
}
}
printf("%d\n", count);
return 0;
} | fn solution() {
let (_n, s): (i32, String) = {
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).unwrap();
let mut iter = buf.split_whitespace();
(
iter.next().unwrap().parse().unwrap(),
iter.next().unwrap().to_string(),
)
};
... | medium |
1115 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Kurohashi has never participated in AtCoder Beginner Contest (ABC).</p>
<p>The next ABC to be held is ABC <var>N</var> (the <var>N</var>-th ABC ever held).
Kurohashi wants to make his debut in some ABC ... | int solution(void) {
int n = 0;
int x[10] = {111, 222, 333, 444, 555, 666, 777, 888, 999};
scanf("%d", &n);
if (n <= x[0]) {
n = x[0];
} else if (n > x[0] && n <= x[1]) {
n = x[1];
} else if (n > x[1] && n <= x[2]) {
n = x[2];
} else if (n > x[2] && n <= x[3]) {
n = x[3];
} else if (n... | fn solution() {
let handle = std::io::stdin();
let mut buf = String::new();
handle.lock().read_line(&mut buf).unwrap();
let num: usize = usize::from_str(buf.trim()).unwrap();
if num < 112 {
println!("111");
} else if num < 223 {
println!("222");
} else if num < 334 {
... | medium |
1116 | Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has $$$a$$$ coins, Barbara has $$$b$$$ coins and Cerene has $$$c$$$ coins. Recently Polycarp has returned from the trip around the world and brought $$$n$$$ coins.He wants to distribute all these $$$n$$$ coins between his... | int solution() {
int t = 0;
int a = 0;
int b = 0;
int c = 0;
int n = 0;
scanf("%d", &t);
for (int i = 0; i < t; ++i) {
scanf("%d %d %d %d", &a, &b, &c, &n);
if (a >= b && a >= c) {
if (n < a - b + a - c) {
printf("NO\n");
continue;
}
printf(((n - (a - b) - (a - c)... | fn solution() {
let stdin = std::io::stdin();
for t in stdin.lock().lines().skip(1) {
let t: Vec<i64> = t.unwrap().split(' ').map(|x| x.parse().unwrap()).collect();
if let [a, b, c, n] = t[..] {
let m = std::cmp::max(a, std::cmp::max(b, c));
let r = n - (m - a) - (m - b... | easy |
1117 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Along a road running in an east-west direction, there are <var>A</var> shrines and <var>B</var> temples.
The <var>i</var>-th shrine from the west is located at a distance of <var>s_i</var> meters from t... | int solution() {
int i;
int A;
int B;
int Q;
long long s[100002];
long long t[100002];
long long x[100001];
scanf("%d %d %d", &A, &B, &Q);
for (i = 1; i <= A; i++) {
scanf("%lld", &(s[i]));
}
for (i = 1; i <= B; i++) {
scanf("%lld", &(t[i]));
}
for (i = 1; i <= Q; i++) {
scanf("%ll... | fn solution() {
input!(
a: usize,
b: usize,
q: usize,
s: [i64; a],
t: [i64; b],
query: [i64; q],
);
let shrine: Vec<i64> = vec![std::i64::MIN]
.into_iter()
.chain(s)
.chain(vec![std::i64::MAX])
.collect();
let temple: Vec<... | medium |
1118 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when... | int solution()
{
int n;
int i;
int j;
int sum = 0;
int c = 0;
int min;
int a = 0;
int k;
scanf("%d", &n);
int x[n];
for (i = 0; i < n; i++) {
scanf("%d", &x[i]);
}
for (j = 0; j < n; j++) {
min = 1000000001;
for (i = 0; i < n; i++) {
if (x[i] >= sum && x[i] - sum < mi... | fn solution() {
io::stdin().read_line(&mut String::new()).unwrap();
let mut line = String::new();
io::stdin().read_line(&mut line).unwrap();
let mut words: Vec<i64> = line
.split_whitespace()
.map(|x| x.parse().unwrap())
.collect();
words.sort();
let mut suma = 0;
... | hard |
1119 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given integers <var>A</var> and <var>B</var>, each between <var>1</var> and <var>3</var> (inclusive).</p>
<p>Determine if there is an integer <var>C</var> between <var>1</var> and <var>3</var> (... | int solution(void) {
int a = 0;
int b = 0;
scanf("%d %d", &a, &b);
if ((a * b % 2) == 0) {
printf("No");
} else {
printf("Yes");
}
} | 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 v: Vec<u32> = s.split_whitespace().map(|x| x.parse().unwrap()).collect();
if v[0] % 2 == 1 && v[1] % 2 == 1 {
println!("Yes");
... | medium |
1120 | <span class="lang-en">
<p>Score: <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>As AtCoder Beginner Contest 100 is taking place, the office of AtCoder, Inc. is decorated with a sequence of length <var>N</var>, <var>a = </var>{<var>a_1, a_2, a_3, ..., a_N</var>}.<br/>
Snuke, an empl... | int solution() {
int n = 0;
scanf("%d\n", &n);
int a[n];
int i = 0;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
i = 0;
int num = 0;
while (i < n) {
if (a[i] % 2 == 0) {
a[i] = a[i] / 2;
num++;
} else {
i++;
}
}
printf("%d\n", num);
return 0;
} | fn solution() {
let mut count_line = String::new();
std::io::stdin().read_line(&mut count_line).ok();
let mut values_line = String::new();
std::io::stdin().read_line(&mut values_line).ok();
let it = values_line.split_whitespace();
let mut dividable_count = 0;
for i in it {
let mut u... | hard |
1121 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In... | int solution() {
int N;
scanf("%d", &N);
int in[N][2];
int out[N];
for (int i = 0; i < N; i++) {
scanf("%d %d", &in[i][0], &in[i][1]);
if (in[i][1] % in[i][0] == 0) {
out[i] = 0;
} else {
out[i] = 2;
}
}
for (int i = 0; i < N; i++) {
printf("%d\n", out[i], in[i][0], in[i][1... | 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... | hard |
1122 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given four integers <var>A</var>, <var>B</var>, <var>C</var>, and <var>D</var>. Find the number of integers between <var>A</var> and <var>B</var> (inclusive) that can be evenly divided by neithe... | int solution(void) {
long long A = 0;
long long B = 0;
long long C = 0;
long long D = 0;
long long bC = 0;
long long bD = 0;
long long bCD = 0;
long long aC = 0;
long long aD = 0;
long long aCD = 0;
long long sumB = 0;
long long sumA = 0;
long long max = 0;
long long min = 0;
long long am... | fn solution() {
input! {
a:u64,
b:u64,
c:u64,
d:u64
}
let mut temp: u64;
let mut m = d;
let mut n = c;
while m % n != 0 {
temp = n;
n = m % n;
m = temp;
}
let min_multi = d * c / n;
let diff_c = b / c - (a - 1) / c;
let... | medium |
1123 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>An integer <var>X</var> is called a Harshad number if <var>X</var> is divisible by <var>f(X)</var>, where <var>f(X)</var> is the sum of the digits in <var>X</var> when written in base <var>10</var>.</p>... | int solution(void) {
int n;
scanf("%d", &n);
int x = 0;
int ten = 1;
for (int i = 0; i <= 8; i++) {
x += n / ten % 10;
ten *= 10;
}
if (n % x == 0) {
printf("Yes\n");
} else {
printf("No\n");
}
return 0;
} | fn solution() {
let stdin = stdin();
let mut stdinlock = stdin.lock();
let mut str1 = String::new();
stdinlock.read_line(&mut str1).unwrap();
let mut it1 = str1.split_whitespace().map(|x| u32::from_str(x).unwrap());
let n = it1.next().unwrap();
let mut na = n;
let mut j = 0;
for _ in... | easy |
1124 | <span class="lang-en">
<p>Score : <var>100</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>.
Let <var>x</var> be the average of <var>a</var> and <var>b</var>.
Print <var>x</var> rounded up to the nearest integer.</p>
</section>
... | int solution(void) {
int a = 0;
int b = 0;
int answer = 0;
scanf("%d %d", &a, &b);
answer = (a + b) / 2;
if ((a + b) % 2 != 0) {
answer++;
}
printf("%d\n", answer);
return 0;
} | fn solution() {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).ok();
let input: Vec<i32> = buf.split_whitespace().map(|x| x.parse().unwrap()).collect();
println!("{}", (input[0] + input[1] + 1) / 2)
} | medium |
1125 | Boboniu likes playing chess with his employees. As we know, no employee can beat the boss in the chess game, so Boboniu has never lost in any round.You are a new applicant for his company. Boboniu will test you with the following chess question:Consider a $$$n\times m$$$ grid (rows are numbered from $$$1$$$ to $$$n$$$,... | int solution() {
int x;
int y;
int n;
int m;
scanf("%d%d%d%d", &n, &m, &x, &y);
printf("%d %d\n", x, y);
printf("%d %d\n", 1, y);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m && i % 2; j++) {
if ((i == x && j == y) || (i == 1 && j == y)) {
continue;
}
printf("%d %d... | 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, m, mut sx, mut sy): (usize, usize, usize, usize) = {
let mut buf = String::new();
re... | hard |
1126 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>AtCoDeer is thinking of painting an infinite two-dimensional grid in a <em>checked pattern of side <var>K</var></em>.
Here, a checked pattern of side <var>K</var> is a pattern where each square is paint... | int solution(void) {
int n;
int m;
int x;
int y;
char c;
static int map[2010][2010];
static int ruiseki[2010][2010];
static int ruisekitemp[2010][2010];
int i;
int j;
int k;
int l;
int flag = 0;
int ans = 0;
int count = 0;
int sum = 0;
int temp;
int temp1;
int temp2;
int len;
... | fn solution() {
input! {
n: usize,
k: usize,
query: [(usize, usize, chars); n],
}
let m = k * 2;
let mut field = vec![vec![0i64; k * 3]; k * 2];
for &(x, y, ref c) in &query {
let y = match *c.first().unwrap() {
'B' => y,
_ => y + k,
};
... | hard |
1127 | You are given three integers $$$x, y$$$ and $$$n$$$. Your task is to find the maximum integer $$$k$$$ such that $$$0 \le k \le n$$$ that $$$k \bmod x = y$$$, where $$$\bmod$$$ is modulo operation. Many programming languages use percent operator % to implement it.In other words, with given $$$x, y$$$ and $$$n$$$ you nee... | int solution() {
int x;
int y;
int n;
int N = 0;
scanf("%d", &N);
while (N > 0) {
scanf("%d", &x);
scanf("%d", &y);
scanf("%d", &n);
if (x == 0) {
printf("%s\n", "x is zero, no answer");
return -1;
}
int k = (n / x) * x;
if (k + y <= n) {
printf("%d\n", k... | fn solution() {
let stdin = io::stdin();
let mut input = stdin.lock();
let mut line = String::new();
input.read_line(&mut line).unwrap();
let mut count: u16 = line.trim().parse().unwrap();
while count > 0 {
line.clear();
input.read_line(&mut line).unwrap();
let mut iter =... | hard |
1128 | You are given an array $$$a$$$ consisting of $$$n$$$ integers. Initially all elements of $$$a$$$ are either $$$0$$$ or $$$1$$$. You need to process $$$q$$$ queries of two kinds: 1 x : Assign to $$$a_x$$$ the value $$$1 - a_x$$$. 2 k : Print the $$$k$$$-th largest value of the array. As a reminder, $$$k$$$-th largest ... | int solution(void) {
int n = 0;
int q = 0;
scanf("%d %d", &n, &q);
int a[n];
int count[2] = {0};
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
count[a[i]]++;
}
int t = 0;
int k = 0;
int l = 0;
for (int m = 0; m < q; m++) {
scanf("%d %d", &t, &k);
if (t == 1) {
a[k - 1] =... | fn solution() {
let std_in = stdin();
let in_lock = std_in.lock();
let input = BufReader::new(in_lock);
let std_out = stdout();
let out_lock = std_out.lock();
let mut output = BufWriter::new(out_lock);
let mut lines = input.lines().map(|r| r.unwrap());
let s = lines.next().unwrap();
... | medium |
1129 | <H1>Standard Deviation</H1><br>
<p>
You have final scores of an examination for <var>n</var> students. Calculate standard deviation of the scores <var>s<sub>1</sub></var>, <var>s<sub>2</sub></var> ... <var>s<sub>n</sub></var>.
</p>
<p>
The variance α<sup>2</sup> is defined by
</p>
<p>
α<sup>2</sup> ... | int solution(void) {
int i;
double n;
double s[1000] = {0};
double a = 0;
double m = 0;
scanf("%lf", &n);
while (n != 0) {
for (i = 0; i < n; i++) {
scanf("%lf", &s[i]);
m = m + s[i];
}
m = m / n;
for (i = 0; i < n; i++) {
a = a + (s[i] - m) * (s[i] - m);
s[i]... | fn solution() {
let stdin = std::io::stdin();
let mut lines = stdin.lock().lines();
loop {
let n = lines.next().unwrap().unwrap().parse::<f64>().unwrap();
if n == 0. {
break;
}
let v = lines
.next()
.unwrap()
.unwrap()
... | medium |
1130 | There are $$$n$$$ piles of sand where the $$$i$$$-th pile has $$$a_i$$$ blocks of sand. The $$$i$$$-th pile is called too tall if $$$1 < i < n$$$ and $$$a_i > a_{i-1} + a_{i+1}$$$. That is, a pile is too tall if it has more sand than its two neighbours combined. (Note that piles on the ends of the array cannot... | int solution() {
int t = 0;
scanf("%d", &t);
int n;
int k;
for (int i = 0; i < t; i++) {
scanf("%d%d", &n, &k);
int a[n];
for (int j = 0; j < n; j++) {
scanf("%d", &a[j]);
}
if (k == 1) {
printf("%d\n", (n - 1) / 2);
} else {
int c = 0;
for (int j = 1; j < n - 1... | fn solution() {
let mut content = String::new();
io::stdin()
.read_to_string(&mut content)
.expect("Unable to read from stdin");
let mut lines = content.lines();
let num_tests: usize = lines.next().unwrap().parse().unwrap();
for _ in 0..num_tests {
let arr: Vec<usize> = line... | easy |
1131 | You are given $$$4n$$$ sticks, the length of the $$$i$$$-th stick is $$$a_i$$$.You have to create $$$n$$$ rectangles, each rectangle will consist of exactly $$$4$$$ sticks from the given set. The rectangle consists of four sides, opposite sides should have equal length and all angles in it should be right. Note that ea... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
int i;
int x = 0;
int y = 0;
int j;
int temp;
int area;
scanf("%d", &n);
int a[4 * n];
for (i = 0; i < 4 * n; i++) {
scanf("%d", &a[i]);
}
for (i = 0; i < 4 * n; i++) {
for (j = 0; j < i; j++)... | fn solution() {
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("failed to read input");
let t = input.trim().parse::<u16>().unwrap();
for _ in 0..t {
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expe... | easy |
1132 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an integer <var>N</var>. Find the number of strings of length <var>N</var> that satisfy the following conditions, modulo <var>10^9+7</var>:</p>
<ul>
<li>The string does not contain charact... | int solution(void) {
long n;
scanf("%ld", &n);
long ans = 0;
if (n == 3) {
ans = pow(4, 3) - 3;
printf("%ld\n", ans);
return 0;
}
long mod = pow(10, 9) + 7;
long dp[n + 1][4][4][4][4];
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 4; k++) {
... | fn solution() {
input! {
N : usize,
}
let MOD = 1_000_000_007;
let mut dp = vec![vec![vec![vec![0; 5]; 5]; 5]; N + 1];
dp[0][0][0][0] = 1;
for n in 0..N {
for c0 in 0..5 {
for c1 in 0..5 {
for c2 in 0..5 {
for c3 in 1..5 {
... | easy |
1133 | You are given two matrices $$$A$$$ and $$$B$$$. Each matrix contains exactly $$$n$$$ rows and $$$m$$$ columns. Each element of $$$A$$$ is either $$$0$$$ or $$$1$$$; each element of $$$B$$$ is initially $$$0$$$.You may perform some operations with matrix $$$B$$$. During each operation, you choose any submatrix of $$$B$$... | int solution() {
int m;
int n;
int free = 1;
scanf("%d%d", &n, &m);
int a[n][m];
int b[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
scanf("%d", &a[i][j]);
if (a[i][j] == 1) {
free = 0;
}
b[i][j] = 0;
}
}
if (free) {
printf("0");
ret... | fn solution() {
let stdin = std::io::stdin();
let mut buf = String::new();
stdin.read_line(&mut buf).unwrap();
let mut w = buf.split_whitespace();
let (n, m): (usize, usize) = (
w.next().unwrap().parse().unwrap(),
w.next().unwrap().parse().unwrap(),
);
let mut eta = vec![vec... | easy |
1134 | After reaching your destination, you want to build a new colony on the new planet. Since this planet has many mountains and the colony must be built on a flat surface you decided to flatten the mountains using boulders (you are still dreaming so this makes sense to you). You are given an array $$$h_1, h_2, \dots, h_n$... | int solution() {
int t = 0;
int n = 0;
int k = 0;
int pit = 0;
int th = 0;
int h[100] = {0};
scanf("%d", &t);
for (int te = 0; te < t; te++) {
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%d", &h[i]);
}
h[n] = 0;
for (int i = 0; i < k; i++) {
pit = 1;
... | fn solution() {
let k = std::io::stdin()
.lock()
.lines()
.next()
.unwrap()
.unwrap()
.parse::<i32>()
.unwrap();
for _ele in 0..k {
let mut l = String::new();
std::io::stdin().read_line(&mut l).unwrap();
let mut l = l
.t... | hard |
1135 | <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> boxes arranged in a row from left to right. The <var>i</var>-th box from the left contains <var>A_i</var> candies.</p>
<p>You will take out the candies from some consecutive boxes... | int solution() {
int n;
int m;
scanf("%d%d", &n, &m);
int a[n];
int i;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
long long int ans = 0;
int tmp[n + 1];
tmp[0] = 0;
int j = 0;
for (i = 0; i < n; i++) {
tmp[i + 1] = (tmp[i] + a[i]) % m;
for (j = 0; j <= i; j++) {
if (tmp[i ... | fn solution() {
let stdin = io::stdin();
let mut s = String::new();
let mut nums: Vec<i64> = Vec::new();
{
stdin.read_line(&mut s).ok();
let it = s.split_whitespace();
for arg in it {
nums.push(i64::from_str(arg).expect("e1"));
}
}
let _n = nums[0];
... | medium |
1136 | <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> towns located in a line, conveniently numbered <var>1</var> through <var>N</var>. Takahashi the merchant is going on a travel from town <var>1</var> to town <var>N</var>, buying a... | int solution(void) {
int n;
int t;
int max = 0;
int min = INT_MAX;
int ans = 0;
scanf("%d%d", &n, &t);
int a[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i < n; i++) {
if (min > a[i]) {
min = a[i];
}
if (max < a[i] - min) {
max = a[i] - min;
... | fn solution() {
io::stdin().read_line(&mut String::new()).ok();
let mut s = String::new();
io::stdin().read_line(&mut s).ok();
let (_, res, _) = s.trim().split(' ').rev().fold((0, 0, 0), |(v, n, x), y| {
let z = y.parse().unwrap();
let d = x - z;
if z > x {
(v, n, ... | hard |
1137 | Michael and Joe are playing a game. The game is played on a grid with $$$n$$$ rows and $$$m$$$ columns, filled with distinct integers. We denote the square on the $$$i$$$-th ($$$1\le i\le n$$$) row and $$$j$$$-th ($$$1\le j\le m$$$) column by $$$(i, j)$$$ and the number there by $$$a_{ij}$$$.Michael starts by saying tw... | int solution() {
int t = 0;
int i = 0;
int j = 0;
int k = 0;
int n = 0;
int m = 0;
int a[40];
int x[40];
int temporary = 0;
int key = 0;
int var1 = 0;
int var2 = 0;
scanf("%d\n", &t);
i = t;
while (i > 0) {
scanf("%d %d\n", &n, &m);
for (j = 0; j < n; j++) {
scanf("%d", &a... | fn solution() {
let mut input = String::new();
let stdin = io::stdin();
let (mut n, mut m): (i32, i32);
let mut num: Vec<i32>;
let (mut best, mut best_i, mut best_j): (i32, i32, i32);
stdin.read_line(&mut input).expect("bruh");
let tests: i32 = input.trim().parse::<i32>().unwrap();
fo... | medium |
1138 | <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> cards placed face down in a row. On each card, an integer <var>1</var> or <var>2</var> is written.</p>
<p>Let <var>A_i</var> be the integer written on the <var>i</var>-th card.</p... | int solution() {
int i;
int u;
int w;
int z;
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 = 1; i <= N; i++) {
adj[i] = NULL;
}
for (i = 0; i < M; i++) {
scanf("%d %d %d", &u, &w, &z);
... | fn solution() {
input! {
n: usize,
m: usize,
xyz: [(usize1, usize1, usize); m]
}
let mut graph = vec![vec![]; n];
for &(x, y, _) in &xyz {
graph[x].push(y);
graph[y].push(x);
}
let mut count = 0;
let mut dist = vec![false; n];
for i in 0..n {
... | medium |
1139 | You're given an array of $$$n$$$ integers between $$$0$$$ and $$$n$$$ inclusive.In one operation, you can choose any element of the array and replace it by the MEX of the elements of the array (which may change after the operation).For example, if the current array is $$$[0, 2, 2, 1, 4]$$$, you can choose the second el... | int solution() {
int t;
scanf("%d", &t);
int n;
int i;
int j;
int k;
int a[1003];
int ans[2003];
int cnt[1003];
int l;
int r;
for (; t > 0; t--) {
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
k = 0;
for (i = 0; i <= n; i++) {
cnt[i] = 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();
let mut xs: Vec<usize> = lines
.next()
.u... | medium |
1140 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has a string <var>S</var> consisting of three kinds of letters: <code>a</code>, <code>b</code> and <code>c</code>.</p>
<p>He has a phobia for palindromes, and wants to permute the characters in <v... | int solution() {
int S_length = 0;
int count_a = 0;
int count_b = 0;
int count_c = 0;
char S[100001];
scanf("%s", S);
while (S[S_length] != '\0') {
S_length++;
}
for (int i = 0; i < S_length; i++) {
switch (S[i]) {
case 'a':
count_a++;
break;
case 'b':
count_b++;
... | fn solution() {
let mut s: String = String::new();
std::io::stdin().read_to_string(&mut s).ok();
let mut itr = s.split_whitespace();
let s: Vec<char> = itr.next().unwrap().chars().collect();
let n = s.len();
if n == 1 {
println!("YES");
} else if n == 2 {
if s[0] == s[1] {
... | easy |
1141 | A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the oth... | int solution() {
int a = 0;
int i = 0;
scanf("%d", &a);
if (a % 2) {
printf("-1");
} else {
for (i = 1; i < a + 1; i++) {
if (i % 2 == 0) {
printf("%d ", i - 1);
} else {
printf("%d ", i + 1);
}
}
}
return 0;
} | fn solution() {
let mut guess = String::new();
io::stdin()
.read_line(&mut guess)
.expect("Failed to read line");
let guess: u32 = match guess.trim().parse() {
Ok(number) => number,
Err(_) => 0,
};
if !guess.is_multiple_of(2) {
println!("-1");
return;
... | easy |
1142 | You are given a string $$$s=s_1s_2\dots s_n$$$ of length $$$n$$$, which only contains digits $$$1$$$, $$$2$$$, ..., $$$9$$$.A substring $$$s[l \dots r]$$$ of $$$s$$$ is a string $$$s_l s_{l + 1} s_{l + 2} \ldots s_r$$$. A substring $$$s[l \dots r]$$$ of $$$s$$$ is called even if the number represented by it is even. Fi... | int solution() {
int n;
int sum = 0;
char a[70000];
scanf("%d", &n);
scanf("%s", a);
for (int i = 0; i < n; i++) {
if ((a[i]) % 2 == 0 && a[i] != 0) {
sum += (i + 1);
}
}
printf("%d", sum);
} | fn solution() {
let mut input = String::new();
std::io::stdin()
.read_line(&mut input)
.expect("INPUT:: read line failed");
let amount: usize = input.trim().parse().expect("amount: parse to usize failed");
input.clear();
std::io::stdin()
.read_line(&mut input)
.expect... | hard |
1143 | A positive integer $$$x$$$ is called a power of two if it can be represented as $$$x = 2^y$$$, where $$$y$$$ is a non-negative integer. So, the powers of two are $$$1, 2, 4, 8, 16, \dots$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to represent $$$n$$$ as the sum of exactly $$$k$$$ powers of... | int solution() {
int n;
int k;
scanf("%d %d", &n, &k);
if (k > n) {
printf("NO");
return 0;
}
int b[31] = {0};
int j = 30;
int even = 0;
while (n > 0) {
b[j] = n % 2;
if (n % 2) {
even++;
}
n /= 2;
j--;
}
for (int z = 0; z < 31; z++) {
if (even < k && b[z] >... | fn solution() {
let mut buf = String::new();
stdin().read_to_string(&mut buf).unwrap();
let mut tok = buf.split_whitespace();
let mut get = || tok.next().unwrap();
let n = get!();
let k = get!(usize);
let mut p = n;
let mut b = 1_i64;
let mut bits = vec![];
while p > 0 {
... | medium |
1144 | The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dic... | int solution(void) {
int t;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
char *array = (char *)malloc(2 * sizeof(char));
scanf("%s", array);
printf("%d\n", ((array[0] - 97) * 25) +
(array[0] > array[1] ? array[1] - 96 : array[1] - 97));
free(array);
}
return 0;
} | fn solution() {
let mut input = String::new();
stdin().read_to_string(&mut input).ok();
let mut output = String::new();
let mut input = input.split_ascii_whitespace();
let t = input.next().unwrap().parse::<usize>().unwrap();
for _ in 0..t {
let s = input.next().unwrap().as_bytes();
... | medium |
1145 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>This contest is <code>CODEFESTIVAL</code>, which can be shortened to the string <code>CF</code> by deleting some characters. </p>
<p>Mr. Takahashi, full of curiosity, wondered if he could obtain <code>... | int solution(void) {
char s[100];
int a = 0;
int i = 0;
scanf("%s", s);
for (i = 0; i < 100; i++) {
if (a == 0 && s[i] == 'C') {
a++;
}
if (a == 1 && s[i] == 'F') {
a++;
break;
}
}
if (a == 2) {
printf("Yes\n");
} else {
printf("No\n");
}
return 0;
} | fn solution() {
let mut st = String::new();
stdin().read_line(&mut st).unwrap();
let y: Vec<char> = st.chars().collect();
let mut x: i32 = 0;
for i in y {
if x == 0 {
if i == 'C' {
x += 1;
};
} else {
if i == 'F' {
x... | easy |
1146 | Binary search | int solution(const int *arr, int l, int r, int x) {
if (r >= l) {
int mid = l + ((r - l) / 2);
if (arr[mid] == x) {
return mid;
}
if (arr[mid] > x) {
return binarysearch1(arr, l, mid - 1, x);
}
return binarysearch1(arr, mid + 1, r, x);
}
return -1;
}
| fn solution<T: Ord>(item: &T, arr: &[T]) -> Option<usize> {
let is_asc = arr.len() > 1 && arr[0] < arr[arr.len() - 1];
let mut left = 0;
let mut right = arr.len();
while left < right {
let mid = left + (right - left) / 2;
let cmp_result = item.cmp(&arr[mid]);
match (is_asc, cm... | hard |
1147 | Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter.Their algorithm will be tested on an array of integers, where the $$$i$$$-th integer represents the color of the $$$i$$$-th pixel in the image. The image is in black and white, ... | int solution() {
int input;
int n;
int k;
int p[256];
scanf("%d%d", &n, &k);
for (int i = 0; i < 256; i++) {
p[i] = -1;
}
for (int i = 0; i < n; ++i) {
scanf("%d", &input);
if (p[input] == -1) {
int temp = (input - k + 1) < 0 ? 0 : (input - k + 1);
for (int j = temp; j <= input;... | fn solution() {
use std::io;
use std::io::prelude::*;
let mut input = String::new();
io::stdin().read_to_string(&mut input).unwrap();
let mut it = input.split_whitespace();
let _n: usize = it.next().unwrap().parse().unwrap();
let k: usize = it.next().unwrap().parse().unwrap();
let p:... | easy |
1148 | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For eac... | int solution() {
int n;
scanf("%d", &n);
int arr[n];
scanf("%d", &arr[0]);
int max = arr[0];
int min = arr[0];
int jlm = 0;
for (int i = 1; i < n; i++) {
scanf("%d", &arr[i]);
if (arr[i] > max) {
jlm++;
max = arr[i];
}
if (arr[i] < min) {
min = arr[i];
jlm++;
... | fn solution() {
{
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
}
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
let (mut minimum, mut maximum, mut delta) = (10001, -1, -2);
for num in buf
.split_whitespace()
... | medium |
1149 | <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> mountains ranging from east to west, and an ocean to the west.</p>
<p>At the top of each mountain, there is an inn. You have decided to choose where to stay from these inns.</p>
<... | int solution(void) {
int N = 0;
int Ni[20];
int max = 0;
int result = 0;
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%d", &Ni[i]);
}
for (int i = 0; i < N; i++) {
if (Ni[i] >= max) {
max = Ni[i];
result++;
}
}
printf("%d", result);
return 0;
} | fn solution() {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).ok();
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).ok();
let hs: Vec<i32> = buf.trim().split(" ").map(|x| x.parse().unwrap()).collect();
let mut ans = 0;
let mut max = 0;
for h in hs {
... | medium |
1150 | <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>Snuke has a favorite positive integer, <var>N</var>. You can ask him the following type of question at most <var>64</var> ti... | int solution() {
int k = 10;
char res;
const long long pow[11] = {1, 10, 100, 1000,
10000, 100000, 1000000, 10000000,
100000000, 1000000000, 10000000000};
long long tmp = 49999999999;
long long ans = 0;
printf("? %l... | fn solution() {
let mut res: i64 = 0;
for i in 0..15 {
let mut low: i64 = if res > 0 { -1 } else { 0 };
let mut high: i64 = 9;
while high - low > 1 {
let mid = (low + high) / 2;
if i < 5 {
println!("? {}9999999999", 10 * res + mid);
} e... | medium |
1151 | Gregor is learning about RSA cryptography, and although he doesn't understand how RSA works, he is now fascinated with prime numbers and factoring them.Gregor's favorite prime number is $$$P$$$. Gregor wants to find two bases of $$$P$$$. Formally, Gregor is looking for two integers $$$a$$$ and $$$b$$$ which satisfy bot... | int solution() {
int t = 0;
scanf("%d", &t);
int prime_number = 0;
int counter = 0;
int results[2000];
for (int i = 0; i < t; i++) {
prime_number = 0;
scanf("%d", &prime_number);
results[counter] = 2;
counter++;
results[counter] = (prime_number - 1);
counter++;
}
counter =... | fn solution() {
let mut t = String::new();
io::stdin().read_line(&mut t).expect("");
let mut t: u32 = t.trim().parse().expect("");
while t > 0 {
let mut p = String::new();
io::stdin().read_line(&mut p).expect("");
let p: u32 = p.trim().parse().expect("");
println!("{} {}... | medium |
1152 | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line. Unfortunately, from time to time... | int solution() {
int a[27];
int count = 0;
int ascii = 'a';
char in[1002];
for (int i = 0; i < 27; i++) {
a[i] = 0;
}
scanf(" %c", &in[0]);
int i = 1;
int flag = 1;
while (flag) {
scanf(" %c", &in[i]);
if (in[i] == '}') {
break;
}
a[in[i] - ascii]++;
}
printf(" %d", c... | fn solution() {
let s: Vec<char> = {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
buf.chars().collect()
};
let mut set = HashSet::new();
for &c in s.iter() {
if let 'a'..='z' = c {
set.insert(c);
}
}
println!("{}... | medium |
1153 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi and Aoki will play a game using a grid with <var>H</var> rows and <var>W</var> columns of square cells.
There are <var>N</var> obstacles on this grid; the <var>i</var>-th obstacle is at <var>(... | int solution() {
long H;
long W;
long N;
long i;
long j;
long k;
long a = 0;
long *A;
scanf("%ld %ld %ld", &H, &W, &N);
A = (long *)malloc((H + 1) * sizeof(long));
for (i = 1; i <= H; i++) {
A[i] = 0;
}
for (k = 0; k < N; k++) {
scanf("%ld %ld", &i, &j);
if (i < j) {
contin... | fn solution() {
input! {
h: usize,
w: usize,
n: usize,
ps: [[usize; 2]; n]
}
if h == 1 {
println!("1");
return;
}
let mut tab = vec![Vec::new(); w];
let mut set = HashSet::new();
for i in 0..n {
if ps[i][0] < ps[i][1] {
cont... | hard |
1154 | Polycarp bought a new expensive painting and decided to show it to his $$$n$$$ friends. He hung it in his room. $$$n$$$ of his friends entered and exited there one by one. At one moment there was no more than one person in the room. In other words, the first friend entered and left first, then the second, and so on.It ... | int solution() {
int cases;
scanf("%d", &cases);
char string[200000];
for (int c = 0; c < cases; c++) {
scanf("%s", &string[0]);
if (strlen(string) == 1) {
printf("1\n");
continue;
}
int start = -1;
int end = 200001;
int i = 0;
while (string[i] != 0) {
if (string[i]... | fn solution() {
let k = std::io::stdin()
.lock()
.lines()
.next()
.unwrap()
.unwrap()
.parse::<i64>()
.unwrap();
for _ in 0..k {
let mut m = String::new();
std::io::stdin().read_line(&mut m);
let m = m
.trim()
... | medium |
1155 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>How many multiples of <var>d</var> are there among the integers between <var>L</var> and <var>R</var> (inclusive)?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All val... | int solution() {
int L;
int R;
int d;
int k = 1;
int i = 0;
int n = 0;
scanf("%d%d%d", &L, &R, &d);
while (1) {
n = d * k;
k++;
if (n >= L && n <= R) {
i++;
}
if (n > R) {
break;
}
}
printf("%d\n", i);
return 0;
} | fn solution() {
let stdin = io::stdin();
let mut buf = String::new();
stdin.read_line(&mut buf).ok();
let mut it = buf.split_whitespace().map(|n| usize::from_str(n).unwrap());
let (mut l, r, d) = (it.next().unwrap(), it.next().unwrap(), it.next().unwrap());
l -= 1;
println!("{}", r / d - l /... | medium |
1156 | A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means... | int solution() {
int n = 0;
scanf("%d", &n);
int *value = (int *)malloc(sizeof(int[n]));
for (int i = 0; i < n; i++) {
scanf("%d", &value[i]);
}
int index = 1;
for (; index < n; index++) {
if (value[index] != value[0]) {
break;
}
}
if (n % index != 0) {
printf("NO");
return 0... | fn solution() {
let reader = io::stdin();
let mut s = String::new();
let _ = io::stdin().read_line(&mut s).expect("???");
let numbers: Vec<i32> = reader
.lock()
.lines()
.next()
.unwrap()
.unwrap()
.trim()
.split(' ')
.map(|s| s.parse().unw... | medium |
1157 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are an integer <var>X</var> and an integer sequence of length <var>N</var>: <var>p_1, \ldots, p_N</var>.</p>
<p>Among the integers not contained in the sequence <var>p_1, \ldots, p_N</var> (not ne... | int solution() {
int x = 0;
int N = 0;
int b = 0;
int list[100] = {0};
scanf("%d %d", &x, &N);
int check[100][2] = {0};
if (N != 0) {
for (int i = 0; i < N; i++) {
scanf("%d ", &b);
list[i] = b;
}
}
for (int i = 0; i < N; i++) {
if (x - list[i] > 0) {
check[x - list[i]]... | fn solution() {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
let l1: Vec<i64> = buf
.split_whitespace()
.filter_map(|x| x.parse().ok())
.collect();
let x = l1[0];
let _n = l1[1];
buf.clear();
stdin().read_line(&mut buf).unwrap();
le... | hard |
1158 | Alica and Bob are playing a game.Initially they have a binary string $$$s$$$ consisting of only characters 0 and 1.Alice and Bob make alternating moves: Alice makes the first move, Bob makes the second move, Alice makes the third one, and so on. During each move, the current player must choose two different adjacent ch... | int solution()
{
int t;
scanf("%d", &t);
while (t--) {
char s[144] = {0};
int one = 0;
int zero = 0;
scanf("%s", s);
for (int i = 0; s[i] != '\0'; i++) {
if (s[i] == '1') {
one++;
} else {
zero++;
}
}
if ((one > zero && zero % 2 == 0) || (zero >= one ... | 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 cs: Vec<char> = lines.next().unwrap().unwrap().chars().collect();
let zeros = cs.iter().filter(|&&c| c == '0').count();
... | easy |
1159 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>A sequence <var>a_1,a_2,... ,a_n</var> is said to be /\/\/\/ when the following conditions are satisfied:</p>
<ul>
<li>For each <var>i = 1,2,..., n-2</var>, <var>a_i = a_{i+2}</var>.</li>
<li>Exactly tw... | int solution(void) {
int n;
int v[100000];
int v1[100000] = {0};
int pv1 = 0;
int pv2 = 0;
int pv2_2 = 0;
int pv1_2 = 0;
int v2[100000] = {0};
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &v[i]);
if (i % 2 == 0) {
v2[v[i]]++;
if (v2[pv2] < v2[v[i]]) {
pv2_... | fn solution() {
let mut buf: String = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
let n: usize = buf.trim().parse::<usize>().unwrap();
let mut v1: Vec<usize> = vec![0; 100001];
let mut v2: Vec<usize> = vec![0; 100001];
let mut buf: String = String::new();
std::io::stdin().r... | medium |
1160 | William really likes the cellular automaton called "Game of Life" so he decided to make his own version. For simplicity, William decided to define his cellular automaton on an array containing $$$n$$$ cells, with each cell either being alive or dead.Evolution of the array in William's cellular automaton occurs iterativ... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int a;
int b;
int dk;
scanf("%d%d", &a, &b);
char s[a];
int n[a];
for (int i = 0; i < a; i++) {
n[i] = 0;
}
scanf("%s", s);
while (b--) {
dk = 0;
for (int i = 0; i < a; i++) {
if (s[i] == '1' &... | fn solution() {
let std_in = stdin();
let in_lock = std_in.lock();
let input = BufReader::new(in_lock);
let std_out = stdout();
let out_lock = std_out.lock();
let mut output = BufWriter::new(out_lock);
let mut lines = input.lines().map(|r| r.unwrap());
let t = lines.next().unwrap().pa... | medium |
1161 | <H1>Debt Hell</H1>
<p>
Your friend who lives in undisclosed country is involved in debt. He is borrowing 100,000-yen from a loan shark. The loan shark adds 5% interest of the debt and rounds it to the nearest 1,000 above week by week.
</p>
<p>
Write a program which computes the amount of the debt in <var>n</var> week... | int solution() {
int n = 0;
int awia = 100000;
scanf("%d", &n);
while (--n >= 0) {
awia += awia * 0.05;
if (awia % 1000) {
awia = (awia / 1000 * 1000) + 1000;
}
}
printf("%d\n", awia);
return 0;
} | fn solution() {
let mut debt = 100000;
let mut buf = String::new();
if let Ok(_) = stdin().read_line(&mut buf) {
let week: u32 = buf.trim().parse::<u32>().unwrap();
for _ in 1..week + 1 {
let interest = debt * 5 / 100;
debt += (interest / 1000) * 1000;
if ... | medium |
1162 | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.However, all is not l... | int solution() {
int n;
char S[100010];
while (scanf("%d", &n) != EOF) {
int con[2] = {0};
int count = 1;
scanf("%s", S);
for (int i = 1; i < n; i++) {
if (S[i - 1] == S[i]) {
con[S[i] - '0']++;
} else if (S[i - 1] != S[i]) {
count++;
}
if (i - 3 >= 0 && S[i... | fn solution() {
let stdin = io::stdin();
let mut iter = stdin.lock().lines();
iter.next().unwrap().unwrap();
let line = iter.next().unwrap().unwrap();
let (n, v) = line.bytes().fold((0, vec![]), |(n, mut v), c| {
v.push(c == 49);
(n + 1, v)
});
println!(
"{}",
... | hard |
1163 | The robot is located on a checkered rectangular board of size $$$n \times m$$$ ($$$n$$$ rows, $$$m$$$ columns). The rows in the board are numbered from $$$1$$$ to $$$n$$$ from top to bottom, and the columns — from $$$1$$$ to $$$m$$$ from left to right.The robot is able to move from the current cell to one of the four c... | int solution() {
int n;
int m;
int i;
int j;
int t;
int up;
int down;
int right;
int left;
int row;
int column;
int h;
int v;
scanf("%d", &t);
char s[1000000 + 1];
for (j = 0; j < t; j++) {
up = 0;
down = 0;
right = 0;
left = 0;
column = 0;
row = 0;
scanf("%d%... | fn solution() {
let mut input = String::new();
stdin().read_to_string(&mut input).unwrap();
let mut input = input.split_ascii_whitespace();
let t: u64 = input.next().unwrap().parse().unwrap();
'main_loop: for _ in 0..t {
let rows: i64 = input.next().unwrap().parse().unwrap();
let co... | medium |
1164 | <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> students and <var>M</var> checkpoints on the <var>xy</var>-plane.<br/>
The coordinates of the <var>i</var>-th student <var>(1 \leq i \leq N)</var> is <var>(a_i,b_i)</var>, and the... | int solution() {
int a;
int b;
scanf("%d %d", &a, &b);
int vetor[2 * a];
int vet[2 * b];
for (int x = 0; x < 2 * a; ++x) {
scanf("%d", &vetor[x]);
}
for (int z = 0; z < 2 * b; ++z) {
scanf("%d", &vet[z]);
}
for (int f = 0; f < 2 * a; f += 2) {
int val = 0;
int v = 1000000000;
in... | fn solution() {
let mut is = String::new();
stdin().read_line(&mut is).ok();
let mut itr = is.split_whitespace().map(|e| e.parse::<i64>().unwrap());
let n = itr.next().unwrap();
let m = itr.next().unwrap();
let mut x = vec![];
let mut y = vec![];
for _ in 0..n {
let mut is = Str... | hard |
1165 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given <var>N</var> items.<br/>
The <em>value</em> of the <var>i</var>-th item <var>(1 \leq i \leq N)</var> is <var>v_i</var>.<br/>
Your have to select at least <var>A</var> and at most <var>B</v... | int solution(void) {
int n;
int l;
int r;
scanf("%i %i %i", &n, &l, &r);
unsigned long long a[n];
for (int i = 0; i < n; i++) {
scanf("%llu", &a[i]);
}
for (int i = 0; i < n; i++) {
int min_idx = i;
for (int j = i + 1; j < n; j++) {
if (a[min_idx] > a[j]) {
min_idx = j;
... | fn solution() {
input! {
N: usize,
A: usize,
B: usize,
V: [u64; N],
}
let mut V = V;
V.sort();
V.reverse();
let mut total = 0;
for i in 0..A {
total += V[i];
}
let ans1 = (total as f64) / (A as f64);
let mut cnt0 = 0;
let mut cnt1 = 0... | hard |
1166 | Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbers in which the array could be split. For example, the awesomeness of an arra... | int solution() {
long long int n;
long long int m;
scanf("%lld %lld", &n, &m);
long long int a[n];
long long int total = 0;
long long int ind = 1;
long long int b[n];
long long int t1 = 0;
long long int t2 = 0;
for (long long int i = 0; i < n; i++) {
scanf("%lld", &a[i]);
}
for (long long i... | fn solution() -> io::Result<()> {
let stdin_ = io::stdin();
let mut stdin = stdin_.lock();
let stdout_ = io::stdout();
let mut stdout = BufWriter::new(stdout_.lock());
let mut buf = String::new();
stdin.read_line(&mut buf)?;
let toks: Vec<&str> = buf.split_whitespace().collect();
let N:... | medium |
1167 | You are given an array consisting of $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$. Initially $$$a_x = 1$$$, all other elements are equal to $$$0$$$.You have to perform $$$m$$$ operations. During the $$$i$$$-th operation, you choose two indices $$$c$$$ and $$$d$$$ such that $$$l_i \le c, d \le r_i$$$, and swap ... | int solution() {
int t;
int n;
int x;
int m;
int i;
int l;
int r;
int l_v = -1;
int r_v = -1;
int flag = 0;
scanf("%d", &t);
while (t--) {
scanf("%d %d %d", &n, &x, &m);
flag = 0;
l_v = -1;
r_v = -1;
for (i = 1; i <= m; i++) {
scanf("%d %d", &l, &r);
if (x >= l &&... | fn solution() {
let stdin = io::stdin();
let mut buffer = String::with_capacity(32);
stdin.read_line(&mut buffer).unwrap();
let t: i32 = buffer.trim_end().parse().unwrap();
for _ in 0..t {
buffer.clear();
stdin.read_line(&mut buffer).unwrap();
let data = buffer
... | medium |
1168 | Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them.The tree looks like a polyline on the plane, consisting of ... | int solution() {
long long n;
long long a[10000] = {0};
long long b;
long long sum = 0;
long long d = 0;
long long e = 0;
scanf("%lld", &n);
for (int i = 0; i < n; i++) {
scanf("%lld", &b);
a[b]++;
sum += b;
}
for (int i = 0;; i++) {
if (a[i] == n) {
d = n / 2 * i;
} else {... | fn solution() {
let mut _input = String::new();
io::stdin()
.read_line(&mut _input)
.expect("failed to read input");
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("failed to read input");
let mut sticks: Vec<u64> = input
.split_wh... | hard |
1169 | Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The ... | int solution() {
int n = 0;
scanf("%i", &n);
int l = 0;
int cartas[n];
for (l = 0; l < n; l++) {
scanf("%i", &cartas[l]);
}
int sd[2] = {0};
int inicio = 0;
int fim = n - 1;
for (l = 0; l < n; l++) {
if (cartas[inicio] > cartas[fim]) {
sd[l % 2] += cartas[inicio];
inicio++;
... | fn solution() {
use std::io;
let mut buf = String::new();
io::stdin().read_line(&mut buf).unwrap();
let n = buf.trim().parse::<u32>().unwrap();
buf.clear();
io::stdin().read_line(&mut buf).unwrap();
let ns: Vec<u32> = buf
.split(" ")
.map(|str| str.trim().parse::<u32>().unwra... | medium |
1170 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a grid with <var>N</var> rows and <var>M</var> columns of squares. Initially, all the squares are white.</p>
<p>There is a button attached to each row and each column.
When a button attached to ... | int solution(void) {
int n = 0;
int m = 0;
int k = 0;
int ans = 0;
scanf("%d %d %d", &n, &m, &k);
for (int a = 0; a <= n && ans == 0; a++) {
for (int b = 0; b <= m && ans == 0; b++) {
if ((a * m - 2 * a * b + b * n) == k) {
ans = 1;
break;
}
}
}
if (ans) {
pri... | fn solution() {
let mut string = String::new();
io::stdin().read_line(&mut string).expect("read error");
let int_vec: Vec<u32> = string
.trim()
.split(" ")
.map(|x| x.parse::<u32>().expect("Not an integer!"))
.collect();
let m = min(int_vec[0], int_vec[1]);
let n = m... | medium |
1171 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a string <var>S</var> of length <var>N</var>.
Among its subsequences, count the ones such that all characters are different, modulo <var>10^9+7</var>. Two subsequences are considered diffe... | int solution() {
int n;
long mod = 1000000007;
scanf("%d\n", &n);
char a[n];
int b[26];
for (int i = 0; i < 26; ++i) {
b[i] = 0;
}
for (int i = 0; i < n; ++i) {
scanf("%c", &a[i]);
}
for (int i = 0; i < n; ++i) {
b[a[i] - 'a']++;
}
long answer = 1;
for (int i = 0; i < 26; ++i) {
... | fn solution() {
let mut st = String::new();
stdin().read_line(&mut st).unwrap();
let _n = st.trim().parse::<i32>().unwrap();
let mut st = String::new();
stdin().read_line(&mut st).unwrap();
let s: Vec<char> = st.trim().chars().collect();
let mut map: HashMap<&char, i64> = HashMap::new();
... | medium |
1172 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have an integer sequence <var>A</var>, whose length is <var>N</var>.</p>
<p>Find the number of the non-empty <strong>contiguous</strong> subsequences of <var>A</var> whose sums are <var>0</var>.
Note... | int solution() {
int i;
int N;
long long A[200001] = {};
scanf("%d", &N);
for (i = 1; i <= N; i++) {
scanf("%lld", &(A[i]));
}
long long h;
list *p;
list data[200001] = {};
list *hash[100003] = {&(data[0])};
for (i = 1; i <= N; i++) {
data[i].value = data[i - 1].value + A[i];
for (h =... | 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 ary: Vec<i64> = vec![0; n];
for i in 0..n {
ary[i] = iter.next().unwrap().parse().unwrap()... | medium |
1173 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a tree with <var>N</var> vertices.<br/>
Here, a <em>tree</em> is a kind of graph, and more specifically, a connected undirected graph with <var>N-1</var> edges, where <var>N</var> is the n... | int solution() {
long long n;
long long i;
long long a;
long long b;
long long c;
long long d[100010];
long long f[100010] = {};
int ta[100010];
int co[200010];
int nt[200010];
int to[200010];
int t;
int r;
int m;
int q[100010];
scanf("%lld", &n);
for (i = 0; i < n; i++) {
ta[i + 1... | fn solution() {
input! {
n: usize,
es: [(usize1, usize1, usize); n - 1],
q: usize,
k: usize1,
qs: [(usize1, usize1); q]
}
let mut t = vec![vec![]; n];
for &(a, b, c) in &es {
t[a].push((b, c));
t[b].push((a, c));
}
let mut d = vec![1 << 60;... | hard |
1174 | There are $$$n$$$ cats in a line, labeled from $$$1$$$ to $$$n$$$, with the $$$i$$$-th cat at position $$$i$$$. They are bored of gyrating in the same spot all day, so they want to reorder themselves such that no cat is in the same place as before. They are also lazy, so they want to minimize the total distance they mo... | int solution() {
int k = 0;
int n = 0;
scanf("%d", &k);
for (int i = 1; i <= k; i++) {
scanf("%d", &n);
if (n % 2 == 0) {
for (int j = 2; j <= n; j += 2) {
printf("%d ", j);
printf("%d ", j - 1);
}
} else {
printf("3 1 2 ");
for (int j = 5; j <= n; j += 2) {
... | fn solution() {
let (i, o) = (io::stdin(), io::stdout());
let mut o = bw::new(o.lock());
for l in i.lock().lines().skip(1) {
let n: u32 = l.unwrap().parse().unwrap();
let mut x = 1;
let mut r = String::new();
if !n.is_multiple_of(2) {
write!(r, "3 1 2 ").ok();
... | medium |
1175 | You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during $$$n$$$ consecutive days. During the $$$i$$$-th day you have to write exactly $$$a_i$$$ names.". You got sc... | int solution() {
int n;
int m;
int s = 0;
scanf("%d %d", &n, &m);
int a[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i < n; i++) {
s += a[i];
printf("%d ", s / m);
s = s % 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 s = buffer
.split_whitespace()
.map(|x| x.parse::<i32>().unwrap())
.collect::<Vec<i32>>();
let mut it = s.iter();
... | medium |
1176 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi loves takoyaki - a ball-shaped snack.</p>
<p>With a takoyaki machine, he can make at most <var>X</var> pieces of takoyaki at a time, taking <var>T</var> minutes regardless of the number of pie... | int solution(void) {
int i = 0;
int a[100] = {0};
int kara = 0;
int k = 0;
int tya = 0;
for (i = 0; i < 3; i++) {
scanf("%d", &a[i]);
}
if (a[1] >= a[0]) {
printf("%d", a[2]);
} else if (a[1] < a[0]) {
if (a[1] > 1) {
i = 0;
while (a[0] >= a[1]) {
a[0] = a[0] - a[1];
... | 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 x: usize = iter.next().unwrap().parse().unwrap();
let t: usize = iter.next().unwrap().parse().unwra... | hard |
1177 | Mihai has an $$$8 \times 8$$$ chessboard whose rows are numbered from $$$1$$$ to $$$8$$$ from top to bottom and whose columns are numbered from $$$1$$$ to $$$8$$$ from left to right.Mihai has placed exactly one bishop on the chessboard. The bishop is not placed on the edges of the board. (In other words, the row and co... | int solution(void) {
int t;
scanf("%d", &t);
char s[8][8];
while (t--) {
scanf("\n\n");
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
scanf("%c", &s[i][j]);
}
scanf("\n");
}
int ans = 0;
for (int i = 1; i < 7; i++) {
for (int j = 1; j < 7; j++) {... | fn solution() {
let stdin = std::io::stdin();
let mut buffer = String::new();
stdin.read_line(&mut buffer).unwrap();
let count: u32 = buffer.trim().parse().unwrap();
for _ in 0..count {
stdin.read_line(&mut buffer).unwrap();
let mut candidate_x = 0;
let mut candidate_y = 0... | medium |
1178 | Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a studen... | int solution() {
int n;
int arr[5001];
int arr2[5001];
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d %d", &arr[i], &arr2[i]);
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (arr[j] < arr[i]) {
int x = arr[i];
arr[i] = arr[j];
arr[j]... | fn solution() {
let mut n = String::new();
stdin().read_line(&mut n).unwrap();
let n: i16 = n.trim().parse().unwrap();
let mut input = Vec::<Vec<i32>>::new();
for _ in 0..n {
let mut s = String::new();
stdin().read_line(&mut s).unwrap();
let words: Vec<i32> = s.split_white... | hard |
1179 | There is a string $$$s$$$ of length $$$3$$$, consisting of uppercase and lowercase English letters. Check if it is equal to "YES" (without quotes), where each letter can be in any case. For example, "yES", "Yes", "yes" are all allowable. | int solution() {
int t;
scanf("%d", &t);
while (t--) {
char s[4];
scanf("%s", s);
if ((s[0] == 'y' || s[0] == 'Y') && (s[1] == 'e' || s[1] == 'E') &&
(s[2] == 's' || s[2] == 'S')) {
printf("YES\n");
} else {
printf("NO\n");
}
}
return 0;
} | fn solution() {
std::io::stdin().lines().skip(1).flatten().for_each(|s| {
if let &[a, b, c] = s.as_bytes() {
if [a | b' ', b | b' ', c | b' '] == [b'y', b'e', b's'] {
println!("YES");
} else {
println!("NO");
}
};
});
} | easy |
1180 | Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a ≤ x ≤ b and x is divisible by k. | int solution() {
long long int a;
long long int b;
long long int k;
long long int r;
long long int ra;
long long int rb;
long long int temp;
scanf("%lli", &k);
scanf("%lli", &a);
scanf("%lli", &b);
if (k != 0) {
if (b > 0) {
if (a == b) {
if (k > llabs(b)) {
r = 0;
... | fn solution() {
let mut line = String::new();
io::stdin().read_line(&mut line).unwrap();
let mut line = line.split_whitespace();
let k: u64 = line.next().unwrap().parse().unwrap();
let a: i64 = line.next().unwrap().parse().unwrap();
let b: i64 = line.next().unwrap().parse().unwrap();
let f... | easy |
1181 | Luca has a cypher made up of a sequence of $$$n$$$ wheels, each with a digit $$$a_i$$$ written on it. On the $$$i$$$-th wheel, he made $$$b_i$$$ moves. Each move is one of two types: up move (denoted by $$$\texttt{U}$$$): it increases the $$$i$$$-th digit by $$$1$$$. After applying the up move on $$$9$$$, it becomes ... | int solution() {
int n;
scanf("%d", &n);
int a[100];
int b[100][100];
b[0][3] = 1;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
for (int j = 0; j < a[i]; j++) {
scanf("%d", &b[i][j]);
}
for (int j = 0; j < a[i]; j++) {
int c[100][100];
scanf("%d", &c[i][j]);
for... | fn solution() {
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
let t: i32 = input.trim().parse().unwrap();
for _ in 0..t {
input.clear();
io::stdin().read_line(&mut input).unwrap();
let n: usize = input.trim().parse().unwrap();
input.clear();
... | hard |
1182 | Some number of people (this number is even) have stood in a circle. The people stand in the circle evenly. They are numbered clockwise starting from a person with the number $$$1$$$. Each person is looking through the circle's center at the opposite person. A sample of a circle of $$$6$$$ persons. The orange arrows ... | int solution() {
int t;
scanf("%d", &t);
int a[t];
int b[t];
int c[t];
for (int i = 0; i < t; i++) {
scanf("%d%d%d", &a[i], &b[i], &c[i]);
}
int ans[t];
for (int i = 0; i < t; i++) {
int ab = abs(a[i] - b[i]);
if (2 * ab < c[i] || 2 * ab < a[i] || 2 * ab < b[i]) {
ans[i] = -1;
... | fn solution() {
let (i, o) = (io::stdin(), io::stdout());
let mut o = bw::new(o.lock());
for l in i.lock().lines().skip(1) {
if let [a, b, c] = l
.unwrap()
.split(' ')
.map(|w| w.parse::<i32>().unwrap())
.collect::<Vec<_>>()[..]
{
l... | easy |
1183 | <span class="lang-en">
<p>Score : <var>200</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. Determine whether all the characters in <var>S</var> are different.</p>
</section>
</div>
<div class="part">
<section>
<h3>Co... | int solution(void) {
char S[100];
scanf("%s\n", S);
int tbl[26];
memset(tbl, 0, sizeof(tbl));
char *p = S;
while (*p) {
int index = (*p) - 'a';
if (tbl[index] > 0) {
printf("no\n");
return 0;
}
tbl[index]++;
p++;
}
printf("yes\n");
return 0;
} | fn solution() {
let mut buf = String::new();
io::stdin().read_line(&mut buf).expect("");
let s: Vec<char> = buf.trim().chars().collect();
let mut set = HashSet::new();
let mut flag = true;
for i in s {
if !set.insert(i) {
flag = false;
println!("no");
... | medium |
1184 | A sequence of $$$n$$$ numbers is called permutation if it contains all numbers from $$$1$$$ to $$$n$$$ exactly once. For example, the sequences $$$[3, 1, 4, 2]$$$, [$$$1$$$] and $$$[2,1]$$$ are permutations, but $$$[1,2,1]$$$, $$$[0,1]$$$ and $$$[1,3,4]$$$ are not.For a given number $$$n$$$ you need to make a permutati... | int solution(void) {
int n = 0;
int number = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &number);
if (number == 3) {
printf("-1\n");
} else {
printf("%d %d", number, number - 1);
for (int j = 1; j <= number - 2; j++) {
printf(" %d", j);
}
prin... | fn solution() {
let mut tests = String::new();
io::stdin().read_line(&mut tests).unwrap();
let tests = tests.trim().parse().unwrap();
for _ in 0..tests {
let mut testline = String::new();
io::stdin().read_line(&mut testline).unwrap();
let length = testline.trim().parse().unwrap(... | medium |
1185 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>The word <code>internationalization</code> is sometimes abbreviated to <code>i18n</code>.
This comes from the fact that there are <var>18</var> letters between the first <code>i</code> and the last <cod... | int solution(void) {
char s[101] = {0};
char n[256] = {0};
char r[256] = {0};
int len = 0;
int sum = 0;
scanf("%s", s);
len = strlen(s);
if (3 <= len && len <= 100) {
int len_tmp = 0;
sum = len - 2;
sprintf(n, "%d", sum);
r[0] = s[0];
strncpy(&r[1], &n[0], strlen(n));
len_tmp ... | fn solution() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
let len = s.trim().len();
let ss = s.chars().collect::<Vec<char>>();
println!("{}{}{}", ss[0], len - 2, ss[len - 1]);
} | hard |
1186 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given sequences <var>A</var> and <var>B</var> consisting of non-negative integers.
The lengths of both <var>A</var> and <var>B</var> are <var>N</var>, and the sums of the elements in <var>A</var... | int solution(void) {
int N;
scanf("%d", &N);
long long int a[N];
long long int b[N];
long long int ans = 0;
long long int min = 1000000007;
int zero = 1;
for (int i = 0; i < N; i++) {
scanf("%lld %lld", &a[i], &b[i]);
if (a[i] != b[i]) {
zero = 0;
}
ans += b[i];
if (a[i] > b[i]... | 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, B): (Vec<i64>, Vec<i64>) = {
let (mut A, mut B) = (vec![], vec![]);
for _ in 0..N {
let mut line:... | medium |
1187 | There is a grid with $$$n$$$ rows and $$$m$$$ columns. Some cells are colored black, and the rest of the cells are colored white.In one operation, you can select some black cell and do exactly one of the following: color all cells in its row black, or color all cells in its column black. You are given two integers $... | int solution() {
int t;
scanf("%d", &t);
for (int x = 0; x < t; x++) {
int n;
int m;
int a;
int b;
scanf("%d", &n);
scanf("%d", &m);
scanf("%d", &a);
scanf("%d", &b);
char arr[n][m];
int z = 0;
int y = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m;... | fn solution() {
let mut handle = io::BufWriter::new(io::stdout());
let mut test_no = String::new();
io::stdin().read_line(&mut test_no).unwrap();
let test_no = test_no.trim().parse().unwrap();
let mut loop_count = 0;
loop {
loop_count += 1;
let mut numberstr = String::new();
... | medium |
1188 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>An integer <var>N</var> is a multiple of <var>9</var> if and only if the sum of the digits in the decimal representation of <var>N</var> is a multiple of <var>9</var>.</p>
<p>Determine whether <var>N</v... | int solution() {
char x[1];
long long count = 0;
scanf("%c", &x[0]);
while (x[0] != 10 && x[0] != ' ') {
count += x[0] - 48;
scanf("%c", &x[0]);
}
if (count % 9 == 0) {
printf("Yes\n");
} else {
printf("No\n");
}
return 0;
} | fn solution() {
let mut buf = String::new();
std::io::stdin()
.read_line(&mut buf)
.expect("failed to read");
let r: u32 = buf
.trim()
.chars()
.fold(0, |r, c| (c.to_digit(10).unwrap() + r) % 9);
println!("{}", if r == 0 { "Yes" } else { "No" })
} | easy |
1189 | You are given an integer $$$k$$$ and a string $$$s$$$ that consists only of characters 'a' (a lowercase Latin letter) and '*' (an asterisk).Each asterisk should be replaced with several (from $$$0$$$ to $$$k$$$ inclusive) lowercase Latin letters 'b'. Different asterisk can be replaced with different counts of letter 'b... | int solution() {
int n;
scanf("%d", &n);
int *a = malloc(10000);
int *b = malloc(10000);
char *c = malloc(5000);
char *d = malloc(5000000);
for (int n1 = 0; n1 < n; n1++) {
int l;
long long k;
long long x;
scanf("%d %lld %lld", &l, &x, &k);
k--;
scanf("%s", c);
int b0 = 0;
... | fn solution() {
let stdin = io::stdin();
let mut lines = stdin.lock().lines();
let t: usize = lines.next().unwrap().unwrap().parse().unwrap();
for _ in 0..t {
let xs: Vec<usize> = lines
.next()
.unwrap()
.unwrap()
.split(' ')
.map(|x| x... | hard |
1190 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has <var>N</var> strings. The <var>i</var>-th string is <var>s_i</var>.</p>
<p>Let us concatenate these strings into one string after arranging them in some order.
Find the maximum possible number... | int solution() {
int numOfStrings;
scanf("%d", &numOfStrings);
int numBxA = 0;
int numBeginB = 0;
int numEndA = 0;
int numAB = 0;
char str[11] = {0};
for (int i = 0; i < numOfStrings; i++) {
scanf("%s", str);
int len = strlen(str);
if (str[0] == 'B' && str[len - 1] == 'A') {
numBxA++... | fn solution() {
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).ok();
let mut it = buf.split_whitespace();
let n = it.next().unwrap().parse::<usize>().unwrap();
let s = (0..n).map(|_| it.next().unwrap()).collect::<Vec<_>>();
let mut res = 0;
let mut cnt_a = 0;
let ... | medium |
1191 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a string <var>S</var>. Each character of <var>S</var> is uppercase or lowercase English letter.
Determine if <var>S</var> satisfies all of the following conditions:</p>
<ul>
<li>The initia... | int solution() {
char s[11];
scanf("%s", s);
if (s[0] != 'A') {
printf("WA");
return 0;
}
int len = strlen(s);
int count = 0;
int i = 1;
while (s[i]) {
if (i >= 2 && i <= len - 2) {
if (s[i] == 'C') {
count++;
}
if (s[i] != 'C' && s[i] >= 'A' && s[i] <= 'Z') {
... | fn solution() {
let mut input = String::new();
io::stdin().read_line(&mut input).ok();
let input = input.trim();
let len = input.len();
let mut input = input.chars();
let mut i = 0;
let mut countC = 0;
let mut countU = 0;
let mut ans = true;
loop {
i += 1;
let ... | easy |
1192 | Rot13 | void solution(char *s) {
for (int i = 0; s[i]; i++) {
if (s[i] >= 'A' && s[i] <= 'Z') {
s[i] = 'A' + ((s[i] - 'A' + 13) % 26);
} else if (s[i] >= 'a' && s[i] <= 'z') {
s[i] = 'a' + ((s[i] - 'a' + 13) % 26);
}
}
}
| fn solution(text: &str) -> String {
let to_enc = text.to_uppercase();
to_enc
.chars()
.map(|c| match c {
'A'..='M' => ((c as u8) + 13) as char,
'N'..='Z' => ((c as u8) - 13) as char,
_ => c,
})
.collect()
} | medium |
1193 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is a positive integer <var>N</var>.</p>
<p>We will choose an integer <var>K</var> between <var>2</var> and <var>N</var> (inclusive), then we will repeat the operation below until <var>N</var> beco... | int solution() {
long n;
scanf("%ld", &n);
if (n == 2) {
printf("1\n");
return 0;
}
long ans = 2;
for (long i = 2; i * i <= n; i++) {
if (i * i == n - 1) {
ans++;
} else if ((n - 1) % i == 0) {
ans += 2;
}
if (n % i != 0) {
continue;
}
long p = n / i;
lo... | fn solution() {
let n: usize = {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
buf.trim_end().parse().unwrap()
};
let mut ans = 0;
{
let mut k = 1;
while k * k < n {
if (n - 1).is_multiple_of(k) {
ans += ... | easy |
1194 | <H1>QQ</H1>
<p>
Write a program which prints multiplication tables in the following format:
</p>
<pre>
1x1=1
1x2=2
.
.
9x8=72
9x9=81
</pre>
<H2>Input</H2>
<p>
No input.
</p>
<H2>Output</H2>
<pre>
1x1=1
1x2=2
.
.
9x8=72
9x9=81
</pre>
<H2>Template for C</H2>
<pre>
#include<stdio.h>
int main(){
retur... | int solution(void) {
int i = 0;
int j = 0;
for (i = 1; i < 10; i++) {
for (j = 1; j < 10; j++) {
if (i == 9 && j == 10) {
break;
}
printf("%dx%d=%d\n", i, j, i * j);
}
}
return 0;
} | fn solution() {
let mut i = 1;
let mut j = 1;
let _done = false;
while i != 10 {
while j != 10 {
println!("{}x{}={}", i, j, i * j);
j += 1;
}
j = 1;
i += 1;
}
} | easy |
1195 | Odd even sort | void solution(int *arr, int size) {
bool isSorted = false;
while (!isSorted) {
isSorted = true;
for (int i = 0; i <= size - 2; i += 2) {
if (arr[i] > arr[i + 1]) {
int temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
isSorted = false;
}
}
for (in... | fn solution<T: Ord>(arr: &mut [T]) {
let len = arr.len();
if len == 0 {
return;
}
let mut sorted = false;
while !sorted {
sorted = true;
for i in (1..len - 1).step_by(2) {
if arr[i] > arr[i + 1] {
arr.swap(i, i + 1);
sorted = fals... | easy |
1196 | In Aramic language words can only represent objects.Words in Aramic have special properties: A word is a root if it does not contain the same letter more than once. A root and all its permutations represent the same object. The root $$$x$$$ of a word $$$y$$$ is the word that contains all letters that appear in $$$y... | int solution() {
int n;
int j = 0;
int g = 0;
int u = 0;
char a;
char x[30];
char z[1000][30];
scanf("%d\n", &n);
for (int i = 0; i < n; i++) {
a = getchar(), memset(x, 0, 26);
while (a != ' ' && a != '\n') {
x[a - 97] = 1, a = getchar();
}
for (j = 0; j < u; j++) {
for (g ... | fn solution() {
use std::io;
use std::io::prelude::*;
let mut input = String::new();
io::stdin().read_to_string(&mut input).unwrap();
let mut it = input.split_whitespace();
let _n: usize = it.next().unwrap().parse().unwrap();
let f = |s: &str| -> usize {
let bl = s.as_bytes();
... | hard |
1197 | There are $$$n$$$ people participating in some contest, they start participating in $$$x$$$ minutes intervals. That means the first participant starts at time $$$0$$$, the second participant starts at time $$$x$$$, the third — at time $$$2 \cdot x$$$, and so on.Duration of contest is $$$t$$$ minutes for each participan... | int solution() {
int setsData;
scanf("%d", &setsData);
for (int i = 1; i <= setsData; i++) {
long long numberOfParticipants;
long long intervalBetweenStudents;
long long timeOfOlympiad;
scanf("%lld %lld %lld", &numberOfParticipants, &intervalBetweenStudents,
&timeOfOlympiad);
long ... | fn solution() {
let std_in = stdin();
let in_lock = std_in.lock();
let input = BufReader::new(in_lock);
let std_out = stdout();
let out_lock = std_out.lock();
let mut output = BufWriter::new(out_lock);
let mut lines = input.lines().map(|r| r.unwrap());
let s = lines.next().unwrap();
... | hard |
1198 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Akaki, a patissier, can make <var>N</var> kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts ... | int solution(void) {
static int n;
static int x;
static int min = 100000;
scanf("%d%d", &n, &x);
for (int i = 0; i < n; i++) {
int m[i];
scanf("%d", &m[i]);
x -= m[i];
if (min > m[i]) {
min = m[i];
}
}
printf("%d\n", n + (x / min));
return 0;
} | fn solution() {
let mut buf = String::new();
io::stdin().read_line(&mut buf).unwrap();
let mut iter = buf.split_whitespace();
let n = iter.next().unwrap().parse::<usize>().unwrap();
let x = iter.next().unwrap().parse::<i64>().unwrap();
let mut t = 0;
let mut num = 0;
let mut min = 1001;
... | easy |
1199 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has <var>N</var> sticks.
The length of the <var>i</var>-th stick is <var>l_i</var>.</p>
<p>Snuke is making a snake toy by joining <var>K</var> of the sticks together.</p>
<p>The length of the toy ... | int solution() {
int a;
int b;
int j = 0;
int ans = 0;
scanf("%d %d", &a, &b);
int l[a];
for (int i = 0; i < a; i++) {
scanf("%d", &l[i]);
}
for (int i = 0; i < a - 1; j++) {
if (l[j] < l[j + 1]) {
int t = l[j + 1];
l[j + 1] = l[j];
l[j] = t;
}
if (j + 3 > a) {
... | fn solution() {
let mut vec: Vec<usize> = Vec::new();
let stdin = io::stdin();
let mut buf = String::new();
stdin.read_line(&mut buf).ok();
let mut it = buf.split_whitespace().map(|n| usize::from_str(n).unwrap());
let (n, k) = (it.next().unwrap(), it.next().unwrap());
let mut buf = String:... | hard |
1200 | Bead sort | void solution(int *a, size_t len) {
int i, j, max, sum;
unsigned char *beads;
for (i = 1, max = a[0]; i < len; i++)
if (a[i] > max)
max = a[i];
beads = calloc(1, max * len);
for (i = 0; i < len; i++)
for (j = 0; j < a[i]; j++)
beads[i * max + j] = 1;
for (j = 0; j < max; j++) {
... | fn solution(a: &mut [usize]) {
let mut max = a[0];
(1..a.len()).for_each(|i| {
if a[i] > max {
max = a[i];
}
});
let mut beads = vec![vec![0; max]; a.len()];
for i in 0..a.len() {
for j in (0..a[i]).rev() {
beads[i][j] = 1;
}
}
for j... | easy |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.