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 |
|---|---|---|---|---|
1701 | The game of Berland poker is played with a deck of $$$n$$$ cards, $$$m$$$ of which are jokers. $$$k$$$ players play this game ($$$n$$$ is divisible by $$$k$$$).At the beginning of the game, each player takes $$$\frac{n}{k}$$$ cards from the deck (so each card is taken by exactly one player). The player who has the maxi... | int solution() {
int t;
scanf("%d", &t);
int n[t];
int m[t];
int k[t];
int i;
for (i = 0; i < t; i++) {
scanf("%d %d %d", &n[i], &m[i], &k[i]);
}
for (i = 0; i < t; i++) {
int j;
int d;
int l;
d = n[i] / k[i];
l = (m[i] - d) % k[i];
if (m[i] == 0) {
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 t: usize = itr.next().unwrap().parse().unwrap();
let mut out = Vec::new();
for _ in 0..t {
let n: usize = itr.next().unwrap().parse().unwrap();
... | easy |
1702 | YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of seq... | int solution() {
int testcase;
scanf("%d", &testcase);
while (testcase--) {
int n;
scanf("%d", &n);
int a[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
int ok = 1;
for (int i = 0; i < n; i++) {
int flag = 0;
for (int j = 2; j <= i + 2; j++) {
if (... | fn solution() -> std::io::Result<()> {
let mut input = String::new();
stdin().read_to_string(&mut input)?;
let mut input_iter = input.split_whitespace();
let mut next_int = || input_iter.next().unwrap().parse::<i64>().unwrap();
'task: for _ in 0..next_int() {
let n = next_int() as usize;
... | easy |
1703 | <H1>Doubly Linked List</H1>
<p>
Your task is to implement a double linked list.
</p>
<p>
Write a program which performs the following operations:
</p>
<ul>
<li>insert x: insert an element with key x into the front of the list.</li>
<li>delete x: delete the first element which has the key of x from the list. If there ... | int solution() {
int i;
int j;
int a;
int num;
int y = 0;
int l;
int h;
int key;
scanf("%d", &a);
int list[a];
char input[12];
for (i = 0; i < a; i++) {
scanf("%s %d", input, &num);
if (input[0] == 'i') {
list[i] = num;
}
else if (input[6] == 'F') {
i -= 2;
... | fn solution() {
let stdin = std::io::stdin();
let mut buf = String::new();
stdin.read_line(&mut buf).ok();
let n: usize = buf.trim().parse().unwrap_or(0);
let mut dll = Vec::new();
let mut head = 0;
for _ in 0..n {
let mut buf = String::new();
stdin.read_line(&mut buf).ok(... | hard |
1704 | Andre has very specific tastes. Recently he started falling in love with arrays.Andre calls an nonempty array $$$b$$$ good, if sum of its elements is divisible by the length of this array. For example, array $$$[2, 3, 1]$$$ is good, as sum of its elements — $$$6$$$ — is divisible by $$$3$$$, but array $$$[1, 1, 2, 3]$$... | int solution() {
int n = 0;
scanf("%d", &n);
int test[100];
int temp = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &temp);
test[i] = temp;
}
int arr[200];
for (int i = 0; i < 200; i++) {
arr[i] = 1;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < test[i]; j++) {
pri... | fn solution() {
let mut inp = String::new();
stdin().read_line(&mut inp).unwrap();
let t: u16 = inp.trim().parse().unwrap();
inp.clear();
for _ in 0..t {
stdin().read_line(&mut inp).unwrap();
let n: u16 = inp.trim().parse().unwrap();
for _ in 1..n {
print!("3 ");
... | hard |
1705 | Alice and Bob received $$$n$$$ candies from their parents. Each candy weighs either 1 gram or 2 grams. Now they want to divide all candies among themselves fairly so that the total weight of Alice's candies is equal to the total weight of Bob's candies.Check if they can do that.Note that candies are not allowed to be c... | int solution() {
int T;
scanf("%d", &T);
while (T--) {
int arr[100];
int n;
scanf("%d", &n);
int num = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
if (arr[i] == 2) {
num++;
}
}
if ((n % 2 && num % 2 && n != num) || (n % 2 == 0 && num % 2 == 0)) {
... | 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 mut candies = String::new();
io::stdin().read_line(&mut candies).unwra... | medium |
1706 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a sequence <var>X</var> of length <var>N</var>, where every element is initially <var>0</var>. Let <var>X_i</var> denote the <var>i</var>-th element of <var>X</var>.</p>
<p>You are given a sequ... | int solution(void) {
long long n;
long long ans = 0;
scanf("%lld", &n);
long long a[n + 1];
a[n] = 0;
for (long long i = 0; i < n; i++) {
scanf("%lld", &a[i]);
}
if (n == 1) {
if (a[0] == 0) {
printf("0\n");
} else {
printf("-1\n");
}
return 0;
}
for (long long i = 1;... | fn solution() {
let mut buf = String::new();
stdin().read_line(&mut buf).unwrap();
let n = buf.trim().parse::<usize>().unwrap();
let mut a: Vec<usize> = BufReader::new(stdin())
.lines()
.map(|l| l.unwrap().trim().parse::<usize>().unwrap())
.collect();
for (i, &n) in a.iter().... | easy |
1707 | This is an interactive problem.We hid from you a permutation $$$p$$$ of length $$$n$$$, consisting of the elements from $$$1$$$ to $$$n$$$. You want to guess it. To do that, you can give us 2 different indices $$$i$$$ and $$$j$$$, and we will reply with $$$p_{i} \bmod p_{j}$$$ (remainder of division $$$p_{i}$$$ by $$$p... | int solution() {
int n;
scanf("%d", &n);
int p[10004];
int x;
int y;
int res[2];
int i;
int j;
for (i = 0; i < n; i++) {
p[i] = -1;
}
i = 0;
for (int a = 0; a < n - 1; a++) {
j = 0;
while (p[j] > 0 || j == i) {
j++;
}
printf("? %d %d\n", i + 1, j + 1);
fflush(stdout... | 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 = vec![0; n + 1];
let mut unk_idx = 1;
for i in 2..=n {
println!("? {} {}", unk_idx, i);
let k1: usize ... | medium |
1708 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given positive integers <var>X</var> and <var>Y</var>.
If there exists a positive integer not greater than <var>10^{18}</var> that is a multiple of <var>X</var> but not a multiple of <var>Y</var... | int solution() {
int a;
int b;
int x;
scanf("%d %d", &a, &b);
x = -1;
if (b != 0 && a % b != 0) {
x = a;
}
printf("%d\n", x);
return 0;
} | fn solution() {
let base: u64 = 10;
let scan = stdin();
let mut line = String::new();
let _ = scan.read_line(&mut line);
let mut iter = line.split_whitespace();
let x: u64 = iter
.next()
.expect("Iteration Error?")
.trim()
.parse()
.expect("Number pls...... | hard |
1709 | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way po... | int solution() {
int n = 0;
scanf("%d", &n);
int nr = n;
int size = 1;
int tow[n];
for (int i = 0; i < n; i++) {
scanf("%d", &tow[i]);
}
int dub[1001] = {0};
for (int i = 0; i < n; i++) {
if (dub[i] == 1) {
continue;
}
int sz = 1;
for (int j = i + 1; j < n; j++) {
if ... | fn solution() {
let mut s0 = String::new();
std::io::stdin().read_line(&mut s0).unwrap();
let n: usize = s0.trim_end().parse().unwrap();
let mut s1 = String::new();
std::io::stdin().read_line(&mut s1).unwrap();
let mut v: Vec<usize> = s1
.trim_end()
.to_string()
.split_w... | hard |
1710 | As their story unravels, a timeless tale is told once again...Shirahime, a friend of Mocha's, is keen on playing the music game Arcaea and sharing Mocha interesting puzzles to solve. This day, Shirahime comes up with a new simple puzzle and wants Mocha to solve them. However, these puzzles are too easy for Mocha to sol... | int solution() {
int t;
scanf("%d", &t);
for (int i = 1; i <= t; i++) {
int n;
scanf("%d", &n);
char str[100];
scanf("%s", str);
for (int i = 0; i < 100; i++) {
if (str[i] == '?' && str[i - 1] == 'R') {
int k = i % 2;
while (str[i] == '?') {
if (i % 2 == k) {
... | 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().par... | easy |
1711 | Your friend Mishka and you attend a calculus lecture. Lecture lasts n minutes. Lecturer tells ai theorems during the i-th minute.Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array t of Mishka's behavior. If Mishka is asleep during the i-th min... | int solution() {
int n;
int k;
scanf("%d%d", &n, &k);
int matrix[2][n];
int beiyong[n];
memset(matrix, 0, sizeof(int) * 2 * n);
memset(beiyong, 0, sizeof(int) * n);
for (int i = 0; i < n; i++) {
scanf("%d", &matrix[0][i]);
}
for (int i = 0; i < n; i++) {
scanf("%d", &matrix[1][i]);
}
in... | fn solution() {
let mut input1 = String::new();
io::stdin().read_line(&mut input1);
let mut iter1 = input1
.split_whitespace()
.map(|x| x.parse::<usize>().unwrap());
let n = iter1.next().unwrap();
let k = iter1.next().unwrap();
let mut input2 = String::new();
io::stdin().rea... | hard |
1712 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>N</var> points in the two-dimensional plane. The coordinates of the <var>i</var>-th point are <var>(X_i,Y_i)</var>.</p>
<p>Among them, we are looking for the points such that the distance f... | int solution(void) {
int n = 0;
long int d = 0;
long int a = 0;
long int b = 0;
int count = 0;
scanf("%d %ld", &n, &d);
d *= d;
while (n--) {
scanf("%ld %ld", &a, &b);
if (d >= (a * a + b * b)) {
count++;
}
}
printf("%d\n", count);
return 0;
} | fn solution() {
let (n, d): (usize, i64) = {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
let mut iter = buf.split_whitespace();
(
iter.next().unwrap().parse().unwrap(),
iter.next().unwrap().parse().unwrap(),
)
};
... | easy |
1713 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>2000001</var> stones placed on a number line. The coordinates of these stones are <var>-1000000, -999999, -999998, \ldots, 999999, 1000000</var>.</p>
<p>Among them, some <var>K</var> cons... | int solution(void) {
int K = 0;
int X = 0;
int min = 0;
int max = 0;
scanf("%d %d", &K, &X);
min = X - K + 1;
max = X + K - 1;
for (int i = min; i <= max; i++) {
printf("%d ", i);
}
printf("\n");
return 0;
} | fn solution() {
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).unwrap();
let mut iter = buf.split_whitespace();
let k: i32 = iter.next().unwrap().parse().unwrap();
let x: i32 = iter.next().unwrap().parse().unwrap();
let from = x - k + 1;
let to = x + k - 1;
print... | medium |
1714 | <!--<h1>写像12相 その8:ボールに区別あり・箱に区別なし・箱の中身は1つ以下</h1>-->
<h1>Balls and Boxes 8</h1>
<table border="">
<tr><th>Balls</th><th>Boxes</th><th>Any way</th><th>At most one ball</th><th>At least one ball</th></tr>
<tr><th>Distinguishable</th><th>Distinguishable</th><td>1</td><td>2</td><td>3</td></tr>
<tr><th>Indistinguishab... | int solution() {
int n;
int k;
scanf("%d%d", &n, &k);
puts(n <= k ? "1" : "0");
return 0;
} | fn solution() {
input!(n:i64,k:i64);
if n > k {
println!("0");
} else {
println!("1");
}
} | easy |
1715 | You are given an array $$$a_1, a_2, \ldots, a_n$$$ consisting of $$$n$$$ positive integers and a positive integer $$$m$$$.You should divide elements of this array into some arrays. You can order the elements in the new arrays as you want.Let's call an array $$$m$$$-divisible if for each two adjacent numbers in the arra... | int solution() {
int t;
scanf("%d", &t);
int n;
int m;
for (int i = 0; i < t; i++) {
int count = 0;
scanf("%d %d", &n, &m);
int arr[n];
int store[m];
for (int j = 0; j < m; j++) {
store[j] = 0;
}
for (int j = 0; j < n; j++) {
scanf("%d", &arr[j]);
store[arr[j] %... | fn solution() {
let mut n = String::new();
io::stdin().read_line(&mut n).unwrap();
let n = n.trim().parse().unwrap();
for _i in 0..n {
let mut s = String::new();
io::stdin().read_line(&mut s).unwrap();
let v = s
.split_whitespace()
.map(|x| x.parse::<i32>(... | hard |
1716 | There are $$$n$$$ friends who want to give gifts for the New Year to each other. Each friend should give exactly one gift and receive exactly one gift. The friend cannot give the gift to himself.For each friend the value $$$f_i$$$ is known: it is either $$$f_i = 0$$$ if the $$$i$$$-th friend doesn't know whom he wants ... | int solution() {
int i;
int n;
scanf("%d", &n);
int giftGiving[n];
int giftGetting[n];
int giftNot[n];
int top = 0;
int bottom = 0;
for (i = 0; i < n; i++) {
giftGetting[i] = 0;
}
for (i = 0; i < n; i++) {
scanf("%d", &giftGiving[i]);
giftGetting[giftGiving[i] - 1] = 1;
}
for (i = ... | fn solution() {
let mut n = String::new();
std::io::stdin().read_line(&mut n).unwrap();
let n: usize = n.trim().parse().unwrap();
let mut l2 = String::new();
std::io::stdin().read_line(&mut l2).unwrap();
let mut f = Vec::with_capacity(n + 1);
f.push(0usize);
for it in l2.split_whitespace... | medium |
1717 | You are given an array $$$a_1, a_2, \dots, a_n$$$ where all $$$a_i$$$ are integers and greater than $$$0$$$. In one operation, you can choose two different indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$). If $$$gcd(a_i, a_j)$$$ is equal to the minimum element of the whole array $$$a$$$, you can swap $$$a_i$$$ and ... | int solution() {
int t;
scanf("%d", &t);
for (int tt = 0; tt < t; tt++) {
int n;
scanf("%d", &n);
int a[n];
int b[n];
int min = 1000000000;
int c = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
b[i] = a[i];
if (a[i] < min) {
min = a[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()... | easy |
1718 | You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. | int solution() {
int count = 0;
scanf("%d\n", &count);
int last = 0;
int i = 0;
int ninccount = 0;
int maxinccount = 0;
for (; i < count; i++) {
int now = 0;
scanf("%d", &now);
if (last < now) {
ninccount++;
} else {
if (maxinccount < ninccount) {
maxinccount = ninccoun... | fn solution() {
let handle = io::stdin();
let line = &mut String::new();
handle.read_line(line).unwrap();
let n = line.trim().parse::<usize>().unwrap();
line.clear();
handle.read_line(line).unwrap();
let a: &mut Vec<u32> = &mut line
.split_whitespace()
.map(|x| x.parse::<u32>... | hard |
1719 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>The problem set at <em>CODE FESTIVAL 20XX Finals</em> consists of <var>N</var> problems.</p>
<p>The score allocated to the <var>i</var>-th <var>(1≦i≦N)</var> problem is <var>i</var> points.</p>
<p>Takah... | int solution() {
long n = 0;
long maxi = 0;
long i = 0;
long remove = 0;
scanf("%ld", &n);
for (i = 1; i < n; i++) {
if (((i + 1) * i) / 2 >= n) {
break;
}
}
maxi = i;
remove = (maxi * (maxi + 1)) / 2 - n;
for (i = 1; i <= maxi; i++) {
if (i != remove) {
printf("%ld\n", i);... | fn solution() {
let mut s: String = String::new();
std::io::stdin().read_to_string(&mut s).ok();
let mut itr = s.split_whitespace();
let n: usize = itr.next().unwrap().parse().unwrap();
let mut out = Vec::new();
let mut ng = 0;
let mut ok = n;
while ok - ng > 1 {
let mid = (ok +... | hard |
1720 | You are given a number $$$k$$$ and a string $$$s$$$ of length $$$n$$$, consisting of the characters '.' and '*'. You want to replace some of the '*' characters with 'x' characters so that the following conditions are met: The first character '*' in the original string should be replaced with 'x'; The last character ... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
int k;
scanf("%d %d", &n, &k);
char str[n + 1];
scanf("%s", str);
int dis = -1;
int preindex = 0;
int bufferdex = 0;
int tot = 0;
int nextdex = 0;
int counttot = 0;
for (int i = 0; i < n; i++) {
if ... | 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, k): (usize, usize) = (sc.next(), sc.next());
let s: Vec<char> ... | easy |
1721 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are an integer sequence <var>A_1,...,A_N</var> consisting of <var>N</var> terms, and <var>N</var> buttons.
When the <var>i</var>-th <var>(1 ≦ i ≦ N)</var> button is pressed, the values of the <var... | int solution(void) {
int n;
long long ans = 0;
scanf("%d", &n);
long long a[n];
long long b[n];
for (int i = 0; i < n; i++) {
scanf("%lld%lld", &a[i], &b[i]);
}
for (int i = n - 1; i >= 0; i--) {
a[i] += ans;
if (a[i] % b[i] != 0) {
ans += b[i] - (a[i] % b[i]);
}
}
printf("%lld... | 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:... | easy |
1722 | <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>Matrix-chain Multiplication<... | int solution(void) {
int i;
int j;
int k;
int n;
scanf("%d", &n);
int M[n][2];
for (i = 0; i < n; i++) {
scanf("%d", &M[i][0]);
scanf("%d", &M[i][1]);
}
int x[n][n];
for (i = 1; i < n; i++) {
for (j = 0; j < n; j++) {
x[i][j] = 999999;
}
}
for (j = 0; j < n; j++) {
... | fn solution() {
let mut buf = String::new();
let _ = std::io::stdin().read_line(&mut buf).ok();
let n: usize = buf.trim().parse().unwrap();
let mut mats = vec![vec![(0, 0, 0); n]; n];
for i in 0..n {
let mut buf = String::new();
let _ = std::io::stdin().read_line(&mut buf).ok();
... | medium |
1723 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Consider a grid with <var>H</var> rows and <var>W</var> columns of squares. Let <var>(r, c)</var> denote the square at the <var>r</var>-th row from the top and the <var>c</var>-th column from the left.
... | int solution(void) {
int h;
int w;
scanf("%d %d", &h, &w);
char s[h][w + 1];
for (int i = 0; i < h; i++) {
scanf("%s", s[i]);
}
int dp[h][w];
dp[0][0] = 0;
if (s[0][0] == '#') {
dp[0][0] = 1;
}
for (int i = 1; i < w; i++) {
dp[0][i] = dp[0][i - 1];
if (s[0][i - 1] == '.' && s[0][i... | fn solution() {
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).ok();
let mut it = buf.split_whitespace();
let h = it.next().unwrap().parse::<usize>().unwrap();
let w = it.next().unwrap().parse::<usize>().unwrap();
let s = (0..h)
.map(|_| it.next().unwrap().as_byte... | easy |
1724 | The string $$$s$$$ is given, the string length is odd number. The string consists of lowercase letters of the Latin alphabet.As long as the string length is greater than $$$1$$$, the following operation can be performed on it: select any two adjacent letters in the string $$$s$$$ and delete them from the string. For ex... | int solution() {
int t;
scanf("%d", &t);
while (t-- > 0) {
char s[49];
char c;
scanf("%s %c", s, &c);
int count = 0;
int i = 0;
while (s[i] != '\0') {
if (s[i] == c && i % 2 == 0) {
count = 1;
break;
}
i++;
}
if (count == 1) {
printf("YES\n")... | fn solution() {
let out = &mut BufWriter::new(stdout());
let mut input = String::new();
let _firstline = stdin().read_line(&mut input).ok();
let t = input.trim_end().parse::<u32>().expect("Failed parsed");
for _ in 0..t {
let mut src = String::new();
let mut target = String::new()... | medium |
1725 | <h2>水道料金 (Water Rate)</h2>
<h2> 問題</h2>
<p>
JOI 君が住んでいる地域には水道会社が X 社と Y 社の 2 つある.2 つの会社の 1 ヶ月の水道料金は,1 ヶ月の水道の使用量に応じて次のように決まる.
</p>
<ul>
<li>X 社: 1 リットル あたり A 円かかる.</li>
<li>Y 社: 基本料金は B 円である.使用量が C リットル以下ならば,料金は基本料金 B 円のみがかかる.使用量が C リットルを超えると基本料金 B 円に加えて追加料金がかかる.追加料金は使用量が C リットルを 1 リットル超えるごとに D 円である.</li>
</ul>
<p>
... | int solution(void) {
int P = 0;
int A = 0;
int B = 0;
int C = 0;
int D = 0;
scanf("%d %d %d %d %d", &A, &B, &C, &D, &P);
int X = A * P;
int Y = B;
int y = ((P - C) * D) + B;
if (P <= C) {
if (X >= Y) {
printf("%d\n", Y);
} else if (X < Y) {
printf("%d\n", X);
}
}
if (P... | fn solution() {
let input = {
let mut buf = vec![];
stdin().read_to_end(&mut buf);
unsafe { String::from_utf8_unchecked(buf) }
};
let mut lines = input.split('\n').map(|s| s.parse::<u32>().unwrap());
let a = lines.next().unwrap();
let b = lines.next().unwrap();
let c = l... | easy |
1726 | Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and the ... | int solution() {
int n = 0;
int x = 0;
int y = 0;
int count = 0;
scanf("%d", &n);
int a[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i < n; i++) {
if (a[i] == 0) {
count++;
x = 0;
y = 0;
} else if (a[i] == 1) {
if (y == 1) {
count+... | fn solution() {
let stdin = std::io::stdin();
let n = {
let mut buf = String::new();
stdin.read_line(&mut buf).unwrap();
buf.trim().parse::<usize>().unwrap()
};
let mut a = vec![0; n];
for (i, cur) in stdin.lock().split(b' ').enumerate() {
let str = String::from_utf8... | medium |
1727 | Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The $$$i$$$-th page contains some mystery that will be explained on page $$$a_i$$$ ($$$a_i \ge i$$$).Ivan wants to read the whole book. Each day, he reads the f... | int solution(void) {
int n = 0;
scanf("%d", &n);
int max = 0;
int days = 0;
for (int i = 1; i <= n; i++) {
int a = 0;
scanf("%d", &a);
if (a > max) {
max = a;
}
if (a == max && a == i) {
days++;
}
}
printf("%d\n", days);
return 0;
} | fn solution() {
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
let _n = input.trim().parse::<usize>().unwrap();
input.clear();
io::stdin().read_line(&mut input).unwrap();
let v: Vec<usize> = input
.split_whitespace()
.map(|x| x.parse::<usize>().unwrap(... | easy |
1728 | <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> cities on a number line. The <var>i</var>-th city is located at coordinate <var>x_i</var>.</p>
<p>Your objective is to visit all these cities at least once.</p>
<p>In order to do ... | int solution() {
int n;
int x;
int y;
int d;
int i;
int j;
int k;
int t;
scanf("%d %d", &n, &x);
for (d = i = 0; i < n; i++) {
scanf("%d", &y);
if (d == 0) {
d = abs(x - y);
} else {
j = d;
k = abs(x - y);
if (k > j) {
t = j;
j = k;
k = t;... | fn solution() {
input! {
n: usize,
init: i32,
xs: [i32; n],
}
let xs = {
let mut xs: Vec<_> = xs.iter().map(|x| x - init).collect();
xs.push(0);
xs.sort();
xs
};
let min_d = xs.windows(2).map(|w| w[1] - w[0]).min().unwrap();
for d in (1..mi... | hard |
1729 | Ichihime is the current priestess of the Mahjong Soul Temple. She claims to be human, despite her cat ears.These days the temple is holding a math contest. Usually, Ichihime lacks interest in these things, but this time the prize for the winner is her favorite — cookies. Ichihime decides to attend the contest. Now she ... | int solution() {
int a[1000][4];
int b[1000][3];
int listNum;
scanf("%d", &listNum);
for (int i = 0; i < listNum; i++) {
scanf("%d %d %d %d", &a[i][0], &a[i][1], &a[i][2], &a[i][3]);
b[i][0] = a[i][0];
b[i][1] = a[i][2];
b[i][2] = a[i][2];
}
for (int i = 0; i < listNum; i++) {
printf(... | fn solution() {
let mut str = String::new();
let _ = stdin().read_line(&mut str).unwrap();
let test: i64 = str.trim().parse().unwrap();
for _ in 0..test {
str.clear();
let _ = stdin().read_line(&mut str).unwrap();
let mut iter = str.split_whitespace();
let _: i64 = iter.n... | hard |
1730 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has <var>3</var> keys on it: the <code>0</code> key, the <code>1</code> key and the backspace key.</p>
<p>To begin wi... | int solution(void) {
char str[15];
int i = 0;
while ((str[i] = getchar()) != '\n') {
if (str[i] == 'B' && i != 0) {
i--;
str[i] = '\0';
continue;
}
if (str[i] == 'B') {
continue;
}
i++;
}
str[i] = '\0';
printf("%s\n", str);
return 0;
} | fn solution() {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
let s = buf.trim();
let mut stack = Vec::with_capacity(s.len());
for c in s.chars() {
match c {
'B' => {
stack.pop();
}
_ => {
sta... | medium |
1731 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Let <var>w</var> be a string consisting of lowercase letters.
We will call <var>w</var> <em>beautiful</em> if the following condition is satisfied:</p>
<ul>
<li>Each lowercase letter of the English alph... | int solution() {
char w[101];
int keys[26] = {0};
int flag = 0;
scanf("%s", w);
for (int i = 0; w[i] != '\0'; i++) {
keys[w[i] - 'a']++;
}
for (int i = 0; i < 26; i++) {
flag = (flag | keys[i]);
}
printf((flag & 1) == 0 ? "Yes\n" : "No\n");
return 0;
} | fn solution() {
let mut s = String::new();
stdin().read_line(&mut s).ok();
let w = s.trim();
let mut d = HashMap::new();
for e in w.chars() {
*d.entry(e).or_insert(0) += 1;
}
println!(
"{}",
if d.iter().all(|e| *e.1 % 2 == 0) {
"Yes"
} else {
... | medium |
1732 | Vasya has the square chessboard of size n × n and m rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another.The cell of the field is under rook's attack, if there is at least one rook located in the same row or in the same column with this cell. If there is a rook ... | int solution() {
long long int n;
long long int m;
scanf("%lli %lli", &n, &m);
int i;
int rows[n + 1];
int columns[n + 1];
int rws = 0;
int cols = 0;
long long int frees[m];
long long int freeCounter = 0;
for (i = 1; i <= n; i++) {
rows[i] = columns[i] = 0;
}
long long int free = n * n;
... | fn solution() {
let mut buffer = String::new();
std::io::stdin().read_to_string(&mut buffer).unwrap();
let mut cin = buffer
.split_whitespace()
.map(|x| x.parse::<usize>().unwrap());
let n = cin.next().unwrap();
cin.next().unwrap();
let mut cntx = n as u64;
let mut cnty = n... | hard |
1733 | As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has n servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of ... | int solution() {
int n;
int m;
scanf("%d%d", &n, &m);
char name[1000][15];
int ip[1000][15];
for (int i = 0; i < n; i++) {
scanf("%s", &name[i][0]);
scanf("%d.%d.%d.%d", &ip[i][0], &ip[i][1], &ip[i][2], &ip[i][3]);
}
char name2[15];
int ip2[4];
for (int i = 0; i < m; i++) {
scanf("%s", n... | fn solution() {
let mut buffer = String::new();
io::stdin().read_to_string(&mut buffer).unwrap();
let mut lines = buffer.lines();
let nm: Vec<i32> = lines
.next()
.unwrap()
.split_whitespace()
.map(|s| s.parse::<i32>().unwrap())
.collect();
let (n, m) = (nm[... | medium |
1734 | You are given a square grid with $$$n$$$ rows and $$$n$$$ columns. Each cell contains either $$$0$$$ or $$$1$$$. In an operation, you can select a cell of the grid and flip it (from $$$0 \to 1$$$ or $$$1 \to 0$$$). Find the minimum number of operations you need to obtain a square that remains the same when rotated $$$0... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
char a[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
scanf(" %c", &a[i][j]);
}
}
int x = 0;
int c = 0;
int y = 0;
int z = n - 1;
int w = n - 1;
while... | fn solution() {
let (stdin, stdout) = (io::stdin(), io::stdout());
let mut scan = Scanner::new(stdin.lock());
let mut out = io::BufWriter::new(stdout.lock());
let t = scan.next();
for _ in 0..t {
let n: usize = scan.next();
let mut v: Vec<Vec<char>> = Vec::new();
for _i in 0.... | medium |
1735 | Given an array $$$a$$$ of $$$n$$$ elements, print any value that appears at least three times or print -1 if there is no such value. | int solution() {
int n;
scanf("%d", &n);
int number = 0;
int count = 0;
int frq[200001] = {0};
for (int j = 0; j < n; j++) {
scanf("%d", &number);
for (int f = 0; f < 200001; f++) {
frq[f] = 0;
}
for (int i = 0; i < number; i++) {
int arr[i];
scanf("%d", &arr[i]);
frq... | fn solution() {
let mut input = String::new();
std::io::stdin()
.read_line(&mut input)
.expect("couldn't read from input");
let num_test_cases: isize = input.trim().parse().expect("couldn't parse number");
for _ in 0..num_test_cases {
let mut input = String::new();
std::... | medium |
1736 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You have decided to give an allowance to your child depending on the outcome of the game that he will play now.</p>
<p>The game is played as follows:</p>
<ul>
<li>There are three "integer panels", each ... | int solution() {
int a = 0;
int b = 0;
int c = 0;
scanf("%d %d %d", &a, &b, &c);
if (a >= b && a >= c) {
printf("%d\n", (a * 10) + b + c);
} else if (b >= a && b >= c) {
printf("%d\n", (b * 10) + a + c);
} else if (c >= a && c >= b) {
printf("%d\n", (c * 10) + a + b);
}
return 0;
} | fn solution() {
let stdin = std::io::stdin();
let mut reader = std::io::BufReader::new(stdin.lock());
let mut s = String::new();
let _ = reader.read_line(&mut s);
let mut v: Vec<u32> = s.split_whitespace().map(|x| x.parse().unwrap()).collect();
v.sort();
println!("{}", v[2] * 10 + v[1] +... | medium |
1737 | Vlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he ... | int solution() {
int n;
int a[(2 * 100000) + 1] = {0};
int b[(2 * 100000) + 1] = {0};
int min = INT_MAX;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
b[a[i] - 1] = i;
}
int count = 0;
for (int i = 0; i < n; i++) {
if (min > b[a[i] - 1]) {
min = b[a[i] - 1];
... | fn solution() {
let mut text = String::new();
stdin().read_line(&mut text).unwrap();
text.clear();
stdin().read_line(&mut text).unwrap();
let a: Vec<usize> = text
.split_whitespace()
.map(|e| e.parse().unwrap())
.collect();
let mut hash: HashMap<usize, usize> = HashMap::n... | hard |
1738 | You are given a system of pipes. It consists of two rows, each row consists of $$$n$$$ pipes. The top left pipe has the coordinates $$$(1, 1)$$$ and the bottom right — $$$(2, n)$$$.There are six types of pipes: two types of straight pipes and four types of curved pipes. Here are the examples of all six types: Types of... | int solution(void) {
int n;
int q;
static int a[2][200000];
static int b[100000];
scanf("%d", &q);
for (int i = 0; i < q; i++) {
scanf("%d", &n);
for (int j = 0; j < 2; j++) {
for (int k = 0; k < n; k++) {
scanf("%1d", &a[j][k]);
}
}
int g = 1;
int l = 0;
int r = ... | fn solution() {
let reader = io::stdin();
let mut result = Vec::new();
let queries_count = reader
.lock()
.lines()
.next()
.unwrap()
.unwrap()
.parse::<u32>()
.unwrap();
for _i in 0..queries_count {
let n = reader
.lock()
... | medium |
1739 | You are given a string $$$s$$$, consisting of lowercase Latin letters. Every letter appears in it no more than twice.Your task is to rearrange the letters in the string in such a way that for each pair of letters that appear exactly twice, the distance between the letters in the pair is the same. You are not allowed to... | int solution() {
unsigned int tests;
scanf("%u\n", &tests);
for (unsigned int l = 0; l != tests; ++l) {
char s[64];
fgets(s, sizeof(s), stdin);
char frec['z' + 1] = {0};
for (const char *i = s; *i && *i != '\n'; ++i) {
++frec[*i];
}
for (char i = 'a'; i <= 'z'; ++i) {
while ... | fn solution() {
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("failed to read input.");
let t: i32 = input.trim().parse().expect("invalid input");
let mut i = 0;
while i < t {
let mut s = String::new();
io::stdin()
.read_line(... | hard |
1740 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>An uppercase or lowercase English letter <var>\alpha</var> will be given as input.
If <var>\alpha</var> is uppercase, print <code>A</code>; if it is lowercase, print <code>a</code>.</p>
</section>
</div... | int solution() {
char str[2];
char *pt = &str[0];
scanf("%s", str);
if ('A' <= *pt && *pt <= 'Z') {
printf("A\n");
} else if ('a' <= *pt && *pt <= 'z') {
printf("a\n");
}
return 0;
} | fn solution() {
let mut is = String::new();
stdin().read_line(&mut is).ok();
is.pop();
println!(
"{}",
if is.chars().all(|c| c.is_ascii_uppercase()) {
'A'
} else {
'a'
}
);
} | medium |
1741 | You are given an array $$$a_1, a_2, \ldots, a_n$$$.In one operation you can choose two elements $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$) and decrease each of them by one.You need to check whether it is possible to make all the elements equal to zero or not. | int solution() {
long long int Arraylength = 0;
long long int i = 0;
long long int num = 0;
long long int sum = 0;
long long int ara[100001] = {0};
scanf("%lld", &Arraylength);
for (i = 0; i < Arraylength; i++) {
scanf("%lld", &num);
ara[i] = num;
sum += num;
}
for (i = 0; i < Arraylength;... | fn solution() {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
buf.clear();
std::io::stdin().read_line(&mut buf).unwrap();
let mut sum: u64 = 0;
let mut max: u64 = 0;
let numbers = buf.split_whitespace().map(|x| x.parse::<u64>().unwrap());
for x in numbers {... | medium |
1742 | <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>N</var>.</p>
<p>Takahashi chooses an integer <var>a</var> from the positive integers not greater than <var>N</var> with equal probability.</p>
<p>Find the probability that <var>... | int solution(void) {
int N = 0;
scanf("%d", &N);
if (N % 2 == 0) {
printf("%f\n", 0.5);
} else {
double a = N;
printf("%f\n", (a + 1) / (2 * a));
}
return 0;
} | fn solution() {
let _stdin: String = {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
s.trim_end().to_owned()
};
let n: f32 = _stdin.parse().unwrap();
if n % 2. == 0.0 {
println!("{}", 1. - (n / 2. / n));
} else {
println!("{}", 1. - (... | medium |
1743 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has <var>N</var> dogs and <var>M</var> monkeys. He wants them to line up in a row.</p>
<p>As a Japanese saying goes, these dogs and monkeys are on bad terms. <em>("ken'en no naka", literally "the ... | int solution(void) {
int d;
int m;
unsigned long long int p = 1;
scanf("%d%d", &d, &m);
switch (d - m) {
case 0:
for (int i = 1; i <= d; i++) {
p = p * i;
p = p % 1000000007;
}
p = p * p;
p = p % 1000000007;
p = p * 2;
break;
case -1:
for (int i = 1; i <= d; i++) {
... | fn solution() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
let v: Vec<usize> = s.split_whitespace().map(|x| x.parse().unwrap()).collect();
let d: usize = std::cmp::max(v[0], v[1]) - std::cmp::min(v[0], v[1]);
if d > 1 {
println!("0");
return;
}
co... | medium |
1744 | Three friends are going to meet each other. Initially, the first friend stays at the position $$$x = a$$$, the second friend stays at the position $$$x = b$$$ and the third friend stays at the position $$$x = c$$$ on the coordinate axis $$$Ox$$$.In one minute each friend independently from other friends can change the ... | int solution() {
int n;
scanf("%d", &n);
for (int k = 0; k < n; k++) {
int a[3];
int x;
int s = 0;
scanf("%d%d%d", &a[0], &a[1], &a[2]);
for (int i = 0; i < 3 - 1; i++) {
for (int j = 0; j < 3 - i - 1; j++) {
if (a[j] > a[j + 1]) {
x = a[j];
a[j] = a[j + 1];
... | fn solution() {
let mut str = String::new();
let _b1 = stdin().read_line(&mut str).unwrap();
let N: i32 = str.trim().parse().unwrap();
for _test in 0..N {
let mut str = String::new();
let _b1 = stdin().read_line(&mut str).unwrap();
let mut iter = str.split_whitespace();
l... | hard |
1745 | A and B are preparing themselves for programming contests.B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.Initially, the compiler displayed n compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some ... | int solution() {
int n = 0;
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int i = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &d), a += d;
}
for (i = 0; i < n - 1; i++) {
scanf("%d", &d), b += d;
}
for (i = 0; i < n - 2; i++) {
scanf("%d", &d), c += d;
}
printf("%d\n%... | fn solution() {
let mut n = String::new();
io::stdin().read_line(&mut n).unwrap();
let _n: i64 = n.trim().parse().unwrap();
let mut line = String::new();
io::stdin().read_line(&mut line).unwrap();
let a: Vec<i64> = line
.split_whitespace()
.map(|x| x.parse().unwrap())
... | hard |
1746 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You have <var>N</var> apples, called Apple <var>1</var>, Apple <var>2</var>, Apple <var>3</var>, ..., Apple <var>N</var>. The <em>flavor</em> of Apple <var>i</var> is <var>L+i-1</var>, which can be nega... | int solution(void) {
int N = 0;
int L = 0;
int sweet = 0;
int pie = 0;
int i = 1;
int j = 1;
scanf("%d %d", &N, &L);
sweet = L * L;
for (i = 2; i <= N; i++) {
if (sweet > (L + i - 1) * (L + i - 1)) {
sweet = (L + i - 1) * (L + i - 1);
j = i;
}
}
for (i = 1; i <= N; i++) {
... | fn solution() {
let mut x = String::new();
stdin().read_line(&mut x).unwrap();
let x: Vec<isize> = x.split_whitespace().flat_map(str::parse).collect();
let (n, l) = (x[0], x[1]);
let mut tastes: Vec<(isize, isize)> = (1..n + 1)
.map(|i| l + i - 1)
.map(|i| (if i < 0 { -i } else { i ... | hard |
1747 | Vasya lives in a strange world. The year has n months and the i-th month has ai days. Vasya got a New Year present — the clock that shows not only the time, but also the date.The clock's face can display any number from 1 to d. It is guaranteed that ai ≤ d for all i from 1 to n. The clock does not keep information abou... | int solution() {
int d;
scanf("%d", &d);
int n;
scanf("%d", &n);
int a[n];
int i = 0;
for (; i < n; i++) {
scanf("%d", &a[i]);
}
int ans = 0;
for (i = 0; i < n - 1; i++) {
ans += d - a[i];
}
printf("%d", ans);
} | fn solution() {
let stdin = io::stdin();
let mut s = String::new();
stdin.read_line(&mut s).unwrap();
let d = s.trim().parse::<i32>().unwrap();
s = String::new();
stdin.read_line(&mut s).unwrap();
let _n = s.trim().parse::<i32>().unwrap();
s = String::new();
stdin.read_line(&mut s... | easy |
1748 | Monocarp and Polycarp are learning new programming techniques. Now they decided to try pair programming.It's known that they have worked together on the same file for $$$n + m$$$ minutes. Every minute exactly one of them made one change to the file. Before they started, there were already $$$k$$$ lines written in the f... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int k;
int n;
int m;
scanf("%d %d %d\n", &k, &n, &m);
int a[n];
int b[m];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i < m; i++) {
scanf("%d", &b[i]);
}
int x = 0;
int y = 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 s = lines.next().unwrap();
... | medium |
1749 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi is playing a board game called Sugoroku.</p>
<p>On the board, there are <var>N + 1</var> squares numbered <var>0</var> to <var>N</var>. Takahashi starts at Square <var>0</var>, and he has to s... | int solution() {
int i;
int N;
int M;
char S[100002];
scanf("%d %d", &N, &M);
scanf("%s", S);
int j;
int k;
int dice[100001];
for (i = N, k = 0; i > 0;) {
for (j = (i < M) ? i : M; j >= 1; j--) {
if (S[i - j] == '0') {
break;
}
}
if (j == 0) {
break;
}
... | 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 mut s: Vec<char> = itr.next().unwrap().chars().collec... | medium |
1750 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Determine if we can choose <var>K</var> different integers between <var>1</var> and <var>N</var> (inclusive) so that no two of them differ by <var>1</var>.</p>
</section>
</div>
<div class="part">
<sect... | int solution() {
int n;
int N = 0;
int K = 0;
scanf("%d%d", &N, &K);
if (N % 2 != 0) {
n = (N + 1) / 2;
} else {
n = N / 2;
}
if (n >= K) {
printf("YES\n");
} else {
printf("NO\n");
}
return 0;
} | fn solution() {
let mut s = String::new();
stdin().read_line(&mut s).ok();
let vs: Vec<u32> = s
.split_whitespace()
.map(|token| token.parse().ok().unwrap())
.collect();
let n = vs[0];
let k = vs[1];
if n.div_ceil(2) >= k {
println!("YES");
} else {
pr... | medium |
1751 | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be sh... | int solution() {
int t = 0;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
int n = 0;
scanf("%d", &n);
for (int j = 0; j < n; j++) {
printf("%d ", j + 2);
}
printf("\n");
}
return 0;
} | fn solution() {
let mut handle = std::io::BufWriter::new(std::io::stdout());
let mut test_no = String::new();
std::io::stdin().read_line(&mut test_no).unwrap();
let test_no: u8 = test_no.trim().parse::<u8>().unwrap();
for _ in 0..test_no {
let mut case = String::new();
std::io::stdin... | hard |
1752 | Your friend Jeff Zebos has been trying to run his new online company, but it's not going very well. He's not getting a lot of sales on his website which he decided to call Azamon. His big problem, you think, is that he's not ranking high enough on the search engines. If only he could rename his products to have better ... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
char s[5001];
scanf("%s", s);
char c[5001];
scanf("%s", c);
int n = strlen(s);
int m = strlen(c);
int flag = 1;
for (int i = 0; i < (n < m ? n : m) && flag; i++) {
int j;
if (s[i] < c[i]) {
flag = 0;
}... | fn solution() {
let stdin = io::stdin();
let mut scan = Scanner::new(stdin.lock());
let tt: usize = scan.token();
for _ in 0..tt {
let mut s: String = scan.token();
let c: String = scan.token();
let mut ss = s.clone().char_indices().collect::<Vec<_>>();
ss.sort_by(|a, b| ... | easy |
1753 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a rectangular grid of squares 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</... | int solution() {
int h;
int w;
int n;
int sr;
int sc;
scanf("%d%d%d%d%d", &h, &w, &n, &sr, &sc);
char s[n + 1];
char t[n + 1];
scanf("%s%s", s, t);
int i;
int c_l = sc;
int c_r = sc;
int r_u = sr;
int r_d = sr;
for (i = 0; i < n; i++) {
if (s[i] == 'L') {
c_l--;
if (c_l < 1... | fn solution() {
let mut s: String = String::new();
stdin().read_to_string(&mut s).ok();
let mut itr = s.split_whitespace();
let h: usize = itr.next().unwrap().parse().unwrap();
let w: usize = itr.next().unwrap().parse().unwrap();
let n: usize = itr.next().unwrap().parse().unwrap();
let sr: u... | easy |
1754 | <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>Connected Components</H1>
<... | int solution() {
int i;
int j;
int n;
int m;
int s;
int t;
int t1;
int t2;
fscanf(stdin, "%d %d", &n, &m);
int *gg[n];
int gid[m];
for (i = 0; i < n; i++) {
gg[i] = NULL;
}
for (i = 0; i < m; i++) {
gid[i] = i;
}
int maxgrp = 0;
for (i = 0; i < m; i++) {
fscanf(stdin, "%... | fn solution() {
let mut buf = String::new();
let _ = std::io::stdin().read_line(&mut buf).ok();
let mut buf = buf.split_whitespace();
let n: usize = buf.next().unwrap().parse().unwrap();
let m: usize = buf.next().unwrap().parse().unwrap();
let mut g = vec![vec![]; n];
for _ in 0..m {
... | hard |
1755 | <span class="lang-en">
<p>Score: <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>In this problem, a date is written as Y-M-D. For example, <var>2019</var>-<var>11</var>-<var>30</var> means November <var>30</var>, <var>2019</var>.</p>
<p>Integers <var>M_1, D_1, M_2</var>, and <var>D_... | int solution(void) {
int M1 = 0;
int M2 = 0;
int D1 = 0;
int D2 = 0;
scanf("%d %d", &M1, &D1);
scanf("%d %d", &M2, &D2);
if (M1 != M2 && D2 == 1) {
printf("1\n");
} else {
printf("0\n");
}
return 0;
} | fn solution() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).ok();
let a: Vec<u32> = s
.split_whitespace()
.map(|e| e.parse().ok().unwrap())
.collect();
let mut s = String::new();
std::io::stdin().read_line(&mut s).ok();
let b: Vec<u32> = s
.spli... | hard |
1756 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>A group of people played a game. All players had distinct scores, which are positive integers.</p>
<p>Takahashi knows <var>N</var> facts on the players' scores. The <var>i</var>-th fact is as follows: t... | int solution(void) {
long n;
scanf("%ld", &n);
long a[n];
long b[n];
for (long i = 0; i < n; i++) {
scanf("%ld %ld", &a[i], &b[i]);
}
long max = 0;
long n_th;
for (long i = 0; i < n; i++) {
if (a[i] > max) {
max = a[i];
n_th = i;
}
}
printf("%ld\n", max + b[n_th]);
retu... | fn solution() {
let stdin = io::stdin();
let (a, b): (u32, u32) = stdin
.lock()
.lines()
.skip(1)
.map(|r| {
r.as_ref()
.map(|l| {
let mut s = l.split_whitespace().map(|s| s.parse().unwrap());
(s.next().unwrap(),... | medium |
1757 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have an <var>N \times N</var> square grid.</p>
<p>We will paint each square in the grid either black or white.</p>
<p>If we paint exactly <var>A</var> squares white, how many squares will be painted ... | int solution() {
int N = 0;
int A = 0;
scanf("%d %d", &N, &A);
printf("%d", (N * N) - A);
return 0;
} | fn solution() {
let mut line = String::new();
io::stdin().read_line(&mut line).ok();
let vec: Vec<&str> = line.split_whitespace().collect();
let n: i32 = vec[0].parse().unwrap_or(0);
let mut l = String::new();
io::stdin().read_line(&mut l).ok();
let v: Vec<&str> = l.split_whitespace().colle... | hard |
1758 | You are given $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$. Find the maximum value of $$$max(a_l, a_{l + 1}, \ldots, a_r) \cdot min(a_l, a_{l + 1}, \ldots, a_r)$$$ over all pairs $$$(l, r)$$$ of integers for which $$$1 \le l < r \le n$$$. | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
long long int a[n];
for (int i = 0; i < n; i++) {
scanf("%lld", &a[i]);
}
long long int ans = 0;
ans = a[0] * a[1];
if (n > 2) {
for (int i = 1; i < n - 1; i++) {
if ((a[i] * a[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(2).step_by(2) {
let m = l
.unwrap()
.split(' ')
.map(|w| w.parse::<u64>().unwrap())
.fold((1, 1), |(p, m), n| (n, m.max(p * n)))
... | hard |
1759 | A permutation is a sequence of $$$n$$$ integers from $$$1$$$ to $$$n$$$, in which all numbers occur exactly once. For example, $$$[1]$$$, $$$[3, 5, 2, 1, 4]$$$, $$$[1, 3, 2]$$$ are permutations, and $$$[2, 3, 2]$$$, $$$[4, 3, 1]$$$, $$$[0]$$$ are not.Polycarp was presented with a permutation $$$p$$$ of numbers from $$$... | int solution() {
int t;
scanf("%d", &t);
int n;
for (int m = 0; m < t; m++) {
scanf("%d", &n);
int arr[n];
int max = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
if (arr[i] > max) {
max = arr[i];
}
}
int s1[max];
int s2[max];
int a[max];
i... | fn solution() {
let sin = std::io::stdin();
let mut s = String::new();
sin.read_line(&mut s).unwrap();
let mut t = s.trim().parse::<usize>().unwrap();
while t > 0 {
t -= 1;
let mut s = String::new();
sin.read_line(&mut s).unwrap();
let n = s.trim().parse::<usize>().u... | medium |
1760 | Let's define the value of the permutation $$$p$$$ of $$$n$$$ integers $$$1$$$, $$$2$$$, ..., $$$n$$$ (a permutation is an array where each element from $$$1$$$ to $$$n$$$ occurs exactly once) as follows: initially, an integer variable $$$x$$$ is equal to $$$0$$$; if $$$x < p_1$$$, then add $$$p_1$$$ to $$$x$$$ (se... | int solution() {
int a;
int n;
scanf("%d", &n);
while (n--) {
scanf("%d", &a);
int b[a];
for (int i = 0; i < a; i++) {
if (i < (a - 5) && i >= 0 && a > 4) {
printf("%d ", i + 4);
}
}
if (a > 4) {
printf("2 3 1 %d %d\n", a - 1, a);
} else {
printf("2 1 3 4\... | fn solution() {
let mut lines = io::stdin().lines();
let t: i32 = lines.next().unwrap().unwrap().trim().parse().unwrap();
for _ in 0..t {
let n: i32 = lines.next().unwrap().unwrap().trim().parse().unwrap();
if n % 2 == 0 {
for i in (3..n - 1).rev() {
print!("{i} ... | medium |
1761 | <span class="lang-en">
<p>Score: <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>In the Kingdom of AtCoder, only banknotes are used as currency. There are <var>10^{100}+1</var> kinds of banknotes, with the values of <var>1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}</var>. You have come... | int solution(void) {
char s[1000000 + 10];
scanf("%s", s);
int length = strlen(s);
int num;
long bill_a = 0;
long bill_b = 1;
long case1;
long case2;
long case3;
long case4;
for (int i = 0; i < length; i++) {
num = s[i] - '0';
case1 = bill_a + num;
case2 = bill_b + 10 - num;
case3... | fn solution() {
let mut s: String = String::new();
std::io::stdin().read_to_string(&mut s).ok();
let s: Vec<i64> = s
.trim()
.chars()
.map(|c| c.to_digit(10).unwrap() as i64)
.collect();
let mut dp: Vec<i64> = [0, 1].to_vec();
for &c in s.iter() {
let tmp1 = s... | medium |
1762 | <span class="lang-en">
<p>Score: <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Amidakuji is a traditional method of lottery in Japan.</p>
<p>To make an amidakuji, we first draw <var>W</var> parallel vertical lines, and then draw horizontal lines that connect them. The length of eac... | int solution() {
long long int h;
long long int w;
long long int k;
long long int memo;
long long int result;
long long int two[10] = {1, 2, 3, 5, 8, 13, 21, 34, 55, 256, 512};
scanf("%lld%lld%lld", &h, &w, &k);
long long int s[105][10] = {};
s[h + 1][k] = 1;
for (int i = h; i >= 1; i--) {
for (... | fn solution() {
input! {
h: usize,
w: usize,
k: usize
}
let d = 1000000007;
let fib = vec![0, 1, 1, 2, 3, 5, 8, 13, 21, 34];
let mut v: Vec<Vec<usize>> = vec![vec![0; w + 2]; h + 1];
v[0][1] = 1;
for i in 0..h {
for j in 1..w + 1 {
v[i + 1][j] = (v... | easy |
1763 | You are given two integers $$$n$$$ and $$$k$$$. You are asked to choose maximum number of distinct integers from $$$1$$$ to $$$n$$$ so that there is no subset of chosen numbers with sum equal to $$$k$$$.A subset of a set is a set that can be obtained from initial one by removing some (possibly all or none) elements of ... | int solution() {
int n;
int k;
int t;
int count = 0;
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &k);
int a[1200] = {0};
count = n - 1;
a[k] = 1;
for (int i = 1; i < k; i++) {
if (a[k - i] == 0 && k - i != i) {
a[i] = 1;
count--;
}
}
printf("%d\n"... | fn solution() {
let mut input = String::new();
stdin().read_to_string(&mut input).unwrap();
let mut it = input
.split_whitespace()
.map(|x| x.parse::<usize>().unwrap());
let _t = it.next().unwrap();
while let Some(n) = it.next() {
let k = it.next().unwrap();
let p... | medium |
1764 | Let's denote correct match equation (we will denote it as CME) an equation $$$a + b = c$$$ there all integers $$$a$$$, $$$b$$$ and $$$c$$$ are greater than zero.For example, equations $$$2 + 2 = 4$$$ (||+||=||||) and $$$1 + 2 = 3$$$ (|+||=|||) are CME but equations $$$1 + 2 = 4$$$ (|+||=||||), $$$2 + 2 = 3$$$ (||+||=||... | int solution() {
int q;
scanf("%d", &q);
int n[q];
for (int i = 0; i < q; i++) {
scanf("%d", &n[i]);
}
for (int i = 0; i < q; i++) {
if (n[i] == 2) {
printf("2\n");
}
if (n[i] % 2 == 0 && n[i] != 2) {
printf("0\n");
}
if (n[i] % 2 == 1) {
printf("1\n");
}
}
} | fn solution() {
let mut buffer = String::new();
io::stdin()
.read_line(&mut buffer)
.expect("failed to read input");
let q: u8 = buffer.trim().parse().expect("invalid input");
for _ in 0..q {
let mut input = String::new();
io::stdin()
.read_line(&mut input)
... | medium |
1765 | Real stupidity beats artificial intelligence every time.— Terry Pratchett, Hogfather, DiscworldYou are given a string $$$s$$$ of length $$$n$$$ and a number $$$k$$$. Let's denote by $$$rev(s)$$$ the reversed string $$$s$$$ (i.e. $$$rev(s) = s_n s_{n-1} ... s_1$$$). You can apply one of the two kinds of operations to th... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
int k;
char s[100];
scanf("%d%d %s", &n, &k, s);
int equal = 1;
for (int i = 0; i < n; i++) {
if (s[i] != s[n - 1 - i]) {
equal = 0;
}
}
if (k == 0) {
printf("1\n");
continue;
}
if... | fn solution() {
let mut n_cases = String::new();
io::stdin()
.read_line(&mut n_cases)
.expect("Failed to read input");
let mut n_cases: i8 = n_cases.trim().parse().expect("Invalid input");
loop {
if n_cases == 0 {
break;
} else {
n_cases -= 1
... | hard |
1766 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>A <var>3×3</var> grid with a integer written in each square, is called a magic square if and only if the integers in each row, the integers in each column, and the integers in each diagonal (from the to... | int solution(void) {
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
int f = 0;
int g = 0;
int h = 0;
int M = 0;
scanf("%d %d %d", &a, &b, &M);
g = 2 * M - b;
h = 2 * M - a;
f = 3 * M - g - h;
c = 2 * M - f;
e = 3 * M - c - h;
d = 2 * M - e;
printf("%d %d %d\n", a, b, c);
p... | 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 a: i32 = s.next().unwrap().parse().unwrap();
let b: i32 = s.next().unwrap().parse().unwrap();
let c: i32 = s.next().unwrap().parse().unwrap();... | easy |
1767 | You have a statistic of price changes for one product represented as an array of $$$n$$$ positive integers $$$p_0, p_1, \dots, p_{n - 1}$$$, where $$$p_0$$$ is the initial price of the product and $$$p_i$$$ is how the price was increased during the $$$i$$$-th month.Using these price changes you are asked to calculate t... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
int k;
scanf("%d %d", &n, &k);
long long int p[n + 1];
long long int arr[n + 1];
long long int max = 0;
arr[0] = 0;
for (int i = 0; i < n; i++) {
scanf("%lli", &p[i]);
if (i == 0) {
arr[i] = p[i];
... | fn solution() {
use std::io::{self, Write};
let (stdin, stdout) = (io::stdin(), io::stdout());
let mut sc = cf_scanner::Scanner::new(stdin.lock());
let mut out = io::BufWriter::new(stdout.lock());
let tc: usize = sc.next();
for _ in 0..tc {
let (n, k): (usize, i64) = (sc.next(), sc.nex... | medium |
1768 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilatera... | int solution(void) {
long long N;
long long X;
scanf("%lld%lld", &N, &X);
if (X > N / 2) {
X = N - X;
}
long long sum = 0;
long long k;
sum += X + N - X;
N = N - X;
while (X != 0) {
sum += 2 * X * (N / X);
k = N % X;
N = X;
X = k;
}
sum -= N;
printf("%lld", sum);
} | fn solution() {
let stdin = std::io::stdin();
let line = stdin.lock().lines().next().unwrap().unwrap();
let mut split = line.split(' ').map(|x| x.parse::<u64>().unwrap());
let (n, mut x) = (split.next().unwrap(), split.next().unwrap());
if x * 2 == n {
println!("{}", x * 3);
std::pr... | easy |
1769 | The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinates (xi, yi), a maximum brightness c, equal for all stars, and an initial brightness si (0 ≤ si ≤ c).Over time the stars twinkle. At moment 0 the i-th star has brightness si. Let at moment t some star has brightness x. Th... | int solution() {
int i;
int j;
int c;
int n;
int q;
int x;
int y;
int s;
int t;
int x1;
int x2;
int y1;
int y2;
int ans;
int z;
scanf("%d%d%d", &n, &q, &c);
int arr[101][101][11] = {0};
for (i = 0; i < n; i++) {
scanf("%d%d%d", &x, &y, &s);
arr[x][y][s]++;
}
for (i = 1; i... | fn solution() {
use std::io::stdin;
let (n, q, c) = {
let mut input = String::new();
stdin().read_line(&mut input).unwrap();
let mut input = input
.split_whitespace()
.map(|k| k.parse::<usize>().unwrap());
(
input.next().unwrap(),
... | easy |
1770 | Ashish has $$$n$$$ elements arranged in a line. These elements are represented by two integers $$$a_i$$$ — the value of the element and $$$b_i$$$ — the type of the element (there are only two possible types: $$$0$$$ and $$$1$$$). He wants to sort the elements in non-decreasing values of $$$a_i$$$.He can perform the fol... | int solution() {
int t;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
int m;
int oc = 0;
int zc = 0;
scanf("%d", &m);
int arr[m];
int arr1[m];
for (int j = 0; j < m; j++) {
scanf("%d", &arr[j]);
}
for (int j = 0; j < m; j++) {
scanf("%d", &arr1[j]);
if (arr1[... | 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 xs: Vec<usize> = lines
.next()
.unwra... | medium |
1771 | Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co... | int solution(void) {
int n;
char s[101];
scanf("%s", s);
scanf("%d", &n);
char page[n][101];
int ans = -1;
int mini = 0;
int len = strlen(s);
for (int i = 0; i < n; i++) {
scanf("%s", page[i]);
if (strncmp(s, page[i], len) == 0 && strcmp(page[i], page[mini]) <= 0) {
mini = i;
ans... | fn solution() {
let mut word = String::new();
io::stdin().read_line(&mut word).unwrap();
word = word.trim().to_string();
let mut count = String::new();
io::stdin().read_line(&mut count).unwrap();
let count: u32 = match count.trim().parse() {
Ok(num) => num,
Err(_) => return,
... | hard |
1772 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an integer <var>K</var>.
Print the string obtained by repeating the string <code>ACL</code> <var>K</var> times and concatenating them.</p>
<p>For example, if <var>K = 3</var>, print <code>... | int solution() {
int K = 0;
scanf("%d", &K);
for (int i = 0; i < K * 3; i++) {
switch (i % 3) {
case 0:
printf("A");
break;
case 1:
printf("C");
break;
case 2:
printf("L");
break;
default:
break;
}
}
printf("\n");
return 0;
} | fn solution() -> io::Result<()> {
let mut buf = String::new();
let stdin = io::stdin();
stdin.read_line(&mut buf)?;
buf.retain(|c| c != '\n');
let times: usize = buf.parse().unwrap();
for _ in 0..times {
print!("ACL");
}
println!();
Ok(())
} | hard |
1773 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an <var>H × W</var> grid.<br/>
The squares in the grid are described by <var>H</var> strings, <var>S_1,...,S_H</var>.<br/>
The <var>j</var>-th character in the string <var>S_i</var> corres... | int solution(void) {
int H = 0;
int W = 0;
char board[51][51];
int count = 0;
scanf("%d %d", &H, &W);
for (int i = 0; i < H; i++) {
scanf("%s", board[i]);
}
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (board[i][j] == '.') {
if (i > 0) {
if (board[i - 1]... | fn solution() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).ok();
let v: Vec<usize> = s
.split_whitespace()
.map(|e| e.parse().ok().unwrap())
.collect();
let mut mat: Vec<String> = Vec::new();
let mut ans: Vec<Vec<i32>> = Vec::new();
let mut ans2: Vec<St... | easy |
1774 | You are given two even integers $$$n$$$ and $$$m$$$. Your task is to find any binary matrix $$$a$$$ with $$$n$$$ rows and $$$m$$$ columns where every cell $$$(i,j)$$$ has exactly two neighbours with a different value than $$$a_{i,j}$$$.Two cells in the matrix are considered neighbours if and only if they share a side. ... | int solution() {
int t;
scanf("%d", &t);
for (int o = 0; o < t; o++) {
int n;
int m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int i1 = i / 2;
int j1 = j / 2;
int x = (i1 + j1) & 1;
int y = ((i & 1) + (j & 1));
... | fn solution() {
let mut test_cases_remaining = String::new();
io::stdin()
.read_line(&mut test_cases_remaining)
.expect("bla");
let mut test_cases_remaining: u32 = test_cases_remaining.trim().parse().expect("bla");
loop {
if test_cases_remaining == 0 {
break;
... | medium |
1775 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem</h3><p>Takahashi, who is a novice in competitive programming, wants to learn <var>M</var> algorithms.
Initially, his <em>understanding level</em> of each of the <var>M</var> algorithms is <var>0</var>.</p>
<p>Takahashi ... | int solution(void) {
int N;
int M;
int X;
int ans = 1e9;
scanf("%d %d %d", &N, &M, &X);
int C[N];
int A[N][M];
for (int i = 0; i < N; i++) {
scanf("%d", &C[i]);
for (int j = 0; j < M; j++) {
scanf("%d", &A[i][j]);
}
}
for (int bit = 0; bit < (1 << N); bit++) {
int money = 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 x: usize = itr.next().unwrap().parse().unwrap();
... | easy |
1776 | You've got a string $$$a_1, a_2, \dots, a_n$$$, consisting of zeros and ones.Let's call a sequence of consecutive elements $$$a_i, a_{i + 1}, \ldots, a_j$$$ ($$$1\leq i\leq j\leq n$$$) a substring of string $$$a$$$. You can apply the following operations any number of times: Choose some substring of string $$$a$$$ (fo... | int solution() {
long long int n;
long long int x;
long long int y;
long long int i;
long long int j;
long long int k = 0;
scanf("%lld%lld%lld", &n, &x, &y);
char a[300005];
long long int b[300005];
scanf("%s", a);
for (i = 0; i < n - 1; i++) {
if (a[i] == a[i + 1]) {
continue;
}
... | fn solution() {
let mut buffer = String::new();
let stdin = io::stdin();
let mut handle = stdin.lock();
handle.read_to_string(&mut buffer).unwrap();
let input_strs = buffer
.split_whitespace()
.take(3)
.map(|x| x.parse::<i64>().unwrap())
.collect::<Vec<i64>>();
... | medium |
1777 | Lord Omkar has permitted you to enter the Holy Church of Omkar! To test your worthiness, Omkar gives you a password which you must interpret!A password is an array $$$a$$$ of $$$n$$$ positive integers. You apply the following operation to the array: pick any two adjacent numbers that are not equal to each other and rep... | int solution() {
int n = 0;
scanf("%d", &n);
int i = 0;
for (; i < n; i++) {
int res = 1;
int j = 0;
int t = 0;
int v[200000] = {0};
scanf("%d", &t);
for (; j < t; j++) {
scanf("%d", &v[j]);
}
for (j = 0; j < t; j++) {
if (j == t - 1) {
res = t;
} else 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()... | medium |
1778 | Vasya has got $$$n$$$ books, numbered from $$$1$$$ to $$$n$$$, arranged in a stack. The topmost book has number $$$a_1$$$, the next one — $$$a_2$$$, and so on. The book at the bottom of the stack has number $$$a_n$$$. All numbers are distinct.Vasya wants to move all the books to his backpack in $$$n$$$ steps. During $$... | int solution() {
int books[200001];
int n = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int book = 0;
scanf("%d", &book);
books[book] = i;
}
int lastInsert = 0;
for (int j = 1; j <= n; j++) {
int order = 0;
scanf("%d", &order);
order = books[order];
if ((order - lastInse... | fn solution() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).expect("read_line error");
let _n = match s.split_whitespace().next() {
Some(s) => match s.parse::<i32>() {
Ok(n) => n,
_ => 0,
},
_ => 0,
};
s.clear();
std::io::stdin().... | hard |
1779 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We will play a one-player game using a number line and <var>N</var> pieces.</p>
<p>First, we place each of these pieces at some integer coordinate.</p>
<p>Here, multiple pieces can be placed at the same... | int solution() {
int N;
int M;
int ary[100000] = {0};
int bucket_1[200001] = {0};
int margin[99999] = {0};
int bucket_2[200000] = {0};
int i;
int j;
int k;
int notpass = 0;
scanf("%d %d", &N, &M);
for (i = 0; i < M; i++) {
scanf("%d", &ary[i]);
}
if (M <= N) {
printf("%d\n", 0);
... | fn solution() {
let mut stdin = io::stdin();
let mut buf = String::new();
let _ = stdin.read_to_string(&mut buf);
let mut iter = buf.split_whitespace();
let n: usize = iter.next().unwrap().parse().unwrap();
let m: usize = iter.next().unwrap().parse().unwrap();
let mut x: Vec<i32> = (0..m)
... | medium |
1780 | You and your friend are participating in a TV show "Run For Your Prize".At the start of the show n prizes are located on a straight line. i-th prize is located at position ai. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these two position... | int solution() {
int n;
scanf("%d", &n);
int a[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
int t1 = 0;
int t2 = 0;
if (a[n - 1] <= 500000) {
printf("%d", a[n - 1] - 1);
}
if (a[0] > 500000) {
printf("%d", 1000000 - a[0]);
}
else {
for (int i = 0; i < n; i++) {
... | fn solution() {
let mut buf = String::new();
stdin().read_line(&mut buf).unwrap();
let _n: i64 = buf.split_whitespace().next().unwrap().parse().unwrap();
buf.clear();
stdin().read_line(&mut buf).unwrap();
let a: Vec<i64> = buf
.split_whitespace()
.map(|s| s.parse::<i64>().unwrap(... | medium |
1781 | You are given two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 100$$$). Represent the number $$$n$$$ as the sum of $$$k$$$ positive integers of the same parity (have the same remainder when divided by $$$2$$$).In other words, find $$$a_1, a_2, \ldots, a_k$$$ such that all $$$a_i>0$$... | int solution() {
int t = 0;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
int n = 0;
int k = 0;
scanf("%d%d", &n, &k);
if ((k <= n) && (n - k + 1) % 2 != 0) {
printf("YES\n");
for (int j = 0; j < (k - 1); j++) {
printf("1 ");
}
printf("%d\n", n - k + 1);
} els... | fn solution() {
let stdin = io::stdin();
let mut lines = stdin.lock().lines();
let t: usize = lines.next().unwrap().unwrap().parse().unwrap();
for _ in 0..t {
let xs: Vec<usize> = lines
.next()
.unwrap()
.unwrap()
.split(' ')
.map(|x| x... | easy |
1782 | <H1>Reversing Numbers</H1><br>
<p>
Write a program which reads a sequence and prints it in the reverse order.
</p>
<H2>Input</H2>
<p>
The input is given in the following format:
</p>
<pre>
<var>n</var>
<var>a</var><sub>1</sub> <var>a</var><sub>2</sub> . . . <var>a</var><sub><var>n</var></sub>
</pre>
<p>
<var>n</... | int solution(void) {
int n = 100;
scanf("%d", &n);
int a[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i < n; i++) {
printf("%d ", a[n - i]);
}
printf("%d\n", a[0]);
} | fn solution() {
let stdin = io::stdin();
let mut buf = String::new();
let _ = stdin.read_line(&mut buf);
buf.clear();
let _ = stdin.read_line(&mut buf);
let mut vec: Vec<&str> = buf.split_whitespace().collect();
vec.reverse();
println!("{}", vec.join(" "));
} | hard |
1783 | Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 × n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed h... | int solution() {
int count = 2;
int max = 0;
int n;
int flat = 1;
char goingUp = '1';
scanf("%d", &n);
getchar();
if (n == 1) {
printf("%d", 1);
} else if (n == 2) {
printf("%d", 2);
} else {
int t1;
int t2;
scanf("%d", &t1);
scanf("%d", &t2);
if (t2 < t1) {
goingUp... | fn solution() {
let mut buf = String::new();
io::stdin().read_line(&mut buf);
buf.clear();
io::stdin().read_line(&mut buf);
let s: Vec<u32> = buf
.split_whitespace()
.map(|x| x.parse::<u32>().unwrap())
.collect();
let mut mx = 1;
for i in 0..s.len() {
let mut ... | hard |
1784 | Polycarp wants to buy exactly $$$n$$$ shovels. The shop sells packages with shovels. The store has $$$k$$$ types of packages: the package of the $$$i$$$-th type consists of exactly $$$i$$$ shovels ($$$1 \le i \le k$$$). The store has an infinite number of packages of each type.Polycarp wants to choose one type of packa... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
int k;
int m = 1;
scanf("%d %d", &n, &k);
if (n <= k) {
printf("1\n");
} else {
for (int i = 1; i <= sqrt(n); i++) {
if (n % i == 0) {
if ((n / i) > m && (n / i) <= k) {
m = n / i;
... | fn solution() {
let mut s: String = String::new();
std::io::stdin().read_to_string(&mut s).ok();
let mut itr = s.split_whitespace();
let t: usize = itr.next().unwrap().parse().unwrap();
let mut out = Vec::new();
for _ in 0..t {
let n: u64 = itr.next().unwrap().parse().unwrap();
l... | medium |
1785 | We say that a positive integer $$$n$$$ is $$$k$$$-good for some positive integer $$$k$$$ if $$$n$$$ can be expressed as a sum of $$$k$$$ positive integers which give $$$k$$$ distinct remainders when divided by $$$k$$$.Given a positive integer $$$n$$$, find some $$$k \geq 2$$$ so that $$$n$$$ is $$$k$$$-good or tell tha... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
long long n;
int flag = 0;
scanf("%lld", &n);
long long p = n;
while (p % 2 == 0) {
p = p / 2;
}
if (p == 1) {
printf("-1\n");
} else if (p <= 2e9 && (p * (p + 1)) / 2 <= n) {
printf("%lld\n", p);
} els... | fn solution() {
let std_in = stdin();
let mut input = Scanner::new(std_in.lock());
let std_out = stdout();
let mut output = BufWriter::new(std_out.lock());
let tests = input.token();
for _ in 0..tests {
let n: i64 = input.token();
let mut k = -1i128;
for i in 0..62 {
... | medium |
1786 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given strings <var>s</var> and <var>t</var>.
Find one longest string that is a subsequence of both <var>s</var> and <var>t</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3... | int solution() {
char a[3001];
char b[3001];
scanf("%s", a);
scanf("%s", b);
int s1 = strlen(a);
int s2 = strlen(b);
int i;
int j;
int dp[s1 + 1][s2 + 1];
int count;
for (i = 0; i <= s1; i++) {
for (j = 0; j <= s2; j++) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
} else if (a[i... | fn solution() {
let mut s = String::new();
use std::io::Read;
std::io::stdin().read_to_string(&mut s).unwrap();
let mut it = s.split_whitespace();
let s: Vec<_> = it.next().unwrap().chars().collect();
let t: Vec<_> = it.next().unwrap().chars().collect();
let mut dp = vec![vec![0u16; t.len() ... | medium |
1787 | Suppose you have an integer $$$v$$$. In one operation, you can: either set $$$v = (v + 1) \bmod 32768$$$ or set $$$v = (2 \cdot v) \bmod 32768$$$. You are given $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. What is the minimum number of operations you need to make each $$$a_i$$$ equal to $$$0$$$? | int solution() {
int broj = 32768;
int n;
scanf("%d", &n);
int a[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
int potezi = 30;
for (int k = 0; k < 15; k++) {
for (int l = 0; l < 15; l++) {
int stepen = pow(2.0, l);
if ((((a[i] + k) * stepen) % 32768) == 0) {
... | fn solution() {
let mut dp = vec![-1; 32768];
dp[0] = 0;
let mut q = VecDeque::with_capacity(32768);
q.push_back(0);
while !q.is_empty() {
for _ in 0..q.len() {
let x = q.pop_front().unwrap();
let y = (x + 32768 - 1) % 32768;
if dp[y] == -1 {
... | medium |
1788 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke, a water strider, lives in a rectangular pond that can be seen as a grid with <var>H</var> east-west rows and <var>W</var> north-south columns. Let <var>(i,j)</var> be the square at the <var>i</va... | int solution() {
int i;
int j;
int H;
int W;
int K;
int x[2];
int y[2];
char **c;
scanf("%d %d %d", &H, &W, &K);
scanf("%d %d %d %d", &(x[0]), &(y[0]), &(x[1]), &(y[1]));
c = (char **)malloc(sizeof(char *) * (H + 2));
for (i = 1; i <= H; i++) {
c[i] = (char *)malloc(sizeof(char) * (W + 2));
... | 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 h: usize = s.next().unwrap().parse().unwrap();
let w: usize = s.next().unwrap().parse().unwrap();
let k: i32 = s.next().unwrap().parse().unwra... | medium |
1789 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>It's now the season of TAKOYAKI FESTIVAL!</p>
<p>This year, <var>N</var> takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The <em>deliciousness</em> of the <var>i</var>-th ta... | int solution(void) {
int takoyakis = 0;
int delicious_points_list[50];
int sum_heal_points = 0;
scanf("%d", &takoyakis);
for (int i = 0; i < takoyakis; i++) {
scanf("%d", &delicious_points_list[i]);
}
for (int i = 0; i < takoyakis * takoyakis; i++) {
int base = i / takoyakis;
int material =... | fn solution() {
let mut buf = String::new();
io::stdin().read_line(&mut buf).expect("");
let mut buf = String::new();
io::stdin().read_line(&mut buf).expect("");
let iter = buf.split_whitespace();
let buf: Vec<&str> = iter.collect();
let mut d = Vec::new();
for n in buf {
d.push... | hard |
1790 | <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> consisting of lowercase English letters.</p>
<p>If the length of <var>S</var> is at most <var>K</var>, print <var>S</var> without change.</p>
<p>If the length of <var>S</va... | int solution(void) {
int a = 0;
scanf("%d", &a);
char s[999] = "";
scanf("%s", s);
int y = strlen(s);
if (y <= a) {
printf("%s", s);
} else {
char t[999] = " ";
strncpy(t, s, a);
printf("%s", t);
printf("...");
}
return 0;
} | fn solution() {
let mut s = String::new();
stdin().read_line(&mut s).ok();
let k: usize = s.trim().parse().unwrap();
s.clear();
stdin().read_line(&mut s).ok();
s.pop();
println!(
"{}",
if s.len() <= k {
s
} else {
format!("{}...", &s[..k])
... | medium |
1791 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is a sequence of integers <var>A_1, A_2, ..., A_N</var>.
If its elements are pairwise distinct, print <code>YES</code>; otherwise, print <code>NO</code>.</p>
</section>
</div>
<div class="part">
<... | int solution(void) {
static char A[1000000010];
int N;
int num;
int ans;
scanf("%d", &N);
for (int i = 0; i < 1000000010; i++) {
A[i] = 0;
}
for (int i = 0; i < N; i++) {
scanf("%d", &num);
A[num]++;
if (A[num] > 1) {
printf("NO");
return 0;
}
}
printf("YES");
... | fn solution() {
let n: usize = {
let mut n = String::new();
std::io::stdin().read_line(&mut n).ok();
n.trim().parse().unwrap()
};
let mut line = String::new();
std::io::stdin().read_line(&mut line).ok();
let line: HashSet<&str> = line.split_whitespace().collect();
printl... | medium |
1792 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is having a barbeque party.</p>
<p>At the party, he will make <var>N</var> servings of <em>Skewer Meal</em>.</p>
<div style="text-align: center;">
<img src="https://agc001.contest.atcoder.jp/img/a... | int solution() {
int N = 0;
int sum = 0;
int i = 0;
int L[200];
scanf("%d", &N);
for (int x = 0; x < 2 * N; x++) {
scanf("%d", &L[x]);
++i;
}
for (int y = 0; y < i + 1; y++) {
for (int z = 0; z < i - 1; z++) {
if (L[z] < L[z + 1]) {
sum = L[z];
L[z] = L[z + 1];
... | fn solution() {
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).unwrap();
let mut buf_it = buf.split_whitespace();
let N = buf_it.next().unwrap().parse::<usize>().unwrap();
let mut A = (0..2 * N)
.map(|_| buf_it.next().unwrap().parse::<isize>().unwrap())
.coll... | hard |
1793 | You are given a positive integer $$$n$$$. You have to find $$$4$$$ positive integers $$$a, b, c, d$$$ such that $$$a + b + c + d = n$$$, and $$$\gcd(a, b) = \operatorname{lcm}(c, d)$$$.If there are several possible answers you can output any of them. It is possible to show that the answer always exists.In this problem... | int solution() {
int m = 0;
scanf("%d", &m);
while (m--) {
int n = 0;
scanf("%d", &n);
printf("%d %d %d %d\n", 1, n - 3, 1, 1);
}
return 0;
} | fn solution() {
let stdin = io::stdin();
let lines = stdin.lock().lines().skip(1);
let mut oup = io::BufWriter::new(io::stdout());
for line in lines {
let n = line.unwrap().parse::<u32>().unwrap();
writeln!(oup, "{} 1 1 1", n - 3).unwrap();
}
oup.flush().ok();
} | easy |
1794 | President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all ... | int solution() {
int c;
int r;
int s = 0;
char car;
scanf("%i %i %c\n", &c, &r, &car);
char a[c][r];
for (int i = 0; i < c; i++) {
for (int j = 0; j < r; j++) {
scanf("%c", &a[i][j]);
}
if (i != c - 1) {
scanf("\n");
}
}
for (int i = 0; i < c; i++) {
for (int j = 0; j <... | fn solution() {
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).unwrap();
let mut lines = buf.lines();
let (h, w, c) = {
let mut tokens = lines.next().unwrap().split_whitespace();
let h: i32 = tokens.next().unwrap().parse().unwrap();
let w: i32 = tokens.nex... | medium |
1795 | All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi — a coordinate on the Ox axis. No two cities are located at a single point.Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (becau... | int solution() {
int number = 0;
int p = 0;
scanf("%d", &number);
int location[number];
for (int i = 0; i < number; i++) {
scanf("%d", &location[i]);
}
int max = location[number - 1] - location[0];
int min = location[1] - location[0];
printf("%d %d\n", min, max);
int max1 = 0;
int max2 = 0;
... | fn solution() {
use std::io;
let mut buf = String::new();
io::stdin().read_line(&mut buf).unwrap();
buf.clear();
io::stdin().read_line(&mut buf).unwrap();
let cities: Vec<i64> = buf
.split_whitespace()
.map(|str| str.trim().parse().unwrap())
.collect();
for (i, &city)... | easy |
1796 | A batch of $$$n$$$ goods ($$$n$$$ — an even number) is brought to the store, $$$i$$$-th of which has weight $$$a_i$$$. Before selling the goods, they must be packed into packages. After packing, the following will be done: There will be $$$\frac{n}{2}$$$ packages, each package contains exactly two goods; The weight ... | int solution() {
int t;
scanf("%d", &t);
for (int T = 0; T < t; T++) {
int n;
int k;
int x;
scanf("%d%d", &n, &k);
int *r = calloc(k, sizeof(int));
long long tot = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &x);
tot += (x / k);
r[x % k]++;
}
x = k >> 1;
... | fn solution() {
let (stdin, stdout) = (io::stdin(), io::stdout());
let mut scan = Scanner::new(stdin.lock());
let mut out = io::BufWriter::new(stdout.lock());
let t = scan.token::<usize>();
for _ in 0..t {
let n = scan.token::<usize>();
let k = scan.token::<usize>();
let mu... | medium |
1797 | Nick had received an awesome array of integers $$$a=[a_1, a_2, \dots, a_n]$$$ as a gift for his $$$5$$$ birthday from his mother. He was already going to explore its various properties but after unpacking he was disappointed a lot because the product $$$a_1 \cdot a_2 \cdot \dots a_n$$$ of its elements seemed to him not... | int solution() {
int n;
scanf("%d", &n);
int a[n];
int b[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i < n; i++) {
if (a[i] >= 0) {
b[i] = -1 * (a[i] + 1);
} else {
b[i] = a[i];
}
}
if (n % 2 == 0) {
for (int i = 0; i < n; i++) {
printf... | fn solution() {
let stdin = io::stdin();
let mut it = stdin.lock().lines();
let _input = it.next().unwrap().unwrap();
let input = it.next().unwrap().unwrap();
let a: Vec<i32> = input
.split_whitespace()
.map(|s| s.parse().unwrap())
.collect();
let b: Vec<i32> = a
... | hard |
1798 | <h1>鉛筆 (Pencils)</h1>
<h2>問題文</h2>
<p>
JOI 君は鉛筆を <var>N</var> 本買うために近くの文房具店に行くことにした.
</p>
<p>
文房具店では鉛筆が一定の本数ずつのセットで売られている.セット <var>X</var> は <var>A</var> 本で <var>B</var> 円,セット <var>Y</var> は <var>C</var> 本で <var>D</var> 円である.
</p>
<p>
JOI 君はセット <var>X</var> かセット <var>Y</var> の一方を選び,選んだセットをいくつか購入する.両方のセットを購入することはできな... | int solution() {
int n[5];
int i;
int m = 1;
for (i = 0; i < 5; i++) {
scanf("%d", &n[i]);
}
i = 1;
while (n[0] > n[1] * m) {
++m;
}
while (n[0] > n[3] * i) {
++i;
}
n[2] *= m, n[4] *= i;
if (n[2] > n[4]) {
n[2] = n[4];
}
printf("%d\n", n[2]);
return 0;
} | fn solution() {
let mut buf = String::new();
let handle = std::io::stdin();
handle.read_line(&mut buf).unwrap();
let data: Vec<usize> = buf.split_whitespace().map(|a| a.parse().unwrap()).collect();
let (n, a, b, c, d) = (data[0], data[1], data[2], data[3], data[4]);
let mut total = 0;
let ... | medium |
1799 | There are two infinite sources of water: hot water of temperature $$$h$$$; cold water of temperature $$$c$$$ ($$$c < h$$$). You perform the following procedure of alternating moves: take one cup of the hot water and pour it into an infinitely deep barrel; take one cup of the cold water and pour it into an infini... | int solution() {
int T;
scanf("%d", &T);
long long int h;
long long int c;
long long int t;
long long int min;
long long int mid;
long long int max;
for (; T > 0; T--) {
scanf("%lld %lld %lld", &h, &c, &t);
if (h <= t) {
printf("1\n");
continue;
}
if (h + c >= 2 * t) {
... | 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 h: i64 = itr.next().unwrap().parse().unwrap();
l... | easy |
1800 | One very important person has a piece of paper in the form of a rectangle a × b.Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).A very important p... | int solution() {
long long int n;
long long int a;
long long int b;
long long int c[101][2];
long long int i;
long long int d[101];
long long int e[101][2];
long long int x = 0;
long long int s = 0;
long long int t;
long long int j;
long long int q;
scanf("%lld %lld %lld", &n, &a, &b);
if (a... | fn solution() {
let (n, a, b) = {
let mut input = String::new();
stdin().read_line(&mut input).unwrap();
let mut it = input
.split_whitespace()
.map(|k| k.parse::<usize>().unwrap());
(it.next().unwrap(), it.next().unwrap(), it.next().unwrap())
};
let ... | medium |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.