Идея: BledDest
Разбор
Tutorial is loading...
Решение (BledDest)
t = int(input())
for i in range(t):
n = int(input())
print('Alice' if n >= 5 else 'Bob')
1841B - Сохраняем массив красивым
Идея: BledDest
Разбор
Tutorial is loading...
Решение (awoo)
for _ in range(int(input())):
q = int(input())
a = []
cnt = 0
for x in map(int, input().split()):
nw_cnt = cnt + (len(a) > 0 and a[-1] > x)
if nw_cnt == 0 or (nw_cnt == 1 and x <= a[0]):
a.append(x)
cnt = nw_cnt
print('1', end="")
else:
print('0', end="")
print()
Идея: BledDest
Разбор
Tutorial is loading...
Решение 1 (Neon)
#include <bits/stdc++.h>
using namespace std;
const int val[] = {1, 10, 100, 1000, 10000};
const int INF = 1e9;
string s;
int dp[2][5][2];
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int t;
cin >> t;
while (t--) {
cin >> s;
reverse(s.begin(), s.end());
for (int j = 0; j < 5; ++j)
dp[0][j][0] = dp[0][j][1] = -INF;
dp[0][0][0] = 0;
for (auto c : s) {
int x = c - 'A';
for (int j = 0; j < 5; ++j)
dp[1][j][0] = dp[1][j][1] = -INF;
for (int j = 0; j < 5; ++j) {
for (int t = 0; t < 2; ++t) {
for (int y = 0; y < 5; ++y) {
int nj = max(j, y);
int nt = t + (x != y);
if (nt < 2) dp[1][nj][nt] = max(dp[1][nj][nt], dp[0][j][t] + (y < nj ? -val[y] : val[y]));
}
}
}
swap(dp[0], dp[1]);
}
int ans = -INF;
for (int j = 0; j < 5; ++j)
ans = max(ans, max(dp[0][j][0], dp[0][j][1]));
cout << ans << '\n';
}
}
Решение 2 (BledDest)
def replace_char(s, i, c):
return s[:i] + c + s[i + 1:]
def id(c):
return ord(c) - ord('A')
def evaluate(s):
t = s[::-1]
ans = 0
max_id = -1
for x in t:
i = id(x)
if max_id > i:
ans -= 10 ** i
else:
ans += 10 ** i
max_id = max(max_id, i)
return ans
t = int(input())
for i in range(t):
s = input()
candidates = []
for x in ['A', 'B', 'C', 'D', 'E']:
for y in ['A', 'B', 'C', 'D', 'E']:
if not (x in s):
continue
candidates.append(replace_char(s, s.find(x), y))
candidates.append(replace_char(s, s.rfind(x), y))
print(max(map(evaluate, candidates)))
Идея: BledDest
Разбор
Tutorial is loading...
Решение (BledDest)
#include<bits/stdc++.h>
using namespace std;
bool comp(const pair<int, int>& a, const pair<int, int>& b)
{
return a.second < b.second;
}
void solve()
{
int n;
scanf("%d", &n);
vector<pair<int, int>> s(n);
for(int i = 0; i < n; i++)
scanf("%d %d", &s[i].first, &s[i].second);
vector<pair<int, int>> pairs;
for(int i = 0; i < n; i++)
for(int j = i + 1; j < n; j++)
if(max(s[i].first, s[j].first) <= min(s[i].second, s[j].second))
pairs.push_back(make_pair(min(s[i].first, s[j].first), max(s[i].second, s[j].second)));
int cnt_pairs = 0;
sort(pairs.begin(), pairs.end(), comp);
int last_pos = -1;
for(auto x : pairs)
if(x.first > last_pos)
{
cnt_pairs++;
last_pos = x.second;
}
printf("%d\n", n - cnt_pairs * 2);
}
int main()
{
int t;
scanf("%d", &t);
for(int i = 0; i < t; i++) solve();
}
Идея: BledDest
Разбор
Tutorial is loading...
Решение (awoo)
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
struct seg{
int l, r;
};
bool operator <(const seg &a, const seg &b){
return a.l < b.l;
}
int main() {
int t;
scanf("%d", &t);
while (t--){
int n;
scanf("%d", &n);
vector<int> a(n);
forn(i, n) scanf("%d", &a[i]);
long long m;
scanf("%lld", &m);
map<seg, int> used;
used[{0, n}] = n;
vector<int> ord(n);
iota(ord.begin(), ord.end(), 0);
sort(ord.begin(), ord.end(), [&a](int x, int y){
return a[x] > a[y];
});
long long ans = 0;
int j = 0;
vector<long long> cnt(n + 1);
for (int i = n; i >= 0; --i){
while (j < n && a[ord[j]] >= i){
auto it = used.upper_bound({ord[j], -1});
--it;
auto tmp = it->first;
cnt[tmp.r - tmp.l] += it->second - i;
used.erase(it);
if (tmp.l != ord[j])
used[{tmp.l, ord[j]}] = i;
if (tmp.r != ord[j] + 1)
used[{ord[j] + 1, tmp.r}] = i;
++j;
}
}
for (int i = n; i > 0; --i){
long long t = min(cnt[i], m / i);
ans += t * 1ll * (i - 1);
m -= t * 1ll * i;
if (t != cnt[i] && m > 0){
ans += m - 1;
m = 0;
}
}
printf("%lld\n", ans);
}
return 0;
}
Идея: TheWayISteppedOutTheCar и BledDest
Разбор
Tutorial is loading...
Решение (TheWayISteppedOutTheCar)
#include <iostream>
#include <algorithm>
using namespace std;
#define int long long
#define x first
#define y second
const int MAXN = 2e6 + 16;
int a[MAXN], b[MAXN];
pair<int, int> v[MAXN];
int section(pair<int, int> a) {
if (a.x > 0 && a.y >= 0)
return 0;
else if (a.x <= 0 && a.y > 0)
return 1;
else if (a.x < 0 && a.y <= 0)
return 2;
else
return 3;
}
bool cmp(pair<int, int> a, pair<int, int> b) {
if (section(a) != section(b))
return section(a) < section(b);
else
return (__int128)a.x * (__int128)b.y - (__int128)a.y * (__int128)b.x > 0;
}
void print(__int128 x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9) print(x / 10);
putchar(x % 10 + '0');
}
signed main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
vector<int> t(4);
for(int j = 0; j < 4; j++)
cin >> t[j];
a[i] = t[0] - t[1];
b[i] = t[2] - t[3];
}
int it = 0;
__int128 sx = 0, sy = 0;
for (int i = 0; i < n; ++i) {
v[i << 1].x = a[it];
v[i << 1].y = b[it];
++it;
v[i << 1 ^ 1].x = -v[i << 1].x;
v[i << 1 ^ 1].y = -v[i << 1].y;
if (!v[i << 1].x && !v[i << 1].y) {
--i, --n;
continue;
}
if (v[i << 1].y < 0 || (!v[i << 1].y && v[i << 1].x < 0))
sx += v[i << 1].x, sy += v[i << 1].y;
}
sort(v, v + 2 * n, cmp);
__int128 ans = sx * sx + sy * sy;
for (int i = 0; i < 2 * n; ++i) {
sx += v[i].x;
sy += v[i].y;
ans = std::max(ans, sx * sx + sy * sy);
}
print(ans);
return 0;
}