Идея: BledDest
Разбор
Tutorial is loading...
Решение (BledDest)
t = int(input())
for i in range(t):
print(eval(input()))
Идея: BledDest
Разбор
Tutorial is loading...
Решение (BledDest)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
for(int _ = 0; _ < t; _++)
{
vector<int> a(4);
for(int i = 0; i < 4; i++)
cin >> a[i];
int maxpos = max_element(a.begin(), a.end()) - a.begin();
int minpos = min_element(a.begin(), a.end()) - a.begin();
if(maxpos + minpos == 3)
puts("YES");
else
puts("NO");
}
}
Идея: BledDest
Разбор
Tutorial is loading...
Решение (BledDest)
def construct(f, k):
return [(i + 2 if i < f - 1 else 1) for i in range(k)]
t = int(input())
for i in range(t):
k, n = map(int, input().split())
ans = 1
for f in range(1, k):
d = construct(f, k - 1)
if sum(d) <= n - 1:
ans = f
res = [1]
d = construct(ans, k - 1)
for x in d:
res.append(res[-1] + x)
print(*res)
Идея: BledDest
Разбор
Tutorial is loading...
Решение (BledDest)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
for(int i = 0; i < t; i++)
{
int n;
cin >> n;
vector<int> a(n);
for(int j = 0; j < n; j++)
cin >> a[j];
int mn = 0, mx = int(1e9);
for(int j = 0; j + 1 < n; j++)
{
int x = a[j];
int y = a[j + 1];
int midL = (x + y) / 2;
int midR = (x + y + 1) / 2;
if(x < y)
mx = min(mx, midL);
if(x > y)
mn = max(mn, midR);
}
if(mn <= mx) cout << mn << endl;
else cout << -1 << endl;
}
}
Идея: BledDest
Разбор
Tutorial is loading...
Решение (Neon)
for tc in range(int(input())):
n = int(input())
p = list(map(int, input().split()))
a, b, c = 0, 0, 0
for i in range(n):
if p[i] != i + 1 and p[i] != n - i:
c += 1
elif p[i] != i + 1:
a += 1
elif p[i] != n - i:
b += 1
if a + c <= b:
print("First")
elif b + c < a:
print("Second")
else:
print("Tie")
Идея: BledDest
Разбор
Tutorial is loading...
Решение (awoo)
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
struct op{
int t, x, y, i;
};
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int main(){
int n, m, k;
cin >> n >> m >> k;
vector<vector<string>> a(k + 1, vector<string>(n));
forn(z, k + 1) forn(i, n)
cin >> a[z][i];
vector<int> cnt(k + 1);
forn(z, k + 1){
for (int i = 1; i < n - 1; ++i){
for (int j = 1; j < m - 1; ++j){
bool ok = true;
forn(t, 4)
ok &= a[z][i][j] != a[z][i + dx[t]][j + dy[t]];
cnt[z] += ok;
}
}
}
vector<int> ord(k + 1);
iota(ord.begin(), ord.end(), 0);
sort(ord.begin(), ord.end(), [&cnt](int x, int y){
return cnt[x] > cnt[y];
});
vector<op> ops;
forn(z, k){
forn(i, n) forn(j, m) if (a[ord[z]][i][j] != a[ord[z + 1]][i][j]){
a[ord[z]][i][j] ^= '0' ^ '1';
ops.push_back({1, i + 1, j + 1, -1});
}
ops.push_back({2, -1, -1, ord[z + 1] + 1});
}
cout << ord[0] + 1 << '\n';
cout << ops.size() << '\n';
for (auto it : ops){
cout << it.t << " ";
if (it.t == 1)
cout << it.x << " " << it.y << '\n';
else
cout << it.i << '\n';
}
}
Идея: BledDest
Разбор
Tutorial is loading...
Решение (adedalic)
#include<bits/stdc++.h>
using namespace std;
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define sz(a) int((a).size())
typedef long long li;
int n;
li x, y;
vector<li> a;
inline bool read() {
if(!(cin >> n >> x >> y))
return false;
a.resize(n);
fore (i, 0, n)
cin >> a[i];
return true;
}
li ceil(li a, li b) {
assert(a >= 0 && b >= 0);
return (a + b - 1) / b;
}
inline void solve() {
sort(a.begin(), a.end());
vector<li> t(n), b(n);
fore (i, 0, n) {
if (i > 0 && b[i - 1] >= a[i]) {
t[i] = t[i - 1];
b[i] = b[i - 1] + 1;
} else {
t[i] = a[i] - i;
b[i] = a[i] + 1;
}
}
li ans = 0;
while (x < y) {
int pos = int(upper_bound(t.begin(), t.end(), x) - t.begin());
li p = pos, m = n - pos;
if (x + p >= y) {
cout << ans + (y - x) << endl;
return;
}
if (p <= m) {
cout << -1 << endl;
return;
}
//1. x + k(p - m) + p >= y
li k = ceil(y - x - p, p - m);
if (pos < n) {
//2. x + k(p - m) >= t[pos]
k = min(k, ceil(t[pos] - x, p - m));
}
ans += k * n;
//x + k(p - m) < y, since 1. and p >= p - m
x += k * (p - m);
}
assert(false);
}
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
int tt = clock();
#endif
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cout << fixed << setprecision(15);
int t; cin >> t;
while (t--) {
read();
solve();
#ifdef _DEBUG
cerr << "TIME = " << clock() - tt << endl;
tt = clock();
#endif
}
return 0;
}