Idea: BledDest
Tutorial
Tutorial is loading...
Solution (BledDest)
t = int(input())
for i in range(t):
n = int(input())
x = list(map(int, input().split()))
if n > 2 or x[0] + 1 == x[-1]:
print('NO')
else:
print('YES')
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (Neon)
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int l, r, L, R;
cin >> l >> r >> L >> R;
int inter = min(r, R) - max(l, L) + 1;
int ans = inter - 1;
if (inter <= 0) {
ans = 1;
} else {
ans += (l != L);
ans += (r != R);
}
cout << ans << '\n';
}
}
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (adedalic)
fun main() {
repeat(readln().toInt()) {
val (n, k) = readln().split(" ").map { it.toInt() }
val a = readln().split(" ").map { it.toInt() }.sortedDescending().toIntArray()
var score = 0L
var rem = k
for (i in a.indices) {
if (i % 2 == 0) {
score += a[i]
}
else {
val needed = minOf(rem, a[i - 1] - a[i])
a[i] += needed
rem -= needed
score -= a[i]
}
}
println(score)
}
}
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (Neon)
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const string vars[] = {"BG", "BR", "BY", "GR", "GY", "RY"};
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int t;
cin >> t;
while (t--) {
int n, q;
cin >> n >> q;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
char s[5];
cin >> s;
a[i] = find(vars, vars + 6, s) - vars;
}
vector<vector<int>> lf(n), rg(n);
for (int o = 0; o < 2; ++o) {
vector<int> last(6, -INF);
for (int i = 0; i < n; ++i) {
last[a[i]] = (o ? n - i - 1 : i);
(o ? rg[n - i - 1] : lf[i]) = last;
}
reverse(a.begin(), a.end());
}
while (q--) {
int x, y;
cin >> x >> y;
--x; --y;
int ans = INF;
for (int j = 0; j < 6; ++j) {
if (a[x] + j != 5 && j + a[y] != 5) {
ans = min(ans, abs(x - lf[x][j]) + abs(lf[x][j] - y));
ans = min(ans, abs(x - rg[x][j]) + abs(rg[x][j] - y));
}
}
if (ans > INF / 2) ans = -1;
cout << ans << '\n';
}
}
}
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (BledDest)
#include<bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int N = int(1e7) + 43;
int lp[N + 1];
vector<int> pr;
int idx[N + 1];
void precalc()
{
for (int i = 2; i <= N; i++)
{
if (lp[i] == 0)
{
lp[i] = i;
pr.push_back(i);
}
for (int j = 0; j < pr.size() && pr[j] <= lp[i] && i * 1ll * pr[j] <= N; ++j)
lp[i * pr[j]] = pr[j];
}
for (int i = 0; i < pr.size(); i++)
idx[pr[i]] = i + 1;
}
int get(int x)
{
if(x == 1) return 1;
x = lp[x];
if(x == 2)
return 0;
else return idx[x];
}
void solve()
{
int n;
scanf("%d", &n);
int res = 0;
for(int i = 0; i < n; i++)
{
int x;
scanf("%d", &x);
res ^= get(x);
}
if(res) puts("Alice");
else puts("Bob");
}
int main()
{
precalc();
int t;
scanf("%d", &t);
for(int i = 0; i < t; i++) solve();
}
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (Neon)
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
for (auto& x : a) cin >> x;
vector<int> p(n + 1);
for (int i = 0; i < n; ++i) p[i + 1] = p[i] + a[i];
map<int, int> cnt;
long long ans = 0;
for (int len = 0; len <= n; ++len) {
for (int i = 0; i <= n - len; ++i) {
int s = p[i] + p[i + len];
ans += len;
ans -= 2 * cnt[s];
ans -= (s % 2 == 1 || !binary_search(p.begin(), p.end(), s / 2));
cnt[s] += 1;
}
}
cout << ans << '\n';
}
}
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (awoo)
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
const int D = 10;
const int INF = 1e9;
typedef array<array<int, D>, D> mat;
mat mul(const mat &a, const mat &b, bool fl){
mat c;
forn(i, D) forn(j, D) c[i][j] = INF;
if (fl){
forn(i, D) forn(j, D){
c[j][i] = min(c[j][i], min(a[j][0] + b[0][i], a[j][i] + b[i][i]));
c[j][0] = min(c[j][0], a[j][i] + b[i][0]);
}
}
else{
forn(i, D) forn(j, D){
c[i][j] = min(c[i][j], min(a[i][0] + b[0][j], a[i][i] + b[i][j]));
c[0][j] = min(c[0][j], a[0][i] + b[i][j]);
}
}
return c;
}
struct minqueue{
vector<pair<mat, mat>> st1, st2;
void push(const mat &a){
if (!st1.empty())
st1.push_back({a, mul(st1.back().second, a, true)});
else
st1.push_back({a, a});
}
void pop(){
if (st2.empty()){
st2 = st1;
reverse(st2.begin(), st2.end());
st1.clear();
assert(!st2.empty());
st2[0].second = st2[0].first;
forn(i, int(st2.size()) - 1)
st2[i + 1].second = mul(st2[i + 1].first, st2[i].second, false);
}
st2.pop_back();
}
int get(){
if (st1.empty()) return st2.back().second[0][0];
if (st2.empty()) return st1.back().second[0][0];
int ans = INF;
forn(i, D) ans = min(ans, st2.back().second[0][i] + st1.back().second[i][0]);
return ans;
}
};
mat tran[D];
void init(int d){
forn(i, D) forn(j, D) tran[d][i][j] = INF;
for (int i = 1; i <= 9; ++i){
tran[d][i][i] = i;
tran[d][i][0] = i;
}
tran[d][0][d] = 0;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
for (int i = 1; i <= 9; ++i) init(i);
int n, k;
cin >> n >> k;
string s;
cin >> s;
minqueue q;
forn(i, n){
q.push(tran[s[i] - '0']);
if (i - k >= 0) q.pop();
if (i - k >= -1) cout << q.get() << ' ';
}
cout << '\n';
return 0;
}