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 |
|---|---|---|---|---|
1601 | Stanley defines the beauty of an array $$$a$$$ of length $$$n$$$, which contains non-negative integers, as follows: $$$$$$\sum\limits_{i = 1}^{n} \left \lfloor \frac{a_{i}}{k} \right \rfloor,$$$$$$ which means that we divide each element by $$$k$$$, round it down, and sum up the resulting values.Stanley told Sam the in... | int solution() {
int t;
int i;
int j;
long long n[1005];
long long k[1005];
long long b[1005];
long long s[1005];
long long left;
scanf("%d", &t);
for (i = 1; i <= t; i++) {
scanf("%lld%lld%lld%lld", &n[i], &k[i], &b[i], &s[i]);
}
for (i = 1; i <= t; i++) {
if (s[i] >= (k[i] * b[i]) &&
... | fn solution() {
let mut buf = String::new();
stdin().read_line(&mut buf).unwrap();
let t: u32 = buf.trim().parse().unwrap();
buf.clear();
let mut out = String::new();
for _ in 0..t {
stdin().read_line(&mut buf).unwrap();
let inp: Vec<&str> = buf.split_whitespace().collect();
... | easy |
1602 | Given the integer $$$n$$$ — the number of available blocks. You must use all blocks to build a pedestal. The pedestal consists of $$$3$$$ platforms for $$$2$$$-nd, $$$1$$$-st and $$$3$$$-rd places respectively. The platform for the $$$1$$$-st place must be strictly higher than for the $$$2$$$-nd place, and the platform... | int solution(void) {
int testcase = 0;
scanf("%i", &testcase);
for (int i = 0; i < testcase; i++) {
int n = 0;
scanf("%i", &n);
int h1 = 0;
int h2 = 0;
int h3 = 0;
if (n % 3 == 0) {
h3 = (n / 3) - 1;
} else {
h3 = (n / 3) - 2;
}
if ((n % 3 == 2) || h3 == 0) {
... | fn solution() {
let mut buf = BufWriter::new(io::stdout().lock());
io::stdin()
.lines()
.skip(1)
.flatten()
.flat_map(|s| s.parse::<usize>())
.for_each(|n| {
let a = n.wrapping_add(1).wrapping_div(3);
let b = n.wrapping_add(5).wrapping_div(3);
... | hard |
1603 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>K</var> pieces of cakes.
Mr. Takahashi would like to eat one cake per day, taking <var>K</var> days to eat them all.</p>
<p>There are <var>T</var> types of cake, and the number of the cak... | int solution(void) {
int k;
int t;
scanf("%d %d", &k, &t);
int a[t];
for (int i = 0; i < t; i++) {
scanf("%d", &a[i]);
}
int max = 0;
for (int i = 0; i < t; i++) {
if (a[i] > max) {
max = a[i];
}
}
int answer = max - 1 - (k - max);
if (answer < 0) {
answer = 0;
}
printf(... | fn solution() {
let mut s: String = String::new();
std::io::stdin().read_to_string(&mut s).ok();
let mut itr = s.split_whitespace();
let _k: usize = itr.next().unwrap().parse().unwrap();
let t: usize = itr.next().unwrap().parse().unwrap();
let mut a: Vec<usize> = (0..t)
.map(|_| itr.next... | medium |
1604 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Find the largest integer that can be formed with exactly <var>N</var> matchsticks, under the following conditions:</p>
<ul>
<li>Every digit in the integer must be one of the digits <var>A_1, A_2, ..., A... | int solution() {
int n;
int m;
scanf("%d %d", &n, &m);
int i;
int j;
int k;
int a[10];
for (i = 0; i < m; i++) {
scanf("%d", &a[i]);
}
int c[10] = {1000000009, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int dp[10004][10];
for (i = 0; i < 10004; i++) {
for (j = 0; j < 10; j++) {
dp[i][j] = 0;
... | fn solution() {
let mut s: String = String::new();
std::io::stdin().read_to_string(&mut s).ok();
let mut itr = s.split_whitespace();
let n: usize = itr.next().unwrap().parse().unwrap();
let m: usize = itr.next().unwrap().parse().unwrap();
let a: Vec<usize> = (0..m)
.map(|_| itr.next().un... | hard |
1605 | <H1>Is it a Right Triangle?</H1>
<p>
Write a program which judges wheather given length of three side form a right triangle. Print "<span>YES</span>" if the given sides (integers) form a right triangle, "<span>NO</span>" if not so.
</p>
<H2>Input</H2>
<p>
Input consists of several data sets. In the first line, the n... | int solution(void) {
int kosu = 0;
int a = 0;
int b = 0;
int c = 0;
scanf("%d", &kosu);
for (; kosu > 0; --kosu) {
scanf("%d%d%d", &a, &b, &c);
if (a * a == b * b + c * c || b * b == a * a + c * c ||
c * c == a * a + b * b) {
puts("YES");
} else {
puts("NO");
}
a = ... | fn solution() {
let input = BufReader::new(stdin());
for line in input.lines() {
let mut values: Vec<u32> = line
.unwrap()
.split_whitespace()
.filter_map(|x| x.parse::<u32>().ok())
.collect();
if values.len() == 1 {
continue;
}... | hard |
1606 | <span class="lang-en">
<p>Score: <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p><var>N</var> programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most <var>9</var> contestants can participate in the finals.</p>
<p>The... | int solution() {
int m;
scanf("%d", &m);
int i;
long long int d[200005];
long long int c[200005];
for (i = 0; i < m; i++) {
scanf("%lld %lld", &d[i], &c[i]);
}
long long int ans = 0;
for (i = 0; i < m; i++) {
ans += c[i];
}
ans--;
long long int v = 0;
for (i = 0; i < m; i++) {
v +=... | fn solution() {
let M: usize = {
let mut line: String = String::new();
std::io::stdin().read_line(&mut line).unwrap();
line.trim().parse().unwrap()
};
let (d, c): (Vec<usize>, Vec<usize>) = {
let (mut d, mut c) = (vec![], vec![]);
for _ in 0..M {
let mut l... | medium |
1607 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a board with a <var>2 \times N</var> grid.
Snuke covered the board with <var>N</var> dominoes without overlaps.
Here, a domino can cover a <var>1 \times 2</var> or <var>2 \times 1</var> square.<... | int solution(void) {
int n;
scanf("%d", &n);
char s1[n];
char s2[n];
scanf("%s", s1);
scanf("%s", s2);
long long exp = 1;
int leftis2 = 0;
int leftis1 = 0;
for (int i = 0; i < n; i++) {
if (s1[i] == s2[i]) {
if (leftis1 == 1) {
exp *= 2;
} else if (leftis2 == 1) {
ex... | 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 s: Vec<char> = itr.next().unwrap().chars().collect();
let t: Vec<char> = itr.next().unwrap().chars().colle... | medium |
1608 | You are given two binary strings $$$x$$$ and $$$y$$$, which are binary representations of some two integers (let's denote these integers as $$$f(x)$$$ and $$$f(y)$$$). You can choose any integer $$$k \ge 0$$$, calculate the expression $$$s_k = f(x) + f(y) \cdot 2^k$$$ and write the binary representation of $$$s_k$$$ in... | int solution() {
int T;
char strX[100001];
char strY[100001];
scanf("%d", &T);
while (T--) {
scanf("%s %s", strX, strY);
int lenX = strlen(strX);
int lenY = strlen(strY);
int idxY = -1;
for (int i = lenY - 1; i >= 0; --i) {
if (strY[i] == '1') {
idxY = i;
break;
... | fn solution() {
let stdin = stdin();
let mut stdin = stdin.lock();
let t: usize = {
let mut string = String::new();
stdin.read_line(&mut string);
string
.split_ascii_whitespace()
.next()
.unwrap()
.parse()
.unwrap()
};
... | medium |
1609 | Polycarp was dismantling his attic and found an old floppy drive on it. A round disc was inserted into the drive with $$$n$$$ integers written on it.Polycarp wrote the numbers from the disk into the $$$a$$$ array. It turned out that the drive works according to the following algorithm: the drive takes one positive nu... | int solution() {
int t;
int n;
int m;
static long long a[200000] = {[0 ... 199999] = 0};
static long long ascA[200000] = {[0 ... 199999] = 0};
static long long x[200000] = {[0 ... 199999] = 0};
int ans;
int rm;
int upbound;
long long step;
long long lcnt;
scanf("%d", &t);
for (int i = 0; i < t... | 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 tc: usize = sc.next();
for _ in 0..tc {
let (n, q): (usize, usize) = (sc.next(), sc.next());
let arr: Vec<i64>... | hard |
1610 | <H1>How Many Divisors?</H2>
<p>
Write a program which reads three integers <var>a</var>, <var>b</var> and <var>c</var>, and prints the number of divisors of <var>c</var> between <var>a</var> and <var>b</var>.
</p>
<H2>Input</H2>
<p>
Three integers <var>a</var>, <var>b</var> and <var>c</var> are given in a line ... | int solution(void) {
int a = 0;
scanf("%d", &a);
int b = 0;
scanf("%d", &b);
int c = 0;
scanf("%d", &c);
int counter = 0;
for (int i = 1; i <= c; i++) {
if (c % i == 0) {
if (((c / i) >= a) && ((c / i) <= b)) {
counter++;
}
}
}
printf("%d\n", counter);
return 0;
... | fn solution() {
let v: Vec<u32> = {
let mut b = String::new();
let s = std::io::stdin();
s.read_line(&mut b).unwrap();
b.split_whitespace().flat_map(str::parse).collect()
};
println!(
"{}",
(v[0]..v[1] + 1).filter(|i| v[2].is_multiple_of(*i)).count()
);
} | hard |
1611 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><var>10^{10^{10}}</var> participants, including Takahashi, competed in two programming contests.
In each contest, all participants had distinct ranks from first through <var>10^{10^{10}}</var>-th.</p>
<... | int solution() {
int i;
int Q;
long long A;
long long B;
long long C;
long long ans;
scanf("%d", &Q);
for (i = 1; i <= Q; i++) {
scanf("%lld %lld", &A, &B);
C = (long long)sqrt(A * B);
ans = (C - 1) * 2;
if (C * (C + 1) < A * B) {
ans++;
} else if (C * C == A * B) {
ans--... | fn solution() {
input! {
q: usize,
v: [(usize, usize); q]
}
for &(a, b) in &v {
let x = min(a, b);
let y = max(a, b);
let mut l = 0;
let mut r = y;
while l + 1 < r {
let m = (l + r) / 2;
if m * m < x * y {
l = m;... | medium |
1612 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | int solution() {
int n;
int i;
int t[1005] = {0};
int g[1005];
int yer = 0;
int kontrol;
int k;
int j;
int max;
int sonuc;
int puan[1005] = {0};
char c[1005][35] = {0};
char s[1005][35];
scanf("%d", &n);
for (i = 0; i < n; i++) {
kontrol = 1;
scanf("%s %d", s[i], &g[i]);
for (j... | fn solution() -> Result<(), Box<dyn std::error::Error>> {
let stdin = std::io::stdin();
let stdin = stdin.lock();
let mut lines = stdin.lines();
let n = lines.next().unwrap()?.parse::<usize>().unwrap();
let mut a = Vec::<(String, i32)>::new();
let mut scores = HashMap::<String, i32>::new();
... | hard |
1613 | Recall that the sequence $$$b$$$ is a a subsequence of the sequence $$$a$$$ if $$$b$$$ can be derived from $$$a$$$ by removing zero or more elements without changing the order of the remaining elements. For example, if $$$a=[1, 2, 1, 3, 1, 2, 1]$$$, then possible subsequences are: $$$[1, 1, 1, 1]$$$, $$$[3]$$$ and $$$[... | int solution() {
int t = 0;
scanf("%d", &t);
while (t--) {
int size = 0;
long long int sum = 0;
scanf("%d", &size);
long long int arr[size];
for (int i = 1; i <= size; i++) {
scanf("%lld", &arr[i]);
}
arr[0] = -arr[1];
int j = 0;
int k = 1;
while (k <= size) {
... | fn solution() {
let mut s: String = String::new();
std::io::stdin().read_to_string(&mut s).ok();
let mut itr = s.split_whitespace();
let t: usize = itr.next().unwrap().parse().unwrap();
let mut out = Vec::new();
for _ in 0..t {
let n: usize = itr.next().unwrap().parse().unwrap();
... | medium |
1614 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>2N</var> squares arranged from left to right. You are given a string of length <var>2N</var> representing the color of each of the squares.</p>
<p>The color of the <var>i</var>-th square ... | int solution() {
long long int n;
scanf("%lld\n", &n);
char s[200005];
scanf("%s", s);
long long int p = 1e9 + 7;
long long int i;
long long int count = 0;
long long int ans = 1;
for (i = 1; i <= n; i++) {
ans = ans * i % p;
}
for (i = 0; i < 2 * n; i++) {
if (s[i] == 'B') {
if (coun... | fn solution() {
let N: i64 = {
let mut line: String = String::new();
std::io::stdin().read_line(&mut line).unwrap();
line.trim().parse().unwrap()
};
let S: Vec<char> = {
let mut line: String = String::new();
std::io::stdin().read_line(&mut line).unwrap();
line... | medium |
1615 | You are given an array $$$a$$$ of $$$n$$$ integers.You want to make all elements of $$$a$$$ equal to zero by doing the following operation exactly three times: Select a segment, for each number in this segment we can add a multiple of $$$len$$$ to it, where $$$len$$$ is the length of this segment (added integers can b... | int solution() {
long long int n;
scanf("%lld", &n);
int arr[n];
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
if (n == 1) {
printf("%d %d\n%d\n", 1, 1, -arr[0]);
printf("1 1\n0\n1 1\n0");
return 0;
}
printf("%d %lld\n", 1, n - 1);
for (int i = 0; i < n - 1; i++) {
printf(... | fn solution() {
let n: usize = {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
buf.trim_end().parse().unwrap()
};
let a: Vec<i64> = {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
let iter = buf.spli... | medium |
1616 | Alice and Bob are playing a game on an array $$$a$$$ of $$$n$$$ positive integers. Alice and Bob make alternating moves with Alice going first.In his/her turn, the player makes the following move: If $$$a_1 = 0$$$, the player loses the game, otherwise: Player chooses some $$$i$$$ with $$$2\le i \le n$$$. Then player de... | int solution() {
int t;
int n;
char c[10];
scanf("%d", &t);
while (t > 0) {
scanf("%d", &n);
int a[n];
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
for (int i = 1; i < n; ++i) {
if (a[0] <= a[i]) {
strcpy(c, "Bob");
} else {
strcpy(c, "Alice");
... | fn solution() {
let mut buf = BufWriter::new(io::stdout().lock());
io::stdin().lines().flatten().for_each(|s| {
let mut i = s.split_ascii_whitespace().flat_map(str::parse::<usize>);
if let Some(a) = i.next()
&& let Some(m) = i.min() {
writeln!(buf, "{}", if a > m { "A... | easy |
1617 | <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>H</var> horizontal rows and <var>W</var> vertical columns, and there are obstacles on some of the squares.</p>
<p>Snuke is going to choose one of the squares not occupied by an... | int solution() {
int h;
int w;
scanf("%d %d", &h, &w);
int field[2005][2005] = {0};
for (int i = 0; i < h; i++) {
char s[2005];
scanf("%s", s);
for (int j = 0; j < w; j++) {
if (s[j] == '#') {
field[i + 1][j + 1] = 1;
}
}
}
int tate[2020][2020] = {0};
for (int i = 1;... | fn solution() {
let (h, w) = {
let mut line = String::new();
std::io::stdin().read_line(&mut line).ok();
let mut integers = line.split_whitespace().map(|e| e.parse::<usize>().unwrap());
(integers.next().unwrap(), integers.next().unwrap())
};
let mut s: Vec<Vec<char>> = Vec::... | medium |
1618 | <span class="lang-en">
<p>Score: <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>You are an immigration officer in the Kingdom of AtCoder. The document carried by an immigrant has some number of integers written on it, and you need to check whether they meet certain criteria.</p>
<p... | int solution(void) {
int n = 0;
int a = 0;
int flag = 1;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a);
if (a % 2 == 0) {
if (a % 3 != 0 && a % 5 != 0) {
flag = 0;
}
}
}
if (flag == 1) {
printf("APPROVED");
} else {
printf("DENIED");
}
return... | fn solution() {
let mut number_count = String::new();
io::stdin().read_line(&mut number_count).unwrap();
number_count.pop();
let mut numbers = String::new();
io::stdin().read_line(&mut numbers).unwrap();
numbers.pop();
let numbers: Vec<u32> = numbers
.split(' ')
.map(|s| u32:... | easy |
1619 | <h3>改元</h3>
<p>平成31年4月30日をもって現行の元号である平成が終了し,その翌日より新しい元号が始まることになった.平成最後の日の翌日は新元号元年5月1日になる.</p>
<p>ACM-ICPC OB/OGの会 (Japanese Alumni Group; JAG) が開発するシステムでは,日付が和暦(元号とそれに続く年数によって年を表現する日本の暦)を用いて "平成 <i>y</i> 年 <i>m</i> 月 <i>d</i> 日" という形式でデータベースに保存されている.この保存形式は変更することができないため,JAGは元号が変更されないと仮定して和暦で表した日付をデータベースに保存し,出力の際に日付を正し... | int solution() {
int y;
int m;
int d;
char g[10];
while (1) {
scanf("%s%d%d%d", g, &y, &m, &d);
if (strcmp(g, "#") == 0) {
break;
}
if ((y == 31 && m > 4) || y > 31) {
printf("? %d %d %d\n", y - 30, m, d);
} else {
printf("%s %d %d %d\n", g, y, m, d);
}
}
return ... | fn solution() {
loop {
let reader = std::io::stdin();
let mut line = String::new();
let _r = reader.read_line(&mut line);
let vec: Vec<&str> = line.split_whitespace().collect();
let mut v = vec[0];
if v == "#" {
break;
} else {
let mut ... | medium |
1620 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In CODE FESTIVAL XXXX, there are <var>N+1</var> participants from all over the world, including Takahashi.</p>
<p>Takahashi checked and found that the <em>time gap</em> (defined below) between the local... | int solution() {
int n;
scanf("%d", &n);
int i;
int d[55];
for (i = 0; i < n; i++) {
scanf("%d", &d[i]);
}
d[n] = 0;
for (i = 0; i < n; i++) {
if (d[i] > d[i + 1]) {
d[i] ^= d[i + 1];
d[i + 1] ^= d[i];
d[i] ^= d[i + 1];
if (i > 0) {
i -= 2;
}
}
}
for... | 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 d: Vec<i32> = (0..n)
.map(|_| itr.next().unwrap().parse().unwrap())
.collect();
d.push... | medium |
1621 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is an integer <var>r</var>.</p>
<p>How many times is the area of a circle of radius <var>r</var> larger than the area of a circle of radius <var>1</var>?</p>
<p>It can be proved that the answer is... | int solution() {
int r = 0;
scanf("%d", &r);
printf("%d\n", r * r);
return 0;
} | fn solution() {
let mut buf = String::new();
io::stdin().read_line(&mut buf).ok();
let r = buf.trim().parse::<i32>().unwrap();
println!("{}", r * r);
} | easy |
1622 | <h1>休憩スペース (Refreshment Area)</h1>
<h2>問題</h2>
<p>
世界的なプログラミングコンテストが日本で開催されることになり,現在会場の設営が行われている.この会場は南北方向に N マス,東西方向に M マスのマス目状に区切られており,いくつかのマスには競技用の機材が置かれている.
</p>
<p>
このコンテストでは,選手が競技中に休憩するために,軽食や飲み物などを置いた休憩スペースを 1 箇所会場内に設けることになった.休憩スペースは南北方向または東西方向に連続した D マスでなければならない.ただし,機材の置かれたマス目に休憩スペースを設けることはできない.
</p>
<p>
会場... | int solution(void) {
int n;
int m;
int d;
int i;
int j;
int l;
int g = 0;
char a[300][300];
scanf("%d %d %d", &n, &m, &d);
for (i = 0; i < n; i++) {
scanf("%s", a[i]);
}
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
l = 0;
while (l <= d - 1) {
if (a[i + l][j] ==... | fn solution() {
let input = {
let mut buf = vec![];
stdin().read_to_end(&mut buf);
unsafe { String::from_utf8_unchecked(buf) }
};
let mut lines = input.splitn(2, '\n');
let (n, m, d) = {
let line = lines.next().unwrap();
let mut iter = line.split(' ').map(|s| s.p... | easy |
1623 | You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how... | int solution() {
int t;
int n[100];
scanf("%d", &t);
for (int i = 0; i < t; i++) {
scanf("%d", &n[i]);
}
for (int i = 0; i < t; i++) {
if (n[i] % 2 == 0) {
for (int j = 0; j < n[i] / 2; j++) {
printf("1");
}
} else {
printf("7");
for (int j = 0; j < (n[i] / 2) -... | fn solution() {
let stdin = io::stdin();
let mut lines = stdin.lock().lines();
let n = lines.next().unwrap().unwrap().parse::<usize>().unwrap();
let mut inputs = Vec::new();
for _ in 0..n {
let tmp = lines.next().unwrap().unwrap().parse::<usize>().unwrap();
inputs.push(tmp);
}
... | medium |
1624 | You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length ... | int solution(void) {
int ch = 0;
while (islower(ch) == 0) {
ch = getchar();
}
int prev = ch;
int next = ch;
while (prev == next && ch != '\n') {
prev = next;
next = ch;
ch = getchar();
}
if (prev != next) {
puts("YES");
putchar(prev);
putchar(next);
} else {
puts("NO");... | fn solution() {
let mut n = String::new();
std::io::stdin().read_line(&mut n).expect("");
let _n: i32 = n.trim().parse().expect("");
let mut s = String::new();
std::io::stdin().read_line(&mut s).expect("");
let s = String::from(s.trim());
let s: Vec<_> = s.chars().collect();
let mut l =... | medium |
1625 | Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.The killer starts with two potential victims on his first day, selects one of these two, kills selected vi... | int solution() {
char StrA[11];
char StrB[11];
char StrC[11];
char StrD[11];
int n;
scanf("%s %s", StrA, StrB);
scanf("%d", &n);
printf("%s %s\n", StrA, StrB);
while (n--) {
scanf("%s %s", StrC, StrD);
if (strcmp(StrC, StrA) == 0) {
memcpy(StrA, StrD, sizeof(StrA));
} else if (strcmp... | fn solution() {
let mut names = String::new();
let mut n = String::new();
io::stdin().read_line(&mut names).unwrap();
let mut iter = names.split_whitespace();
let mut a = iter.next().unwrap().to_string();
let mut b = iter.next().unwrap().to_string();
io::stdin().read_line(&mut n).unwrap();
... | hard |
1626 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N + 1</var> squares arranged in a row, numbered <var>0, 1, ..., N</var> from left to right.</p>
<p>Initially, you are in Square <var>X</var>.
You can freely travel between adjacent square... | int solution(void) {
static int n;
static int m;
static int x;
static int left;
static int right;
scanf("%d%d%d", &n, &m, &x);
for (int i = 0; i < m; i++) {
int a[i];
scanf("%d", &a[i]);
if (a[i] < x) {
left++;
} else {
right++;
}
}
if (left < right) {
prin... | fn solution() {
input! {
_n: usize,
m: usize,
x: u32,
a: [u32;m]
}
let mut l = 0;
let mut r = 0;
for i in a {
if i < x {
l += 1;
}
if i > x {
r += 1;
}
}
println!("{}", std::cmp::min(l, r));
} | medium |
1627 | A big football championship will occur soon! $$$n$$$ teams will compete in it, and each pair of teams will play exactly one game against each other.There are two possible outcomes of a game: the game may result in a tie, then both teams get $$$1$$$ point; one team might win in a game, then the winning team gets $$$3$... | int solution() {
int x;
int y;
int z;
int i;
int j;
int k;
int a;
int b;
int c;
int n;
int m;
int t;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
i = 1;
j = 2;
for (x = 1; x <= n; x++) {
for (y = x + 1; y <= n; y++) {
if (!(n & 1) && x == i && j == y) {
... | 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 tc: usize = sc.next();
for _ in 0..tc {
let n: i32 = sc.next();
let mut tot = n * (n - 1) / 2;
let mut... | hard |
1628 | You are given an array of integers $$$a$$$ of length $$$n$$$. The elements of the array can be either different or the same. Each element of the array is colored either blue or red. There are no unpainted elements in the array. One of the two operations described below can be applied to an array in a single step: eith... | int solution() {
int t;
scanf("%d", &t);
int n;
for (int i = 0; i < t; i++) {
scanf("%d", &n);
long long arr[n];
char str[n];
int inc[n + 1];
int dec[n + 1];
for (int j = 0; j < n; j++) {
scanf("%lld", &arr[j]);
inc[j] = 0;
dec[j] = 0;
}
dec[n] = 0;
inc[n] =... | 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: usize = it.next().unwra... | medium |
1629 | Given a sequence $$$a_1, a_2, \ldots, a_n$$$, find the minimum number of elements to remove from the sequence such that after the removal, the sum of every $$$2$$$ consecutive elements is even. | int solution() {
int num_case = 0;
scanf("%d", &num_case);
int nums = 0;
int number = 0;
int odd_cnt = 0;
for (int i = 0; i < num_case; i++) {
scanf("%d", &nums);
for (int j = 0; j < nums; j++) {
scanf("%d", &number);
if (number % 2) {
odd_cnt++;
}
}
if (odd_cnt < ... | fn solution() {
let stdin = stdin();
let mut count = String::new();
stdin.read_line(&mut count).unwrap();
let count: u32 = count.trim().parse().unwrap();
let mut data_read = String::new();
for _ in 0..count {
stdin.read_line(&mut data_read).unwrap();
data_read.clear();
... | medium |
1630 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a <var>3×3</var> square grid, where each square contains a lowercase English letters.
The letter in the square at the <var>i</var>-th row from the top and <var>j</var>-th column from the left is... | int solution(void) {
char str[9];
scanf("%c%c%c\n", &str[0], &str[1], &str[2]);
scanf("%c%c%c\n", &str[3], &str[4], &str[5]);
scanf("%c%c%c", &str[6], &str[7], &str[8]);
printf("%c%c%c", str[0], str[4], str[8]);
return 0;
} | fn solution() {
for i in 0..3 {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
let v: Vec<char> = s.trim().chars().collect();
print!("{}", v[i]);
}
println!();
} | hard |
1631 | A robot cleaner is placed on the floor of a rectangle room, surrounded by walls. The floor consists of $$$n$$$ rows and $$$m$$$ columns. The rows of the floor are numbered from $$$1$$$ to $$$n$$$ from top to bottom, and columns of the floor are numbered from $$$1$$$ to $$$m$$$ from left to right. The cell on the inters... | int solution() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int a[6];
int dc = 1;
int dr = 1;
int s = 0;
for (int j = 0; j < 6; j++) {
scanf("%d", &a[j]);
}
if (a[2] == a[4] || a[3] == a[5]) {
printf("%d\n", s);
} else {
for (int z = 0;; z++) {
... | fn solution() {
let mut input = String::new();
stdin().read_to_string(&mut input).unwrap();
let mut input = input.split_ascii_whitespace().flat_map(str::parse);
let t = input.next().unwrap();
let mut output = String::new();
for _ in 0..t {
let n = input.next().unwrap();
let m = i... | hard |
1632 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Let us consider the following operations on a string consisting of <code>A</code> and <code>B</code>:</p>
<ol>
<li>Select a character in a string. If it is <code>A</code>, replace it with <code>BB</code... | int solution() {
char s[100005];
char t[100005];
scanf("%s%s", s, t);
int q;
scanf("%d", &q);
int a[100005];
int b[100005];
int c[100005];
int d[100005];
int i;
for (i = 0; i < q; i++) {
scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
}
int vs[100005];
int vt[100005];
vs[0] = 0;
fo... | fn solution() {
let S: Vec<char> = {
let mut line: String = String::new();
std::io::stdin().read_line(&mut line).unwrap();
line.trim().chars().collect()
};
let T: Vec<char> = {
let mut line: String = String::new();
std::io::stdin().read_line(&mut line).unwrap();
... | easy |
1633 | Polycarp and his friends want to visit a new restaurant. The restaurant has $$$n$$$ tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from $$$1$$$ to $$$n$$$ in the order from left to right. The state of the restaurant is described by a string of length $$$n$$$ wh... | int solution() {
int t;
scanf("%d", &t);
while (t) {
int n;
int k;
int count = 0;
int zeros = 0;
scanf("%d", &n);
scanf("%d", &k);
char a[n];
scanf("%s", a);
for (int i = 0; i < n; i++) {
if (a[i] == '0') {
zeros++;
}
if (zeros > k || i == 0) {
... | fn solution() {
let t: usize = {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
buf.trim_end().parse().unwrap()
};
for _ in 0..t {
let (n, k): (usize, usize) = {
let mut buf = String::new();
std::io::stdin().read_line(&mut... | easy |
1634 | Recently, on the course of algorithms and data structures, Valeriy learned how to use a deque. He built a deque filled with $$$n$$$ elements. The $$$i$$$-th element is $$$a_i$$$ ($$$i$$$ = $$$1, 2, \ldots, n$$$). He gradually takes the first two leftmost elements from the deque (let's call them $$$A$$$ and $$$B$$$, res... | int solution() {
int n;
int q;
scanf("%d %d", &n, &q);
int a[n];
int b[n];
int c[n];
int A[n];
int B[n];
for (int i = 0; i < n; i++) {
scanf("%d ", &a[i]);
}
for (int i = 1; i < n; i++) {
c[i] = a[0];
if (a[0] > a[i]) {
b[i] = a[i];
} else {
b[i] = a[0];
a[0] = a... | fn solution() {
let stdin = io::stdin();
let stdout = io::stdout();
let mut out = io::BufWriter::new(stdout.lock());
let line = stdin.lock().lines().next().unwrap().unwrap();
let nq: Vec<i32> = line.split(" ").map(|i| i.parse().unwrap()).collect();
let n = nq[0];
let q = nq[1];
let line... | easy |
1635 | We just discovered a new data structure in our research group: a suffix three!It's very useful for natural language processing. Given three languages and three suffixes, a suffix three can determine which language a sentence is written in.It's super simple, 100% accurate, and doesn't involve advanced machine learning a... | int solution() {
int t;
scanf("%d\n", &t);
while (t--) {
char str[1001];
scanf("%[^\n]%*c\n", str);
int d = strlen(str);
if (str[d - 1] == 'o' && str[d - 2] == 'p') {
printf("FILIPINO\n");
}
if (str[d - 1] == 'u' && str[d - 2] == 's' && str[d - 3] == 'e' &&
str[d - 4] == 'd')... | fn solution() -> io::Result<()> {
let mut buffer = String::new();
let input = stdin();
input.read_line(&mut buffer)?;
let x: u32 = buffer.trim().parse().expect("Not int");
for _ in 0..x {
buffer = String::new();
input.read_line(&mut buffer)?;
if buffer.trim().ends_with("po") ... | easy |
1636 | A number $$$a_2$$$ is said to be the arithmetic mean of two numbers $$$a_1$$$ and $$$a_3$$$, if the following condition holds: $$$a_1 + a_3 = 2\cdot a_2$$$. We define an arithmetic mean deviation of three numbers $$$a_1$$$, $$$a_2$$$ and $$$a_3$$$ as follows: $$$d(a_1, a_2, a_3) = |a_1 + a_3 - 2 \cdot a_2|$$$.Arithmeti... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int a[3];
scanf("%d %d %d", &a[0], &a[1], &a[2]);
int s = a[0] + a[1] + a[2];
if (s % 3 == 0) {
printf("0\n");
} else {
printf("1\n");
}
}
return 0;
} | fn solution() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
let t = u64::from_str(s.trim_end()).unwrap();
for _ in 0..t {
s.clear();
std::io::stdin().read_line(&mut s).unwrap();
println!(
"{}",
if s.split(' ')
.m... | easy |
1637 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> piles of stones. The <var>i</var>-th pile has <var>A_i</var> stones.</p>
<p>Aoki and Takahashi are about to use them to play the following game:</p>
<ul>
<li>Starting with Aoki, t... | int solution() {
int i;
int N;
long long A[301];
long long xor = 0;
scanf("%d", &N);
for (i = 1; i <= N; i++) {
scanf("%lld", &(A[i]));
xor ^= A[i];
}
if (xor== 0) {
printf("0\n");
fflush(stdout);
return 0;
}
xor ^= A[1] ^ A[2];
long long bit[41];
long long x = A[1] + A[2];
... | fn solution() {
let n: usize = {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
buf.trim_end().parse().unwrap()
};
let a: Vec<usize> = {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
let iter = buf.spl... | medium |
1638 | Fibonacci search | int solution(const int arr[], int x, int n) {
int fibMMm2 = 0;
int fibMMm1 = 1;
int fibM = fibMMm2 + fibMMm1;
while (fibM < n) {
fibMMm2 = fibMMm1;
fibMMm1 = fibM;
fibM = fibMMm2 + fibMMm1;
}
int offset = -1;
while (fibM > 1) {
int i = ((offset + fibMMm2) < (n - 1)) ? (offset + fibMMm... | fn solution<T: Ord>(item: &T, arr: &[T]) -> Option<usize> {
let len = arr.len();
if len == 0 {
return None;
}
let mut start = -1;
let mut f0 = 0;
let mut f1 = 1;
let mut f2 = 1;
while f2 < len {
f0 = f1;
f1 = f2;
f2 = f0 + f1;
}
while f2 > 1 {
... | hard |
1639 | You are given two strings $$$s$$$ and $$$t$$$. The string $$$s$$$ consists of lowercase Latin letters and at most one wildcard character '*', the string $$$t$$$ consists only of lowercase Latin letters. The length of the string $$$s$$$ equals $$$n$$$, the length of the string $$$t$$$ equals $$$m$$$.The wildcard charact... | int solution() {
int n;
int m;
int i = 0;
int f = 0;
int b = 0;
scanf("%d", &n);
scanf("%d", &m);
int temp = n;
char s[200001];
char t[200001];
scanf("%s", s);
scanf("%s", t);
while (s[i] != '\0') {
if (s[i] == '*') {
temp = n - 1;
}
i++;
}
i = 0;
if (temp <= m) {
w... | fn solution() {
let mut stdin = String::new();
std::io::Read::read_to_string(&mut std::io::stdin(), &mut stdin).unwrap();
let mut stdin = stdin.split_whitespace();
let mut get = || stdin.next().unwrap();
let n = get!(usize);
let m = get!(usize);
let s = get().as_bytes();
let t = get().... | easy |
1640 | You're given an array $$$b$$$ of length $$$n$$$. Let's define another array $$$a$$$, also of length $$$n$$$, for which $$$a_i = 2^{b_i}$$$ ($$$1 \leq i \leq n$$$). Valerii says that every two non-intersecting subarrays of $$$a$$$ have different sums of elements. You want to determine if he is wrong. More formally, you ... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int arr[n];
_Bool ok = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
for (int j = 0; j < i; j++) {
if (arr[j] == arr[i] && ok == 0) {
printf("YES\n");
ok = 1;
... | fn solution() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
let t: i32 = s.trim().parse().unwrap();
for _ in 0..t {
std::io::stdin().read_line(&mut s).unwrap();
s.clear();
let mut map = std::collections::HashSet::new();
std::io::stdin().read_li... | medium |
1641 | A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are r... | int solution() {
int t;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
int n;
scanf("%d", &n);
for (int i = 0; i < n * 2; i += 2) {
for (int k = 0; k < i / 2; k++) {
printf("()");
}
for (int j = i; j < n * 2; j++) {
if (j < (i + ((n * 2) - i) / 2)) {
prin... | fn solution() {
let mut input = String::new();
let stdin = io::stdin();
stdin.read_line(&mut input).unwrap();
let mut t: i32 = input.trim().parse().unwrap();
while t > 0 {
let mut input = String::new();
stdin.read_line(&mut input).unwrap();
let n: usize = input.trim().parse()... | easy |
1642 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is a string <var>S</var> of length <var>N-1</var>.
Each character in <var>S</var> is <code><</code> or <code>></code>.</p>
<p>A sequence of <var>N</var> non-negative integers, <var>a_1,a_2,\... | int solution(void) {
char S[(5 * 100000) + 3];
long long cnt_p = 0;
long long cnt_m = 0;
long long ans = 0;
scanf("%s", S);
int i = 0;
for (i = 0; S[i] != '\0'; i++) {
if (S[i] == '>') {
cnt_m++;
} else {
cnt_p++;
}
if ((S[i] == '>' && S[i + 1] == '<') || S[i + 1] == '\0') {
... | fn solution() {
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).unwrap();
let s = buf.chars().collect::<Vec<char>>();
let n = buf.len() + 1;
let mut vs: Vec<i64> = vec![0; n];
for i in 0..n - 1 {
if s[i] == '<' {
vs[i + 1] = vs[i] + 1;
}
}
... | medium |
1643 | Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty d on Decoforces is as hard as the problem with difficulty d on any other judge). Mak... | int solution(int argc, char const *argv[]) {
int n;
int k;
int i;
int j;
int ar[1001];
int max = 0;
int c = 0;
int t;
scanf("%d %d", &n, &k);
for (int i = 0; i < n; ++i) {
scanf("%d", &ar[i]);
}
c = 1;
while (c != 0) {
c = 0;
for (i = 1; i < n; i++) {
if (ar[i - 1] > ar[i]) {... | fn solution() {
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
let mut it = input.split_whitespace().map(|s| s.parse::<u32>().unwrap());
let (_n, mut k) = (it.next().unwrap(), it.next().unwrap());
let mut input = String::new();
std::io::stdin().read_line(&mu... | medium |
1644 | You are given an integer $$$x$$$. Can you make $$$x$$$ by summing up some number of $$$11, 111, 1111, 11111, \ldots$$$? (You can use any number among them any number of times).For instance, $$$33=11+11+11$$$ $$$144=111+11+11+11$$$ | int solution() {
int numInputs = 0;
scanf("%d", &numInputs);
for (int i = 0; i < numInputs; i++) {
int num = 0;
scanf("%d", &num);
int r = num % 11;
if (r * 111 <= num) {
printf("YES\n");
} else {
printf("NO\n");
}
}
return 0;
} | fn solution() {
let std_in = stdin();
let in_lock = std_in.lock();
let input = BufReader::new(in_lock);
let std_out = stdout();
let out_lock = std_out.lock();
let mut output = BufWriter::new(out_lock);
let mut lines = input.lines().map(|r| r.unwrap());
let t = lines.next().unwrap().pa... | easy |
1645 | Inna loves sleeping very much, so she needs n alarm clocks in total to wake up. Let's suppose that Inna's room is a 100 × 100 square with the lower left corner at point (0, 0) and with the upper right corner at point (100, 100). Then the alarm clocks are points with integer coordinates in this square.The morning has co... | int solution() {
int clocks;
scanf("%d", &clocks);
int A[clocks][2];
int *Hashx = (int *)calloc(sizeof(int), 101);
int *Hashy = (int *)calloc(sizeof(int), 101);
for (int i = 0; i < clocks; i++) {
for (int j = 0; j < 2; j++) {
scanf("%d", &A[i][j]);
if (j == 0) {
Hashx[A[i][j]]++;
... | fn solution() {
let n = {
let mut buf = String::new();
stdin().read_line(&mut buf).expect("Failed to read line 1");
buf.trim().parse::<i32>().unwrap()
};
let mut rows: HashSet<i32> = HashSet::new();
let mut cols: HashSet<i32> = HashSet::new();
for _ in 0..n {
let mut ... | hard |
1646 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>N</var> switches with "on" and "off" state, and <var>M</var> bulbs. The switches are numbered <var>1</var> to <var>N</var>, and the bulbs are numbered <var>1</var> to <var>M</var>.</p>
<p>B... | int solution() {
int n;
int m;
scanf("%d%d", &n, &m);
int k[m];
int s[m][n];
for (int i = 0; i < m; i++) {
scanf("%d", &k[i]);
for (int j = 0; j < k[i]; j++) {
scanf("%d", &s[i][j]);
}
}
int p[m];
for (int i = 0; i < m; i++) {
scanf("%d", &p[i]);
}
int ret = 0;
for (in... | fn solution() {
let mut s = String::new();
io::stdin().read_line(&mut s).unwrap();
let v: Vec<&str> = s.split_whitespace().collect();
let (n, m) = (
v[0].parse::<usize>().unwrap(),
v[1].parse::<usize>().unwrap(),
);
let mut lamps = Vec::new();
for _i in 0..m {
let mu... | medium |
1647 | <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>Longest Common Subsequence</... | int solution() {
int q;
scanf("%d", &q);
for (int n = 0; n < q; n++) {
char x[1010];
char y[1010];
int lenx;
int leny;
scanf("%s%n", x, &lenx);
scanf("%s%n", y, &leny);
lenx--;
leny--;
int dp[lenx + 1][leny + 1];
for (int i = 0; i < lenx + 1; i++) {
dp[i][0] = 0;
... | fn solution() {
input! {
q: usize,
str: [(chars, chars); q]
}
for (l, r) in str {
let llen = l.len();
let rlen = r.len();
let mut dp = vec![vec![0; llen + 1]; rlen + 1];
for i in 0..rlen {
for j in 0..llen {
if r[i] == l[j] {
... | medium |
1648 | Anton likes to play chess, and so does his friend Danik.Once they have played n games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.Now Anton wonders, who won more games, he or Danik? Help him determine this. | int solution() {
long n = 0;
int a = 0;
int d = 0;
scanf("%ld\n", &n);
if ((n >= 1) && (n <= 100000)) {
char s[n];
int i = 0;
for (i = 0; i < n; i++) {
scanf("%c", s + i);
if (s[i] == 'A') {
a++;
} else if (s[i] == 'D') {
d++;
}
}
s[i] = '\0';
... | fn solution() {
let mut round = String::new();
let mut winners = String::new();
let _ = io::stdin().read_line(&mut round);
let _ = io::stdin().read_line(&mut winners);
let mut anton = 0;
let mut danik = 0;
for winner in winners.trim().chars() {
if winner == 'A' {
anton ... | easy |
1649 | You find yourself on an unusual crossroad with a weird traffic light. That traffic light has three possible colors: red (r), yellow (y), green (g). It is known that the traffic light repeats its colors every $$$n$$$ seconds and at the $$$i$$$-th second the color $$$s_i$$$ is on.That way, the order of the colors is desc... | int solution() {
int zushu;
scanf("%d", &zushu);
for (int zu = 1; zu <= zushu; zu++) {
int n;
char c;
scanf("%d %c", &n, &c);
char s[2 * n];
scanf("%s", s);
for (int i = 0; i < n; i++) {
s[i + n] = s[i];
}
int max = 0;
for (int i = 0; i < n; i++) {
if (s[i] == c) ... | fn solution() {
let stdin = std::io::stdin();
let stdin_lock = stdin.lock();
let mut line_iter = stdin_lock.lines();
let t = line_iter
.next()
.unwrap()
.unwrap()
.as_str()
.parse::<usize>()
.unwrap();
for _ in 0..t {
let n_c_str = line_iter.ne... | medium |
1650 | New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You k... | int solution() {
int n = 0;
int i = 0;
int c[n];
int a = 0;
int b = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d %d", &a, &b);
printf("%d\n", ((23 - a) * 60) + 60 - b);
}
} | fn solution() {
let stdin = io::stdin();
let mut input = stdin.lock();
let mut line = String::new();
input.read_line(&mut line).unwrap();
let mut queries: i16 = line.trim().parse().unwrap();
while queries > 0 {
line.clear();
input.read_line(&mut line).unwrap();
let mut nu... | medium |
1651 | <h1>Bit Flag</h1>
<p>
A state with $n$ flags of ON or OFF can be represented by a sequence of bits where $0, 1, ..., n-1$ -th flag corresponds to 1 (ON) or 0 (OFF).
The state can be managed by the corresponding decimal integer, because the sequence of bits is a binary representation where each bit is 0 or 1.
</p>... | int solution(void) {
unsigned long long int bit = 0;
int q;
scanf("%d", &q);
for (int i = 0; i < q; i++) {
int command;
scanf("%d", &command);
if (0 <= command && command <= 3) {
int t;
scanf("%d", &t);
if (command == 0) {
if (bit >> t & 1UL) {
printf("1\n");
... | fn solution() {
let stdin = io::stdin();
let lock = stdin.lock();
let mut lines = lock.lines();
let mut state = 0u64;
let q = lines.next().unwrap().unwrap().parse().unwrap();
for (_, l) in (0..q).zip(lines) {
let l = l.unwrap();
let mut sw = l.split_whitespace();
let c... | medium |
1652 | Fillomino is a classic logic puzzle. (You do not need to know Fillomino in order to solve this problem.) In one classroom in Yunqi town, some volunteers are playing a board game variant of it:Consider an $$$n$$$ by $$$n$$$ chessboard. Its rows are numbered from $$$1$$$ to $$$n$$$ from the top to the bottom. Its columns... | int solution() {
unsigned n;
unsigned a[500];
unsigned b[500][500];
scanf("%u", &n);
for (unsigned i = 0; i < n; i++) {
scanf("%u", &a[i]);
}
for (unsigned i = 0; i < n; i++) {
unsigned j = 0;
for (unsigned k = 0; k < n; k++) {
if (a[k] >= i + 1) {
b[i + j][j] = a[k];
j... | fn solution() {
use std::io::Read;
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).unwrap();
let mut itr = buf.split_whitespace();
use std::io::Write;
let out = std::io::stdout();
let mut out = std::io::BufWriter::new(out.lock());
let n = scan!(usize);
le... | hard |
1653 | Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and... | int solution() {
short len;
short n;
scanf("%hi %hi", &len, &n);
short start[n];
short end[n];
char from[n];
char to[n];
char str[len];
scanf("%s", str);
for (short i = 0; i < n; ++i) {
scanf("%hi %hi %c %c", &start[i], &end[i], &from[i], &to[i]);
}
for (short i = 0; i < n; ++i) {
fo... | fn solution() {
let mut input = String::new();
std::io::stdin()
.read_line(&mut input)
.expect("input: read line failed");
let vec = input
.split_whitespace()
.map(|item| item.parse::<usize>().unwrap())
.collect::<Vec<usize>>();
let (_length, amount) = (vec[0], ... | medium |
1654 | <H1>Problem B: 友だちの誘い方</H1>
<p>
明日から、待ちに待った夏休みが始まります。なのでわたしは、友だちを誘って、海に遊びに行くこ
とに決めました。
</p>
<p>
けれども、わたしの友だちには、恥ずかしがりやさんが多いです。その人たちは、あまり多くの人が
いっしょに来ると知ったら、きっと嫌がるでしょう。
</p>
<p>
ほかにも、わたしの友だちには、目立ちたがりやさんも多いです。その人たちは、いっしょに来る人
があまり多くないと知れば、きっと嫌がるでしょう。
</p>
<p>
それと、わたしの友だちには、いつもは目立ちたがりやなのに実は恥ずかしがりやさんな人もいま
す。その人たちは、いっしょに来... | int solution() {
int a[100002] = {0};
int b[100002] = {0};
int N;
int i;
int k;
int answer = 0;
int p;
scanf("%d", &N);
for (i = 1; i <= N; i++) {
scanf("%d %d", &a[i], &b[i]);
}
for (k = N + 1; k >= 1; k--) {
p = 0;
for (i = 1; i <= N; i++) {
if (a[i] <= k && k <= b[i]) {
... | fn solution() {
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).unwrap();
let mut iter = buf.split_whitespace();
let mut v: Vec<i32> = (0..100010).map(|_| 0).collect();
let n: usize = iter.next().unwrap().parse().unwrap();
for _i in 0..n {
let a: usize = iter.next... | medium |
1655 | You are given a binary string $$$s$$$ consisting of $$$n$$$ zeros and ones.Your task is to divide the given string into the minimum number of subsequences in such a way that each character of the string belongs to exactly one subsequence and each subsequence looks like "010101 ..." or "101010 ..." (i.e. the subsequence... | int solution() {
int tc;
scanf("%d", &tc);
while (tc--) {
int n;
int i;
int z = -1;
int o = -1;
int s = 0;
int max = -1;
scanf("%d", &n);
char ss[n + 5];
char at[2];
scanf("%s", ss);
int a[n];
int b[n];
int zero[n];
int one[n];
for (i = 0; i < n; i++) {... | 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 |
1656 | A pair of positive integers $$$(a,b)$$$ is called special if $$$\lfloor \frac{a}{b} \rfloor = a \bmod b$$$. Here, $$$\lfloor \frac{a}{b} \rfloor$$$ is the result of the integer division between $$$a$$$ and $$$b$$$, while $$$a \bmod b$$$ is its remainder.You are given two integers $$$x$$$ and $$$y$$$. Find the number of... | int solution() {
int t;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
int x;
int y;
long long int Answer = 0;
scanf("%d%d", &x, &y);
for (int k = 1; k < pow(x, 0.5); k++) {
int temp = (x / k) - 1;
int min1;
int max1;
if (y < temp) {
min1 = y;
} 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 tc: usize = sc.next();
for _ in 0..tc {
let (x, y): (i64, i64) = (sc.next(), sc.next());
let mut i = 1;
... | medium |
1657 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a grid with <var>H</var> horizontal rows and <var>W</var> vertical columns. Let <var>(i,j)</var> denote the square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the... | int solution(void) {
int h;
int w;
scanf("%d %d", &h, &w);
long a[h][w];
long b[h][w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
scanf("%ld", &a[i][j]);
}
}
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
scanf("%ld", &b[i][j]);
}
}
long ab[... | fn solution() {
let mut input_str = String::new();
std::io::stdin().read_to_string(&mut input_str).unwrap();
let input_parts = input_str.split_whitespace().collect::<Vec<_>>();
let mut input_parts_it = input_parts.iter().cloned();
let mut next = || input_parts_it.next().unwrap();
let h: usize ... | medium |
1658 | <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> non-negative integers <var>A_1, A_2, ..., A_N</var> and another non-negative integer <var>K</var>.</p>
<p>For a integer <var>X</var> between <var>0</var> and <var>K</var> (inc... | int solution(void) {
int N = 0;
long K = 0;
int bin[50] = {0};
long long sum = 0;
long X = 0;
scanf("%d %ld", &N, &K);
long A[N];
for (int i = 0; i < N; i++) {
A[i] = 0;
scanf("%ld", &A[i]);
sum += A[i];
for (int j = 0; j < 50; j++) {
if (A[i] % 2) {
bin[j]++;
}
... | 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 k: u64 = iter.next().unwrap().parse().unwrap();
let a: Vec<u64> = (0..n)
.map(|_| iter.next().... | hard |
1659 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a directed graph with <var>N</var> vertices numbered <var>1</var> to <var>N</var> and <var>M</var> edges.
The <var>i</var>-th edge is directed from Vertex <var>A_i</var> to Vertex <var>B_i</var... | int solution() {
int n;
int m;
long long int p;
scanf("%d %d %lld", &n, &m, &p);
int a[5003];
int b[5003];
long long int c[5003];
int i;
int j;
for (i = 0; i < m; i++) {
scanf("%d %d %lld", &a[i], &b[i], &c[i]);
}
for (i = 0; i < m; i++) {
c[i] -= p;
}
long long int d[3003];
for (i... | fn solution() {
let out = std::io::stdout();
let mut out = std::io::BufWriter::new(out.lock());
input! {
n: usize,
m: usize,
p: i64,
es: [(usize1, usize1, i64); m],
}
let es: Vec<_> = es.into_iter().map(|(a, b, c)| (a, b, c - p)).collect();
let mut score = vec![-(1i64 <<... | easy |
1660 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You will be given an integer <var>a</var> and a string <var>s</var> consisting of lowercase English letters as input.</p>
<p>Write a program that prints <var>s</var> if <var>a</var> is not less than <va... | int solution(void) {
int a = 0;
char s[20];
char *ss = "red";
scanf("%d", &a);
scanf("%s", s);
if (a >= 3200) {
printf("%s\n", s);
} else {
printf("%s\n", ss);
}
return 0;
} | fn solution() {
let mut a = String::new();
let mut s = String::new();
std::io::stdin().read_line(&mut a).unwrap();
std::io::stdin().read_line(&mut s).unwrap();
let a: i32 = a.trim().parse().unwrap();
println!("{}", if a >= 3200 { s.trim() } else { "red" });
} | easy |
1661 | You are given a rooted tree consisting of $$$n$$$ vertices. Vertices are numbered from $$$1$$$ to $$$n$$$. Any vertex can be the root of a tree.A tree is a connected undirected graph without cycles. A rooted tree is a tree with a selected vertex, which is called the root.The tree is specified by an array of ancestors $... | int solution() {
int t;
int i;
scanf("%d", &t);
for (i = 0; i < t; i++) {
int n;
int j;
scanf("%d", &n);
int parent[n + 1];
int order[n + 1];
int weight[n + 1];
int tot_weight[n + 1];
order[0] = -100;
parent[0] = -100;
weight[0] = -100;
for (j = 1; j <= n; j++) {
... | 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 b: Vec<usize> = lines
.next()
.unwrap... | medium |
1662 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Niwango created a playlist of <var>N</var> songs.
The title and the duration of the <var>i</var>-th song are <var>s_i</var> and <var>t_i</var> seconds, respectively.
It is guaranteed that <var>s_1,\ldo... | int solution(void) {
int n;
scanf("%d\n", &n);
char s[n][100];
int t[n];
for (int i = 0; i < n; i++) {
scanf("%s %d\n", s[i], &t[i]);
}
char x[100];
scanf("%s\n", x);
int flag = 0;
int sum = 0;
for (int i = 0; i < n; i++) {
if (flag == 1) {
sum += t[i];
}
if (strcmp(x, s[i... | fn solution() {
let mut s = String::new();
use std::io::Read;
std::io::stdin().read_to_string(&mut s).unwrap();
let mut s = s.split_whitespace();
let n: usize = s.next().unwrap().parse().unwrap();
let st: Vec<_> = (0..n)
.map(|_| (s.next().unwrap(), s.next().unwrap().parse::<i32>().unwra... | hard |
1663 | <!-- - - - - - begin nicebody - - - - - -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
<script type="text/javascript" async
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<h1>A: 丸付け</h1>
<h2>問題... | int solution() {
char mozi[100000];
int i;
int n;
int count = 0;
scanf("%d", &n);
scanf("%s", mozi);
for (i = 0; i < n; i++) {
count++;
if (mozi[i] == 'x' && mozi[i + 1] == 'x') {
printf("%d\n", count);
return 0;
}
}
printf("%d\n", count);
return 0;
} | fn solution() {
input!(N:usize,S:chars);
let mut S: Vec<char> = S;
S.push('x');
S.push('x');
let mut ans = 0;
let mut flag = false;
for i in 0..N {
if S[i] == 'x' {
if flag {
break;
}
flag = true;
} else {
flag =... | easy |
1664 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi has a string <var>S</var> consisting of lowercase English letters.</p>
<p>Starting with this string, he will produce a new one in the procedure given as follows.</p>
<p>The procedure consists ... | int solution(void) {
char s[500001];
char *p1 = &s[200000];
scanf("%s", p1);
char *p2 = p1 + strlen(p1);
int q;
scanf("%d", &q);
int flag = 1;
for (int i = 0; i < q; i++) {
int n;
int f;
char c;
scanf("%d", &n);
if (n == 1) {
flag = 1 - flag;
continue;
}
scanf("%d... | fn solution() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
let mut s: VecDeque<char> = s.trim_end().chars().collect();
let mut q = String::new();
std::io::stdin().read_line(&mut q).unwrap();
let q: u64 = q.trim_end().parse().unwrap();
let mut reversed = false;
... | hard |
1665 | Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$... | int solution() {
int h;
int w;
scanf("%d %d", &h, &w);
int matrix[h][w];
memset(matrix, 0, sizeof(matrix));
for (int i = 0; i < h; ++i) {
int r = 0;
scanf("%d", &r);
for (int j = 0; j < r; ++j) {
matrix[i][j] += 1;
}
if (r < w) {
matrix[i][r] += 4;
}
}
for (int i ... | 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 h = get!(usize);
let w = get!(usize);
let mut grid = vec![vec![0; w]; h];
for r in 0..h {
let c = get!(usize);... | medium |
1666 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is a three-digit integer <var>N</var>. Does <var>N</var> contain the digit <var>7</var>?</p>
<p>If so, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
<div class="p... | int solution() {
char s[3];
scanf("%s", s);
if (s[0] != '7' && s[1] != '7' && s[2] != '7') {
printf("No");
} else {
printf("Yes");
}
return 0;
} | fn solution() {
let mut s = String::new();
stdin().read_line(&mut s).ok();
let mut itr = s.trim().chars();
println!("{}", if itr.any(|e| e == '7') { "Yes" } else { "No" });
} | easy |
1667 | You are given two positive integers $$$n$$$ and $$$k$$$. Print the $$$k$$$-th positive integer that is not divisible by $$$n$$$.For example, if $$$n=3$$$, and $$$k=7$$$, then all numbers that are not divisible by $$$3$$$ are: $$$1, 2, 4, 5, 7, 8, 10, 11, 13 \dots$$$. The $$$7$$$-th number among them is $$$10$$$. | int solution() {
int t;
scanf("%d\n", &t);
long long int n[t];
long long int k[t];
for (int i = 0; i < t; i++) {
scanf("%lld %lld\n", &n[i], &k[i]);
}
for (int i = 0; i < t; i++) {
long long int q;
long long int r;
q = k[i] / (n[i] - 1);
r = k[i] % (n[i] - 1);
if (r == 0) {
p... | 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<u32> = lines
.next()
.unwrap()
.unwrap()
.split(' ')
.map(|x| x.p... | medium |
1668 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an undirected graph consisting of <var>N</var> vertices and <var>M</var> edges.
The vertices are numbered <var>1</var> to <var>N</var>, and the edges are numbered <var>1</var> to <var>M</v... | int solution() {
int i;
int N;
int M;
int u;
int w;
int deg[2][200001] = {};
char s[200002];
list *adj[200001] = {};
list e[400001];
list *p;
scanf("%d %d", &N, &M);
scanf("%s", &(s[1]));
for (i = 0; i < M; i++) {
scanf("%d %d", &u, &w);
if (u == w) {
deg[s[u] - 'A'][u]++;
... | fn solution() {
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).ok();
let mut it = buf.split_whitespace();
let n = it.next().unwrap().parse::<usize>().unwrap();
let m = it.next().unwrap().parse::<usize>().unwrap();
let s = it.next().unwrap().as_bytes();
let mut to = ve... | medium |
1669 | It has finally been decided to build a roof over the football field in School 179. Its construction will require placing $$$n$$$ consecutive vertical pillars. Furthermore, the headmaster wants the heights of all the pillars to form a permutation $$$p$$$ of integers from $$$0$$$ to $$$n - 1$$$, where $$$p_i$$$ is the he... | int solution() {
int tt;
scanf("%d", &tt);
while (tt--) {
int n;
scanf("%d", &n);
int k = 1;
while (k < n) {
k *= 2;
}
k /= 2;
for (int i = 1; i < n; i++) {
if (i == k) {
printf("0 %d ", k);
} else {
printf("%d ", i);
}
}
printf("\n");
... | fn solution() {
let stdin = io::stdin();
let mut lines = stdin.lock().lines();
let t: usize = lines.next().unwrap().unwrap().parse().unwrap();
for _ in 0..t {
let n: usize = lines.next().unwrap().unwrap().parse().unwrap();
let mut m = 1 << 18;
while (n - 1) & m == 0 {
... | medium |
1670 | A sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Given two integers $$$n$$$ and $$$k$$$, construct a permutation $$$a$$$ of numbers from $$$1$$$ to $$$n$$$ which has exactly $$$k$$$ peaks. An index $$$i$$$ of an array $$$a$$$ of size $$$n$$$ is said... | int solution() {
int t = 0;
scanf("%d", &t);
while (t--) {
int n = 0;
int k = 0;
scanf("%d", &n);
scanf("%d", &k);
int a[n];
for (int i = 0; i < n; i++) {
a[i] = i + 1;
}
if (k > (n - 1) / 2) {
printf("-1\n");
} else {
for (int i = 1; i <= k; i++) {
... | fn solution() {
let mut s = String::new();
stdin().read_line(&mut s).unwrap();
let t: i64 = s.trim().parse().unwrap();
for _i in 0..t {
s.clear();
stdin().read_line(&mut s).unwrap();
let mut iter = s.split_whitespace();
let n: usize = iter.next().unwrap().parse().unwrap()... | easy |
1671 | Alice gave Bob two integers $$$a$$$ and $$$b$$$ ($$$a > 0$$$ and $$$b \ge 0$$$). Being a curious boy, Bob wrote down an array of non-negative integers with $$$\operatorname{MEX}$$$ value of all elements equal to $$$a$$$ and $$$\operatorname{XOR}$$$ value of all elements equal to $$$b$$$.What is the shortest possible... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int a;
int b;
scanf("%d%d", &a, &b);
int temp = 0;
if ((a - 1) % 4 == 0) {
temp = a - 1;
} else if ((a - 1) % 4 == 1) {
temp = 1;
} else if ((a - 1) % 4 == 2) {
temp = a;
} else {
temp = 0;
}
if ... | fn solution() {
let mut s = String::new();
const MAX_VALUE: usize = 3 * 100000;
let mut dp: [usize; MAX_VALUE] = [0; MAX_VALUE];
for i in 1..MAX_VALUE {
dp[i] = dp[i - 1] ^ i;
}
let solve = |a, b| -> usize {
let prev = a - 1;
let xor_up_to = dp[prev];
let remain... | hard |
1672 | <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> of length <var>N</var> consisting of <code>A</code>, <code>C</code>, <code>G</code> and <code>T</code>. Answer the following <var>Q</var> queries:</p>
<ul>
<li>Query ... | int solution(void) {
int n;
int q;
scanf("%d %d\n", &n, &q);
char s[n];
int count[n];
int l[q];
int r[q];
count[0] = 0;
for (int i = 0; i < n; i++) {
scanf("%c\n", &s[i]);
}
for (int j = 0; j < n; j++) {
if (s[j] == 'A' && s[j + 1] == 'C') {
count[j + 1] = count[j] + 1;
} else {
... | 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 q: usize = iter.next().unwrap().parse().unwrap();
let s: Vec<char> = iter.next().unwrap().chars().coll... | easy |
1673 | There's a chessboard of size $$$n \times n$$$. $$$m$$$ rooks are placed on it in such a way that: no two rooks occupy the same cell; no two rooks attack each other. A rook attacks all cells that are in its row or column.Is it possible to move exactly one rook (you can choose which one to move) into a different cell ... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int m;
int n;
scanf("%d%d", &m, &n);
int arr[2 * n];
for (int i = 0; i < 2 * n; i++) {
scanf("%d", &arr[n]);
}
if (m == n) {
printf("No\n");
} else {
printf("Yes\n");
}
}
return 0;
} | fn solution() {
let mut buffer = String::new();
io::stdin().read_line(&mut buffer).unwrap();
let t = buffer.trim().parse::<u16>().unwrap();
for _ in 0..t {
buffer = String::new();
io::stdin().read_line(&mut buffer).unwrap();
let mut parts = buffer.split_whitespace().map(|s| s.par... | medium |
1674 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.</p>
<p>The exercise machine at the gym has <var>N</var> buttons, and exactly one of the buttons is lighten up.
These buttons are n... | int solution() {
int N = 0;
scanf("%d", &N);
int a[N - 1];
for (int n = 0; n < N; n++) {
scanf("%d", &a[n]);
}
int check = 1;
int num = 0;
int count = 0;
while (check) {
num = a[num];
count++;
if (num == 2) {
check = 0;
}
num--;
if (count > N) {
break;
}
}... | 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 buttons: Vec<usize> = (0..n)
.map(|_| iter.next().unwrap().parse().unwrap())
.collect();... | medium |
1675 | An array is beautiful if both of the following two conditions meet: there are at least $$$l_1$$$ and at most $$$r_1$$$ elements in the array equal to its minimum; there are at least $$$l_2$$$ and at most $$$r_2$$$ elements in the array equal to its maximum. For example, the array $$$[2, 3, 2, 4, 4, 3, 2]$$$ has $$$3$... | int solution() {
int test_cases = 0;
scanf("%d", &test_cases);
while (test_cases--) {
int l1 = 0;
int r1 = 0;
int l2 = 0;
int r2 = 0;
scanf("%d", &l1);
scanf("%d", &r1);
scanf("%d", &l2);
scanf("%d", &r2);
int min = 100000;
if (r2 < l1 || r1 < l2) {
printf("%d\n", ... | fn solution() {
let mut str_t = String::new();
io::stdin().read_line(&mut str_t);
let mut total_case = 0;
match str::parse::<i32>(str_t.trim()) {
Ok(val) => total_case = val,
Err(_) => print!("error"),
};
for _i in 0..total_case {
let mut str_l = String::new();
i... | easy |
1676 | Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices. | int solution() {
int numSets = 0;
scanf("%d", &numSets);
for (int currentSet = 0; currentSet < numSets; ++currentSet) {
int numElements = 0;
scanf("%d", &numElements);
if (numElements == 3) {
printf("2 1 3\n");
continue;
}
if ((numElements % 2) == 1) {
printf("0 ");
... | fn solution() {
let mut lines = io::stdin().lines();
lines.next();
for line in lines {
let n = line.unwrap().parse::<i32>().unwrap();
let v = (0..(n - 3)).collect::<Vec<i32>>();
let xor = v.iter().fold(0, |a, b| a ^ b);
let x1 = 1 << 29;
let x2 = 1 << 30;
let ... | hard |
1677 | An array $$$a_1, a_2, \ldots, a_n$$$ is good if and only if for every subsegment $$$1 \leq l \leq r \leq n$$$, the following holds: $$$a_l + a_{l + 1} + \ldots + a_r = \frac{1}{2}(a_l + a_r) \cdot (r - l + 1)$$$. You are given an array of integers $$$a_1, a_2, \ldots, a_n$$$. In one operation, you can replace any one e... | int solution() {
int t;
int i;
scanf("%d", &t);
for (i = 0; i < t; i++) {
int n;
int j;
int k;
int l;
scanf("%d", &n);
int arr[n];
int max = 1;
for (j = 0; j < n; j++) {
scanf("%d", &arr[j]);
}
for (j = 0; j < n - 1; j++) {
for (k = j + 1; k < n; k++) {
... | 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 x: Vec<i64> = lines
.next()
.unwrap()... | medium |
1678 | Polycarp must pay exactly $$$n$$$ burles at the checkout. He has coins of two nominal values: $$$1$$$ burle and $$$2$$$ burles. Polycarp likes both kinds of coins equally. So he doesn't want to pay with more coins of one type than with the other.Thus, Polycarp wants to minimize the difference between the count of coins... | int solution() {
int n = 0;
int c1 = 0;
int c2 = 0;
int t = 0;
int c = 0;
int y = 0;
scanf("%d\n", &t);
for (int i = 0; i < t; i++) {
scanf("%d", &n);
c = n / 3;
y = n % 3;
if (1 <= y && y <= 2) {
if (y == 1) {
c1 = c + 1;
c2 = c;
} else {
c1 = c;
... | fn solution() {
let mut t = String::new();
io::stdin().read_line(&mut t).unwrap();
for _ in 0..t.trim().parse::<i32>().unwrap() {
let mut n = String::new();
io::stdin().read_line(&mut n).unwrap();
let sum = n.trim().parse::<i64>().unwrap();
if sum % 3 == 0 {
p... | easy |
1679 | There are $$$n$$$ people in a horizontal line, each looking either to the left or the right. Each person counts the number of people in the direction they are looking. The value of the line is the sum of each person's count.For example, in the arrangement LRRLL, where L stands for a person looking left and R stands for... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
long long int n;
long long int val = 0;
long long int k = 0;
scanf("%lld\n", &n);
char c[n];
long long int a[n];
for (long long int i = 0; i < n; i++) {
scanf("%c", &c[i]);
if (c[i] == 'L') {
val += i;
... | fn solution() {
let t: usize = {
let mut line: String = String::new();
std::io::stdin().read_line(&mut line).unwrap();
line.trim().parse().unwrap()
};
for _i in 0..t {
let n: usize = {
let mut line: String = String::new();
std::io::stdin().read_line(&m... | medium |
1680 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs <var>700</var> yen (the currency of Japan), plus <var>100</var> yen for each kind of topping (boiled egg, sliced pork, green onions).</p>
<p>... | int solution() {
char top = 0;
char in[4];
scanf("%s", in);
for (int i = 0; i < 4; i++) {
if (*(in + (i * sizeof(char))) == 'o') {
top++;
}
}
printf("%d\n", 700 + (top * 100));
return 0;
} | fn solution() {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).ok();
let cnt = buf.trim().chars().filter(|&x| x == 'o').count();
println!("{}", 700 + cnt * 100);
} | easy |
1681 | Pasha is participating in a contest on one well-known website. This time he wants to win the contest and will do anything to get to the first place!This contest consists of n problems, and Pasha solves ith problem in ai time units (his solutions are always correct). At any moment of time he can be thinking about a solu... | int solution() {
int n;
int m;
scanf("%d", &n);
long int a[n];
int i;
long int sum = 0;
long int max = 100001;
for (i = 0; i < n; i++) {
scanf("%ld", &a[i]);
sum += a[i];
}
int flag = 0;
scanf("%d", &m);
long int l[m];
long int r[m];
for (i = 0; i < m; i++) {
scanf("%ld %ld", &... | fn solution() {
let mut buffer = String::new();
io::stdin().read_line(&mut buffer).unwrap();
let n = buffer.trim().parse::<usize>().unwrap();
buffer.clear();
io::stdin().read_line(&mut buffer).unwrap();
let mut v = buffer
.split_whitespace()
.map(|x| x.trim().parse::<i32>().unwr... | medium |
1682 | <h1>Vector</h1>
<p>
For a dynamic array $A = \{a_0, a_1, ...\}$ of integers, perform a sequence of the following operations:
</p>
<ul>
<li>pushBack($x$): add element $x$ at the end of $A$</li>
<li>randomAccess($p$):print element $a_p$</li>
<li>popBack(): delete the last element of $A$</li>
</ul>
<p>
$A$ ... | int solution() {
int q;
scanf("%d\n", &q);
int a[q];
int i = 0;
int com;
int x;
while (q--) {
scanf("%d \n", &com);
switch (com) {
case 0:
scanf("%d\n", &x);
a[i++] = x;
break;
case 1:
scanf("%d\n", &x);
printf("%d\n", a[x]);
break;
case 2:
a... | fn solution() {
let mut s = String::new();
io::stdin().read_line(&mut s).ok();
let row: usize = s.trim().parse().unwrap_or(0);
s.clear();
let mut array = Vec::new();
for _ in 0..row {
io::stdin().read_line(&mut s).ok();
let v: Vec<isize> = s
.split_whitespace()
... | hard |
1683 | You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform a... | int solution(void) {
int Q;
char s[51];
char t[51];
scanf("%d", &Q);
while (Q--) {
scanf("%s %s", s, t);
int a = 0;
int b = 0;
for (int i = 0; t[i]; ++i) {
if (t[i] == 'a') {
++a;
} else {
b = 1;
}
}
if (a && b) {
printf("-1\n");
} else if (... | 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 q: usize = input.next().unwrap().parse().unwrap();
for _ in 0..q {
let s = input.next().unwrap();
let t = in... | easy |
1684 | <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 <var>N</var>.<br/>
For two positive integers <var>A</var> and <var>B</var>, we will define <var>F(A,B)</var> as the larger of the following: the number of digits in the decimal ... | int solution(void) {
int64_t N;
scanf("%ld", &N);
int MIN = 10;
for (int64_t i = 1; i * i <= N; i++) {
if (N % i == 0) {
int64_t B = N / i;
int M = 0;
while (B > 0) {
B /= 10;
M++;
}
MIN = M;
}
}
printf("%d\n", MIN);
return 0;
} | fn solution() {
let mut s: String = String::new();
std::io::stdin().read_to_string(&mut s).ok();
let mut itr = s.split_whitespace();
let n: usize = itr.next().unwrap().parse().unwrap();
let keta = |x: usize| {
let mut y = x;
let mut res = 0;
while y > 0 {
res +=... | medium |
1685 | There is a chessboard of size $$$n$$$ by $$$n$$$. The square in the $$$i$$$-th row from top and $$$j$$$-th column from the left is labelled $$$(i,j)$$$.Currently, Gregor has some pawns in the $$$n$$$-th row. There are also enemy pawns in the $$$1$$$-st row. On one turn, Gregor moves one of his pawns. A pawn can move on... | int solution() {
int tc;
scanf("%d", &tc);
while (tc--) {
int n;
scanf("%d", &n);
char self[n + 1];
char enemy[n + 1];
scanf("%s", enemy);
scanf("%s", self);
int ans = 0;
for (int i = 0; i < n; i++) {
if (self[i] == '1' && enemy[i] == '0') {
self[i] = '0';
an... | fn solution() {
let mut t = String::new();
stdin().read_line(&mut t).unwrap();
let t: u32 = t.trim().parse().unwrap();
for _ in 0..t {
let mut n = String::new();
stdin().read_line(&mut n).unwrap();
let n: usize = n.trim().parse().unwrap();
let mut black = String::new();... | medium |
1686 | While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly $$$H$$$ centimeters above the water surface. Inessa grabbed the flower and sailed the distance of $$$L$$$ centimeters. Exactly at this point the flower touched the ... | int solution() {
float L;
float H;
scanf("%f", &H);
scanf("%f", &L);
printf("%f", (L * L - H * H) / (2 * H));
return 0;
} | fn solution() {
let (h, l) = {
let mut line = String::new();
stdin().read_line(&mut line).unwrap();
let mut iter = line.split_whitespace();
(
iter.next().unwrap().parse::<f64>().unwrap(),
iter.next().unwrap().parse::<f64>().unwrap(),
)
};
let ... | easy |
1687 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<blockquote>
<p>
Kyoto University Programming Contest is a programming contest voluntarily held by some Kyoto University students.
This contest is abbreviated as <b>K</... | int solution() {
int n;
int m;
int a;
int b[30] = {0};
int c;
int i;
int j;
char s[100010];
scanf("%d %d", &n, &m);
for (i = 0; i < n; i++) {
scanf("%s", s);
b[s[0] - 'A']++;
}
for (c = 0; 1; c++) {
for (i = 0; i < 26; i++) {
a = b[i];
for (j = i; j && b[j - 1] < a; j--) ... | fn solution() {
let mut s = String::new();
use std::io::Read;
std::io::stdin().read_to_string(&mut s).unwrap();
let mut s = s.split_whitespace();
let n: usize = s.next().unwrap().parse().unwrap();
let k: usize = s.next().unwrap().parse().unwrap();
let mut mp = std::collections::BTreeMap::new... | hard |
1688 | To celebrate your birthday you have prepared a festive table! Now you want to seat as many guests as possible.The table can be represented as a rectangle with height $$$h$$$ and width $$$w$$$, divided into $$$h \times w$$$ cells. Let $$$(i, j)$$$ denote the cell in the $$$i$$$-th row and the $$$j$$$-th column of the re... | int solution(void) {
int T;
int h;
int w;
scanf("%d", &T);
while (T--) {
scanf("%d%d", &h, &w);
int a[h + 2][w + 2];
memset(a, 0, sizeof(a));
for (int i = 1; i <= h; ++i) {
for (int j = 1; j <= w; ++j) {
if (i == 1 || i == h || j == 1 || j == w) {
if (!a[i - 1][j - 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 |
1689 | An array $$$b$$$ of length $$$k$$$ is called good if its arithmetic mean is equal to $$$1$$$. More formally, if $$$$$$\frac{b_1 + \cdots + b_k}{k}=1.$$$$$$Note that the value $$$\frac{b_1+\cdots+b_k}{k}$$$ is not rounded up or down. For example, the array $$$[1,1,1,2]$$$ has an arithmetic mean of $$$1.25$$$, which is n... | int solution() {
int t = 0;
scanf("%d", &t);
int i = 0;
for (i = 0; i < t; i++) {
int n = 0;
scanf("%d", &n);
int a[n];
int j = 0;
int sum = 0;
for (j = 0; j < n; j++) {
scanf("%d", &a[j]);
sum += a[j];
}
if (sum == n) {
printf("0\n");
} else if (sum > n) {
... | fn solution() {
let (i, o) = (io::stdin(), io::stdout());
let mut o = bw::new(o.lock());
for l in i.lock().lines().skip(2).step_by(2) {
let (c, s) = l
.unwrap()
.split(' ')
.map(|w| w.parse::<i32>().unwrap())
.fold((0, 0), |(c, s), x| (c + 1, s + x));
... | hard |
1690 | <span class="lang-en">
<p>Score : <var>700</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>.
Does a tree with <var>n</var> vertices that satisfies the following conditions exist?</p>
<ul>
<li>The vertices are numbered <var>1,2,..., n</... | int solution() {
char s[100005];
scanf("%s", s);
int n = 0;
while (s[n] != '\0') {
n++;
}
int i;
int f = 0;
if (s[0] == '0' || s[n - 1] == '1') {
f++;
}
for (i = 0; i < n - 1; i++) {
if (s[i] != s[n - i - 2]) {
f++;
}
}
if (f > 0) {
printf("-1\n");
return 0;
}
i... | fn solution() {
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).unwrap();
let mut buf_it = buf.split_whitespace();
let S = buf_it.next().unwrap().chars().collect::<Vec<_>>();
let N = S.len();
if S[0] == '0' || S[N - 1] == '1' {
println!("-1");
return;
... | easy |
1691 | $$$m$$$ chairs are arranged in a circle sequentially. The chairs are numbered from $$$0$$$ to $$$m-1$$$. $$$n$$$ people want to sit in these chairs. The $$$i$$$-th of them wants at least $$$a[i]$$$ empty chairs both on his right and left side. More formally, if the $$$i$$$-th person sits in the $$$j$$$-th chair, then n... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
long long n;
long long m;
long long sum = 0;
scanf("%lld %lld", &n, &m);
long long a[n];
long long min = 10000000000;
long long max = 0;
for (int i = 0; i < n; i++) {
scanf("%lld", &a[i]);
sum += a[i];
if (... | 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 x: Vec<u64> = lines
.next()
.unwrap()
.unwrap()
.split(' ')
.map(|x| x.pa... | easy |
1692 | <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> slimes lining up from left to right. The colors of these slimes will be given as a string <var>S</var> of length <var>N</var> consisting of lowercase English letters. The <var>i</... | int solution(void) {
int N = 0;
scanf("%d", &N);
char s[100001];
scanf("%s", s);
int ans = 1;
for (int i = 1; i < N; i++) {
if (s[i] != s[i - 1]) {
ans++;
}
}
printf("%d", ans);
return 0;
} | fn solution() {
let mut first_line = String::new();
std::io::stdin().read_line(&mut first_line).unwrap();
let _n: usize = first_line.trim().parse().unwrap();
let mut second_line = String::new();
std::io::stdin().read_line(&mut second_line).unwrap();
let s = second_line.trim();
let mut queue... | medium |
1693 | Arkady invited Anna for a dinner to a sushi restaurant. The restaurant is a bit unusual: it offers $$$n$$$ pieces of sushi aligned in a row, and a customer has to choose a continuous subsegment of these sushi to buy.The pieces of sushi are of two types: either with tuna or with eel. Let's denote the type of the $$$i$$$... | int solution() {
int num_sushis = 0;
int sushi[100000];
int num_ones = 0;
int num_twos = 0;
int current;
int max = 0;
scanf("%d", &num_sushis);
for (int i = 0; i < num_sushis; i++) {
scanf("%d", &sushi[i]);
}
current = sushi[0];
for (int i = 0; i < num_sushis; i++) {
if (sushi[i] == 1) {
... | fn solution() {
let stream = io::stdin();
let line = stream
.lock()
.lines()
.nth(1)
.expect("Iterator is inf")
.expect("Blah");
let result = line.trim().split(" ").filter_map(|x| x.parse::<u8>().ok());
let mut cnts = [0u64; 2];
let mut prev = 0u8;
let mu... | hard |
1694 | <span class="lang-en">
<p>Score: <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>A triple of numbers is said to be <em>poor</em> when two of those numbers are equal but the other number is different from those two numbers.</p>
<p>You will be given three integers <var>A</var>, <var>B... | int solution(void) {
int a = 0;
int b = 0;
int c = 0;
scanf("%d %d %d", &a, &b, &c);
if (a == b && a != c) {
printf("Yes");
}
if (b == c && a != c) {
printf("Yes");
}
if (a == c && a != b) {
printf("Yes");
}
if (a == c && a == b) {
printf("No");
}
if (a != c && a != b && b !=... | fn solution() {
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("Failed to read line.");
let x: Vec<&str> = input.split_whitespace().collect();
if x.len() == 3 {
let mut count = 0;
if x[0] == x[1] {
count += 1;
}
if x[... | easy |
1695 | You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the displ... | int solution() {
int n;
int i;
int j;
int arr[2000];
scanf("%d", &n);
char s[1003];
scanf("%s", s);
for (i = 0; i < n; i++) {
arr[i] = s[i] - '0';
}
int start = 0;
int min[1003];
for (i = 0; i < n; i++) {
min[i] = 10;
}
int curr[1003];
for (i = 0; i < n; i++) {
start = i;
... | fn solution() {
let n = {
let mut line = String::new();
stdin().read_line(&mut line).unwrap();
let mut iter = line.split_whitespace();
iter.next().unwrap().parse::<usize>().unwrap()
};
let mut line = String::new();
stdin().read_line(&mut line).unwrap();
let line: Vec... | medium |
1696 | You are given a matrix with $$$n$$$ rows (numbered from $$$1$$$ to $$$n$$$) and $$$m$$$ columns (numbered from $$$1$$$ to $$$m$$$). A number $$$a_{i, j}$$$ is written in the cell belonging to the $$$i$$$-th row and the $$$j$$$-th column, each number is either $$$0$$$ or $$$1$$$.A chip is initially in the cell $$$(1, 1)... | int solution() {
int n;
scanf("%d", &n);
while (n--) {
int m;
int n;
scanf("%d %d", &m, &n);
int matrix[m + 1][n + 1];
for (int l = 1; l <= m; l++) {
for (int r = 1; r <= n; r++) {
scanf("%d", &matrix[l][r]);
}
}
int min = 0;
if (matrix[1][1] != matrix[m][n]) {
... | fn solution() {
let mut s: String = String::new();
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 h: usize = itr.next().unwrap().parse().unwrap();
let w: u... | hard |
1697 | Little Susie loves strings. Today she calculates distances between them. As Susie is a small girl after all, her strings contain only digits zero and one. She uses the definition of Hamming distance:We will define the distance between two strings s and t of the same length consisting of digits zero and one as the numbe... | int solution() {
char S[100001];
char T[100001];
int i;
int N = 0;
scanf("%s %s", S, T);
for (i = 0; S[i] != '\0'; ++i) {
if (S[i] != T[i]) {
++N;
}
}
if (N & 1) {
puts("impossible");
return 0;
}
N /= 2;
for (i = 0; S[i] != '\0'; ++i) {
if (S[i] != T[i]) {
putchar(N... | fn solution() {
let inputstatus = 1;
let mut buf = String::new();
let filename = "inputrust.txt";
if inputstatus == 0 {
let mut f = File::open(filename).expect("file not found");
f.read_to_string(&mut buf)
.expect("something went wrong reading the file");
} else {
... | easy |
1698 | Given an array $$$a$$$ of length $$$n$$$, you can do at most $$$k$$$ operations of the following type on it: choose $$$2$$$ different elements in the array, add $$$1$$$ to the first, and subtract $$$1$$$ from the second. However, all the elements of $$$a$$$ have to remain non-negative after this operation. What is lex... | int solution() {
int t = 0;
scanf("%d", &t);
int n = 0;
int k = 0;
int index = 0;
int a[101] = {0};
while (t-- > 0) {
index = 0;
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i < k; i++) {
while (a[index] <= 0) {
... | fn solution() {
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
let tt: u32 = input.trim().parse().unwrap();
for _ in 0..tt {
input = String::new();
io::stdin().read_line(&mut input).unwrap();
let v: Vec<&str> = input.trim().split(" ").collect();
... | medium |
1699 | Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The sto... | int solution() {
long long int k;
long long int d;
long long int t;
scanf("%lld %lld %lld", &k, &d, &t);
if (k % d == 0 || t <= k) {
printf("%lf", (double)t);
} else {
long long int x;
if (d >= k) {
x = d;
} else {
long long int c = k / d;
x = (c + 1) * d;
}
t *= 2... | fn solution() {
let mut input = String::new();
use std::io;
use std::io::prelude::*;
io::stdin().read_to_string(&mut input).unwrap();
let mut it = input.split_whitespace();
let k: u64 = it.next().unwrap().parse().unwrap();
let d: u64 = it.next().unwrap().parse().unwrap();
let t: u64 = ... | easy |
1700 | In the pet store on sale there are: $$$a$$$ packs of dog food; $$$b$$$ packs of cat food; $$$c$$$ packs of universal food (such food is suitable for both dogs and cats). Polycarp has $$$x$$$ dogs and $$$y$$$ cats. Is it possible that he will be able to buy food for all his animals in the store? Each of his dogs and ... | int solution(int argc, char const *argv[]) {
int t = 0;
scanf("%d", &t);
unsigned long a = 0;
unsigned long b = 0;
unsigned long c = 0;
unsigned long x = 0;
unsigned long y = 0;
unsigned long common_pets = 0;
unsigned long results[10000];
for (int i = 0; i < t; i++) {
a = b = c = x = y = 0;
... | fn solution() {
let mut t = String::new();
stdin().read_line(&mut t);
let t = t.trim().parse::<usize>().unwrap();
for _ in 0..t {
let mut buf = String::new();
stdin().read_line(&mut buf);
let mut v = Vec::with_capacity(5);
for i in buf.split_whitespace() {
v... | medium |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.