Skip to content
Snippets Groups Projects
Commit bff90d62 authored by Bruno Freitas Tissei's avatar Bruno Freitas Tissei
Browse files

Add solutions to ICPC_LA17

parent 5001dfcc
No related branches found
No related tags found
No related merge requests found
#include <bits/stdc++.h>
#define EPS 1e-6
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define pb push_back
#define ende '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))
using namespace std;
using ll = long long;
using ii = pair<int,int>;
bool is_vowel(char x) {
return x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int num_vow = 0;
string s; cin >> s;
for (auto i : s) num_vow += is_vowel(i);
if (num_vow && !is_vowel(s[0]))
return cout << 0 << ende, 0;
if (num_vow == 0)
return cout << 1 << ende, 0;
int i = 0, n = s.size() - 1;
bool inverted = false;
auto invert = [&]() {
swap(i, n);
inverted = !inverted;
};
auto trim_tail = [&]() {
if (inverted) n++;
else n--;
};
int ans = 0;
while (abs(n - i)) {
if (is_vowel(s[i]) && is_vowel(s[n])) {
invert();
trim_tail();
num_vow--;
} else if (!is_vowel(s[i]) && is_vowel(s[n])) {
break;
} else if (is_vowel(s[i]) && !is_vowel(s[n])) {
if (num_vow == 1) ans++;
trim_tail();
} else if (!is_vowel(s[i]) && !is_vowel(s[n])) {
trim_tail();
}
}
if (i == n && is_vowel(s[i])) ans++;
cout << ans << ende;
return 0;
}
#include <bits/stdc++.h>
#define MAX 101010
#define EPS 1e-6
#define MOD 1000000007
#define inf 0x3f3f3f3f
......@@ -20,10 +21,38 @@ using ll = long long;
using ii = pair<ll,ll>;
using iii = pair<ii,ll>;
struct BIT {
int N;
vector<ll> tree;
BIT(int N) :
N(N), tree(N)
{}
void init() {
fill(all(tree), 0LL);
}
ll query(int idx) {
ll sum = 0LL;
for (; idx > 0; idx -= (idx & -idx))
sum = max(sum, tree[idx]);
return sum;
}
void update(int idx, ll val) {
for (; idx < N; idx += (idx & -idx))
tree[idx] = max(tree[idx], val);
}
};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
BIT bit(MAX);
bit.init();
map<ii,ll> M;
int n; cin >> n;
for (int i = 0; i < n; ++i) {
......@@ -32,18 +61,43 @@ int main() {
}
vector<iii> v;
for (auto i : M) {
v.pb(iii(ii(i.fi.se, i.fi.se), i.se));
}
for (auto i : M)
v.pb(iii(ii(i.fi.fi, i.fi.se), i.se));
n = v.size();
return 0;
}
sort(all(v), [](const iii &a, const iii &b) {
if (a.fi.fi != b.fi.fi)
return a.fi.fi < b.fi.fi;
else if (a.fi.se != b.fi.se)
return a.fi.se > b.fi.se;
return a.se > b.se;
});
set<ll> S;
map<ll,ll> compress;
for (auto i : v)
S.insert(i.fi.se);
ll k = 1LL;
for (auto i : S)
compress[i] = k++;
for (auto &i : v)
i.fi.se = compress[i.fi.se];
2 8 13
1 4 12
2 1 16
ll ans = 0, last = v[0].fi.fi;
for (int i = 0; ; ) {
for (; i < n && v[i].fi.fi == last; ++i) {
ll bst = max(bit.query(v[i].fi.se - 1) + v[i].se,
bit.query(v[i].fi.se));
bit.update(v[i].fi.se, bst);
ans = max(ans, bst);
}
1 4 12
2 8 13
2 1 16
if (i >= n) break;
last = v[i].fi.fi;
}
cout << ans << ende;
return 0;
}
#include <bits/stdc++.h>
#define MAX 101010
#define EPS 1e-6
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define pb push_back
#define ende '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))
using namespace std;
using ll = long long;
using ii = pair<int,int>;
map<int,ii> forw;
map<ii,int> backw;
int L[MAX], R[MAX], val[MAX];
struct comb {
ll pos[4];
comb() { mset(pos, 0); }
static comb base() {
comb res;
res.pos[0] = res.pos[3] = 1;
return res;
}
};
comb dfs(int x) {
comb res;
comb l = (L[x]) ? (dfs(L[x])) : (comb::base());
comb r = (R[x]) ? (dfs(R[x])) : (comb::base());
for (int i = 0; i < 4; ++i)
for (int j = 0; j < 4; ++j) {
ii nand = ii(!(forw[i].fi && forw[j].fi), !(forw[i].se && forw[j].se));
res.pos[backw[nand]] = (res.pos[backw[nand]] +
(l.pos[i] % MOD) * (r.pos[j] % MOD)) % MOD;
}
if (val[x] == 0) {
res.pos[0] = (res.pos[0] + res.pos[2]) % MOD, res.pos[2] = 0;
res.pos[1] = (res.pos[1] + res.pos[3]) % MOD, res.pos[3] = 0;
} else if (val[x] == 1) {
res.pos[2] = (res.pos[2] + res.pos[0]) % MOD, res.pos[0] = 0;
res.pos[3] = (res.pos[3] + res.pos[1]) % MOD, res.pos[1] = 0;
}
return res;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
for (int i = 1; i <= n; ++i)
cin >> L[i] >> R[i] >> val[i];
forw[0] = ii(0, 0); backw[ii(0, 0)] = 0;
forw[1] = ii(0, 1); backw[ii(0, 1)] = 1;
forw[2] = ii(1, 0); backw[ii(1, 0)] = 2;
forw[3] = ii(1, 1); backw[ii(1, 1)] = 3;
comb ans = dfs(1);
cout << (ans.pos[1] + ans.pos[2]) % MOD << ende;
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment