Thanks for participating. We hope you enjoyed the contest!
Idea: flamestorm
Tutorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
cout << (n / 10) + (n % 10) << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt; cin >> tt; for (int i = 1; i <= tt; i++) {solve();}
// solve();
}
Idea: SlavicG
Tutorial
Tutorial is loading...
Solution
def f(a, b):
if (a > b): return 1
if (a == b): return 0
if (a < b): return -1
for _ in range(int(input())):
a, b, c, d = map(int, input().split())
ans = 0
if f(a, c) + f(b, d) > 0:
ans += 1
if f(a, d) + f(b, c) > 0:
ans += 1
if f(b, c) + f(a, d) > 0:
ans += 1
if f(b, d) + f(a, c) > 0:
ans += 1
print(ans)
Idea: SlavicG
Tutorial
Tutorial is loading...
Solution
def solve():
n, s, m = map(int, input().split())
segs = [[0, 0], [m, m]] + [list(map(int, input().split())) for i in range(n)]
segs.sort()
for i in range(1, n + 2):
if segs[i][0] - segs[i - 1][1] >= s:
print('YES')
return
print('NO')
#sys.stdin = open('in', 'r')
for _ in range(int(input())):
solve()
Idea: SlavicG
Tutorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
int main() {
int test_cases; cin >> test_cases;
while(test_cases--) {
string s, t; cin >> s >> t;
int idx = 0;
for(int i = 0; i < (int)s.size(); ++i) {
if(s[i] == '?') {
if(idx < (int)t.size()) s[i] = t[idx++];
else s[i] = 'a';
} else if(s[i] == t[idx]) ++idx;
}
if(idx >= t.size()) cout << "YES\n" << s << "\n";
else cout << "NO\n";
}
}
Idea: flamestorm
Tutorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200'007;
const int MOD = 1'000'000'007;
int a[MAX], psum[MAX];
int f(int x) {
int cnt = 0;
while (x) {
x /= 3;
cnt++;
}
return cnt;
}
void solve() {
int l, r;
cin >> l >> r;
cout << psum[r] - psum[l - 1] + a[l] << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
psum[0] = 0;
for (int i = 1; i < MAX - 1; i++) {
a[i] = f(i);
psum[i] = psum[i - 1] + a[i];
}
int tt; cin >> tt; for (int i = 1; i <= tt; i++) {solve();}
// solve();
}
Idea: mesanu
Tutorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;
int64_t fact[N];
int64_t pw(int64_t a, int64_t b) {
int64_t r = 1;
while(b > 0) {
if(b & 1) r = (r * a) % mod;
b /= 2;
a = (a * a) % mod;
}
return r;
}
int64_t C(int64_t n, int64_t k) {
if(n < k) return 0LL;
return (fact[n] * pw((fact[n - k] * fact[k]) % mod, mod - 2)) % mod;
}
int main() {
int t; cin >> t;
fact[0] = 1;
for(int64_t i = 1; i < N; ++i) fact[i] = (fact[i - 1] * i) % mod;
while(t--) {
int n, k; cin >> n >> k;
vector<int> a(n);
int ones = 0;
for(int i = 0; i < n; ++i) {
cin >> a[i];
ones += a[i];
}
//at least k/2+1 ones
int64_t ans = 0;
for(int cnt_ones = k / 2 + 1; cnt_ones <= min(ones, k); ++cnt_ones) {
ans += C(ones, cnt_ones) * C(n - ones, k - cnt_ones) % mod;
ans %= mod;
}
cout << ans << "\n";
}
}
Idea: flamestorm
Tutorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200'007;
const int MOD = 1'000'000'007;
void solve() {
int l = 2, r = 1000;
while (l < r) {
int mid = l + (r - l) / 2;
cout << "? 1 " << mid << endl;
int resp; cin >> resp;
if (resp == mid) {
l = mid + 1;
}
else {
r = mid;
}
}
cout << "! " << l << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt; cin >> tt; for (int i = 1; i <= tt; i++) {solve();}
// solve();
}
Idea: flamestorm
Tutorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200'007;
const int MOD = 1'000'000'007;
void solve() {
int l = 1, r = 999;
while (r - l > 2) {
int a = (2 * l + r) / 3;
int b = (2 * r + l) / 3;
cout << "? " << a << ' ' << b << endl;
int resp; cin >> resp;
if (resp == (a + 1) * (b + 1)) {
r = a;
}
else if (resp == a * b) {
l = b;
}
else {
l = a; r = b;
}
}
if (r - l == 2) {
cout << "? 1 " << l + 1 << endl;
int resp; cin >> resp;
if (resp == l + 1) {l = l + 1;}
else {r = l + 1;}
}
cout << "! " << r << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt; cin >> tt; for (int i = 1; i <= tt; i++) {solve();}
// solve();
}