Skip to content

Commit

Permalink
blah blah blah
Browse files Browse the repository at this point in the history
  • Loading branch information
KryptoCrash committed Nov 19, 2021
1 parent 7c67909 commit e1ef1c3
Show file tree
Hide file tree
Showing 22 changed files with 1,002 additions and 0 deletions.
26 changes: 26 additions & 0 deletions abcconj.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);

ll n;
cin >> n;

ll ans = 0;
for (ll i = 1; i*i*i<=n; i++) {
for(ll j = i; j*j*i <= n; j++) {
if (n / (i * j) - j + 1 < 0) continue;
ans += n / (i * j) - j + 1;
}
}

cout << ans << endl;

return 0;
}
23 changes: 23 additions & 0 deletions arrgame.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main() {
ll n;
cin >> n;

vector<ll> a(n + 2);
a[0] = a[n + 1] = -1;
for (ll i = 1; i <= n; i++) cin >> a[i];

ll l, r;
l = r = 0;
while (a[l] < a[l + 1]) l++;
reverse(a.begin(), a.end());
while (a[r] < a[r + 1]) r++;

cout << (l % 2 || r % 2 ? "Alice" : "Bob") << endl;

return 0;
}
45 changes: 45 additions & 0 deletions arropp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using vpi = vector<pi>;
using vb = vector<bool>;

#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve(){
ll n;
cin>>n;

vi a(n);
for(ll i = 0; i < n; i++) {
cin >> a[i];
}

Tree<pi> ac;
ll ans = 0;
for (ll i = 0; i < n; i++) {
ac.insert({a[i], i});
ll f = ac.order_of_key({a[i], 0});
ll u = i+1-ac.order_of_key({a[i], n});
ans += min(f, u);
}
cout << ans << endl;
}

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);

ll t;
cin >> t;
while (t--) solve();

return 0;
}
71 changes: 71 additions & 0 deletions bakery.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using vb = vector<bool>;

void solve() {
ll n, k;
cin >> n >> k;

vi a(n);
ll x = 0;
for (ll i = 0; i < n; i++) {
cin >> a[i];
x ^= a[i];
}

vector<set<ll>> ed(n, set<ll>());

for (ll i = 0; i < n - 1; i++) {
ll u, v;
cin >> u >> v;
u--, v--;

ed[u].insert(v);
ed[v].insert(u);
}

if (x == 0) {
cout << "YES" << endl;
return;
}

// root tree and do weird xor dfs
vi x_sum(n);
ll found = 0;
function<pair<ll, bool>(ll, ll)> dfs = [&](ll v, ll p) {
ll xo = a[v];
bool works = true;
for (ll child : ed[v]) {
if (child != p) {
pi f = dfs(child, v);
xo ^= f.first;
if(f.second) works = false;
}
}
x_sum[v] = xo;
if (works && xo == x) found++;
if (!works && xo == 0) found++;
return make_pair(xo, xo == x || works == false);
};

dfs(0, -1);

if (found >= 2 && k > 2) cout << "YES" << endl;
else cout << "NO" << endl;
}

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);

ll t;
cin >> t;

while (t--) solve();

return 0;
}
49 changes: 49 additions & 0 deletions bandit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);

ll n;
cin >> n;

vector<set<ll>> ed(n, set<ll>({}));
for (ll i = 1; i < n; i++) {
ll p;
cin >> p;
p--;
ed[p].insert(i);
}

vi a(n);
for (ll i = 0; i < n; i++) {
cin >> a[i];
}

ll max_ans = 0;

function<pi(ll)> dfs = [&](ll v) {
ll sum = a[v];
ll sz = 0;
for (ll child : ed[v]) {
pi ar = dfs(child);
sum += ar.first;
sz += ar.second;
}

if (sz == 0) sz = 1;
max_ans = max(max_ans, (ll)ceil((double)sum / (double)sz));
return make_pair(sum, sz);
};

dfs(0);

cout << max_ans << endl;

return 0;
}
54 changes: 54 additions & 0 deletions banknotes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

void solve() {
int n, k;
cin >> n >> k;

vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}

// calc cost of each place
vector<ll> c(20);
int r_mx = 0;
int pt = 0;
ll cur_k = 0;
for (int i = 0; i < 20; i++) {
while (true) {
if (pt + 1 >= n) break;
if (a[pt + 1] > i) {
break;
}
pt++;
}
r_mx = max(r_mx, a[pt]);
c[i] = (ll)pow(10,i - r_mx);
cur_k += 9 * c[i];
}

ll ans = 0;

for (int p = 19; p >= 0; p--) {
for (int d = 9; d > 0; d--) {
cur_k -= c[p];
if (!(cur_k > k)) {
cur_k += c[p];
ans += (ll)pow(10, p) * d;
break;
}
}
}

cout << ans << endl;
}

int main() {
int t;
cin >> t;

while (t--) solve();
}
34 changes: 34 additions & 0 deletions building.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);

int n;
cin >> n;

vector<bool> pos(1001);

for(int i = 1; i < 400; i++) {
for(int j = 1; j < 400; j++) {
if (4 * i * j + 3 * i + 3 * j > 1000) continue;
pos[4 * i * j + 3 * i + 3 * j] = true;
}
}

vi a(n);
int ans = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if(pos[a[i]]) ans++;
}

cout << n - ans << endl;

return 0;
}
31 changes: 31 additions & 0 deletions divis.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <bits/stdc++.h>
using namespace std;

int main() {
ios::sync_with_stdio(false);
cin.tie(0);

int t;
cin >> t;

int n;
int i;
int a;
int dv;
while(t--) {
cin >> n;
bool done = false;
for(i = 1; i <= n; i++) {
cin >> a;

if(done) continue;
for(dv = i + 1; a % dv == 0; dv--) {
if(dv < 2) done = true;
}
}

cout << (done ? "NO" : "YES") << endl;
}

return 0;
}
33 changes: 33 additions & 0 deletions flow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <bits/stdc++.h>
using namespace std;

void solve() {
int n, m;
cin >> n >> m;

vector<int> p(n + 1);
for(int i = 1; i <= n; i++) {
int a;
cin >> a;

p[i] = p[i - 1] + a;
}

int ans = 0;

for(int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
if(p[b] - p[a - 1] > 0) ans += p[b] - p[a - 1];
}

cout << ans << endl;
}

int main() {
int t;
cin >> t;
while(t--) solve();

return 0;
}
Loading

0 comments on commit e1ef1c3

Please sign in to comment.