Sorry for delay, we are working on remaining problem. Below are draft editorials.
Tutorial is loading...
Python Solution
T = int(input())
for tc in range(T):
s = [c for c in input()]
n = len(s)
i = 0
while (i < n):
if (s[i] == '?'):
prv = 'd' if i == 0 else s[i - 1]
nxt = 'e' if i + 1 >= n else s[i + 1]
for x in ['a', 'b', 'c']:
if (x != prv) and (x != nxt):
s[i] = x
break
else:
i += 1
ok = True
for i in range(n - 1):
if (s[i] == s[i + 1]):
print("-1")
ok = False
break
if (ok == True):
print("".join(s))
Author: laoriu, prepare laoriu, I_love_Hoang_Yen
Tutorial is loading...
C++ solution
#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 239;
int n, p[M], x;
void solve()
{
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> x;
p[x - 1] = i;
}
int l = n;
int r = 0;
string ans = "";
for (int i = 0; i < n; i++)
{
l = min(l, p[i]);
r = max(r, p[i]);
if (r - l == i)
ans += '1';
else
ans += '0';
}
cout << ans << "\n";
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t;
cin >> t;
while (t--)
solve();
return 0;
}
Author: isaf27, prepare laoriu, I_love_Hoang_Yen
Tutorial is loading...
C++ solution
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < int(n); i++)
int main() {
int t;
cin >> t;
forn(tt, t) {
int n;
cin >> n;
map<int,int> c;
forn(i, n) {
int pi;
cin >> pi;
c[-pi]++;
}
vector<int> pp;
for (auto p: c)
pp.push_back(p.second);
bool ok = false;
int g = pp[0];
int i = 1;
int s = 0;
while (s <= g && i < pp.size())
s += pp[i++];
if (g < s) {
int b = 0;
while (b <= g && i < pp.size())
b += pp[i++];
while (i < pp.size() && g + s + b + pp[i] <= n / 2)
b += pp[i++];
if (g < b && g + s + b <= n / 2) {
ok = true;
cout << g << " " << s << " " << b << endl;
}
}
if (!ok)
cout << 0 << " " << 0 << " " << 0 << endl;
}
}
Author: MikeMirzayanov, prepare laoriu, I_love_Hoang_Yen
Tutorial is loading...
C++ Solution
#include <bits/stdc++.h>
using namespace std;
int main() {
map<int, int> hs;
cin >> hs[0] >> hs[1] >> hs[2] >> hs[3];
int total = hs[0] + hs[1] + hs[2] + hs[3];
for (int st = 0; st < 4; st++) if (hs[st]) {
vector<int> res;
auto ths = hs;
ths[st]--;
res.push_back(st);
int last = st;
for (int i = 0; i < total - 1; i++) {
if (ths[last - 1]) {
ths[last - 1]--;
res.push_back(last - 1);
last--;
}
else if (ths[last + 1]) {
ths[last + 1]--;
res.push_back(last + 1);
last++;
}
else {
break;
}
}
if ((int) res.size() == total) {
cout << "YES\n";
for (int i = 0; i < (int) res.size(); i++) {
cout << res[i] << " \n"[i == (int) res.size() - 1];
}
return 0;
}
}
cout << "NO\n";
return 0;
}
Author: laoriu, prepare laoriu, I_love_Hoang_Yen
Tutorial is loading...
C++ Solution
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
//const int MOD = (int) 1e9 + 7;
const int MOD = 119 << 23 | 1;
const int FFTMOD = 119 << 23 | 1;
const int INF = (int) 1e9 + 23111992;
const ll LINF = (ll) 1e18 + 23111992;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ull isqrt(ull k) {ull r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int mrand() {return abs((int) mt());}
#define db(x) cerr << "[" << #x << ": " << (x) << "] ";
#define endln cerr << "\n";
void chemthan() {
int n; cin >> n;
vi p(n);
FOR(i, 0, n) cin >> p[i], p[i] = mult(p[i], inv(100));
int res = 0;
FOR(i, 0, n) {
addmod(res, 1);
res = mult(res, inv(p[i]));
}
cout << res << "\n";
}
int main(int argc, char* argv[]) {
ios_base::sync_with_stdio(0), cin.tie(0);
if (argc > 1) {
assert(freopen(argv[1], "r", stdin));
}
if (argc > 2) {
assert(freopen(argv[2], "wb", stdout));
}
chemthan();
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
}
Author: chemthan, prepare laoriu, I_love_Hoang_Yen
Tutorial is loading...
C++ Solution
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000 + 10;
const int MOD = 998244353;
int n;
string s;
int s_close[MAXN];
int C[MAXN][MAXN], SC[MAXN][MAXN];
int main() {
cin >> s;
n = s.length();
int tot_question = 0;
for(int i = 0; i < n; ++i) {
s_close[i + 1] = s_close[i] + (s[i] == ')');
tot_question += (s[i] == '?');
}
for(int i = 0; i <= n; ++i) C[i][0] = C[i][i] = 1;
for(int i = 2; i <= n; ++i)
for(int j = 1; j < i; ++j) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;
for(int i = 0; i <= n; ++i) {
SC[i][0] = C[i][0];
for(int j = 1; j <= i; ++j) SC[i][j] = (SC[i][j - 1] + C[i][j]) % MOD;
}
int l_open = 0;
int r_question = tot_question;
int res = 0;
for(int i = 0; i < n; ++i) {
if (s[i] == ')') continue;
l_open += (s[i] == '(');
int r_close = s_close[n] - s_close[i];
int m = tot_question;
if (s[i] == '?') {
m--; l_open++; r_question--;
}
// X = C(left question, u) * C(right question, v)
// where l_open + u <= r_close + v
for(int v = 0; v <= r_question; ++v) {
int maxu = min(r_close + v - l_open, m - r_question);
if (maxu >= 0) {
res = (res + ((1LL * SC[m - r_question][maxu] * C[r_question][v]) % MOD) ) %MOD;
}
}
if (s[i] == '?') l_open--;
}
cout << res << "\n";
}
Author: chemthan, prepare laoriu, I_love_Hoang_Yen
Tutorial is loading...
C++ Solution
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
//const int MOD = (int) 1e9 + 7;
const int MOD = 119 << 23 | 1;
const int FFTMOD = 119 << 23 | 1;
const int INF = (int) 1e9 + 23111992;
const ll LINF = (ll) 1e18 + 23111992;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ull isqrt(ull k) {ull r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int mrand() {return abs((int) mt());}
#define db(x) cerr << "[" << #x << ": " << (x) << "] ";
#define endln cerr << "\n";
struct node_t {
int prd;
int val;
node_t() {
prd = val = 0;
}
};
node_t operator + (node_t a, node_t b) {
if (!a.prd) return b;
if (!b.prd) return a;
node_t c;
c.prd = mult(a.prd, b.prd);
c.val = mult(a.val, b.prd);
addmod(c.val, b.val);
return c;
}
void chemthan() {
int n, q; cin >> n >> q;
vi p(n);
FOR(i, 0, n) cin >> p[i], p[i] = mult(p[i], inv(100));
vector<node_t> st(n << 2);
auto upd = [&] (int p, node_t val) {
for (st[p += n] = val; 1 < p; ) p >>= 1, st[p] = st[p << 1] + st[p << 1 | 1];
};
auto query = [&] (int l, int r) {
node_t lres, rres;
for (l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
if (l & 1) {
lres = lres + st[l++];
}
if (r & 1) {
rres = st[--r] + rres;
}
}
return (lres + rres).val;
};
FOR(i, 0, n) {
node_t c;
c.val = c.prd = inv(p[i]);
upd(i, c);
}
set<int> ss;
ss.insert(0);
int res = query(0, n - 1);
FOR(i, 0, q) {
string op; int u; cin >> u; u--;
auto it = ss.lower_bound(u);
if (it == ss.end() || *it != u) {
it = ss.insert(u).fi;
int lo = *(--it);
it++;
int hi = n;
if (++it != ss.end()) {
hi = *it;
}
submod(res, query(lo, hi - 1));
addmod(res, query(lo, u - 1));
addmod(res, query(u, hi - 1));
}
else {
int lo = *(--it);
it++;
int hi = n;
if (++it != ss.end()) {
hi = *it;
}
addmod(res, query(lo, hi - 1));
submod(res, query(lo, u - 1));
submod(res, query(u, hi - 1));
ss.erase(u);
}
cout << res << "\n";
}
}
int main(int argc, char* argv[]) {
ios_base::sync_with_stdio(0), cin.tie(0);
if (argc > 1) {
assert(freopen(argv[1], "r", stdin));
}
if (argc > 2) {
assert(freopen(argv[2], "wb", stdout));
}
chemthan();
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
}
Author: chemthan, prepare laoriu, I_love_Hoang_Yen
Tutorial is loading...
C++ Solution
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
//const int MOD = (int) 1e9 + 7;
const int MOD = 119 << 23 | 1;
const int FFTMOD = 119 << 23 | 1;
const int INF = (int) 1e9 + 23111992;
const ll LINF = (ll) 1e18 + 23111992;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ull isqrt(ull k) {ull r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int mrand() {return abs((int) mt());}
#define db(x) cerr << "[" << #x << ": " << (x) << "] ";
#define endln cerr << "\n";
void chemthan() {
string s; assert(cin >> s);
int k = sz(s) + 1;
int a = 0, b = 0, c = 0, d = 0;
for (char e : s) {
if (e == ')') {
b++;
}
if (e == '?') {
d++;
}
}
map<int, vector<int>> dps;
auto calc = [&] (int a, int b, int c, int d) {
int x = b + d - a;
if (x < 0) return 0;
int k = c + d;
chkmin(x, k);
if (dps.count(k)) return dps[k][x];
auto& dp = dps[k];
dp.resize(k + 1);
int t = 0, w = 1;
FOR(i, 0, k + 1) {
addmod(t , w);
dp[i] = t;
w = mult(w, c + d - i);
w = mult(w, inv(i + 1));
}
return dp[x];
};
int res = 0;
FOR(i, 0, sz(s)) {
char e = s[i];
if (e == '(') {
a++;
}
if (e == ')') {
b--;
}
if (e == '?') {
c++;
d--;
}
if (e == '(') {
addmod(res, calc(a, b, c, d));
}
else if (e == '?') {
a++, c--;
addmod(res, calc(a, b, c, d));
a--, c++;
}
}
cout << res << "\n";
}
int main(int argc, char* argv[]) {
ios_base::sync_with_stdio(0), cin.tie(0);
if (argc > 1) {
assert(freopen(argv[1], "r", stdin));
}
if (argc > 2) {
assert(freopen(argv[2], "wb", stdout));
}
chemthan();
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
}
Author: chemthan, prepare laoriu, I_love_Hoang_Yen
Tutorial is loading...
C++ Solution
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int FFTMOD = 119 << 23 | 1;
const int INF = (int) 1e9 + 23111992;
const ll LINF = (ll) 1e18 + 23111992;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ull isqrt(ull k) {ull r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int mrand() {return abs((int) mt());}
#define db(x) cerr << "[" << #x << ": " << (x) << "] ";
#define endln cerr << "\n";
void chemthan() {
int n, m; cin >> n >> m;
vi d(n);
vector<vi> g(n, vi(n));
vector<vi> f(n, vi(n, 1));
FOR(i, 0, m) {
int u, v; cin >> u >> v; u--, v--;
d[u]++;
g[u][v] = 1, g[v][u] = 2;
f[u][v] = f[v][u] = 0;
}
priority_queue<pi> heap;
FOR(i, 0, n) {
if (d[i] < n - 1) {
heap.push({-d[i], i});
}
}
while (sz(heap)) {
int u = heap.top().se;
heap.pop();
queue<int> que;
vi vis(n), from(n);
que.push(u), vis[u] = 1;
int id = -1;
while (sz(que)) {
int v = que.front(); que.pop();
int found = 0;
FOR(w, 0, n) if (w != v && !g[v][w]) {
found = 1;
break;
}
if (found) {
id = v;
break;
}
FOR(w, 0, n) if (!vis[w] && g[v][w] == 2 && f[v][w] == 1) {
que.push(w), vis[w] = 1;
from[w] = v;
}
}
if (id == -1) {
continue;
}
FOR(v, 0, n) if (v != id && !g[id][v]) {
g[id][v] = 1, g[v][id] = 2;
break;
}
while (id != u) {
int nid = from[id];
swap(g[id][nid], g[nid][id]);
id = nid;
}
d[u]++;
if (d[u] < n - 1) {
heap.push({-d[u], u});
}
}
FOR(i, 0, n) {
FOR(j, 0, n) {
if (i == j) {
cout << 0;
}
else {
cout << 2 - g[i][j];
}
}
cout << "\n";
}
}
int main(int argc, char* argv[]) {
ios_base::sync_with_stdio(0), cin.tie(0);
if (argc > 1) {
assert(freopen(argv[1], "r", stdin));
}
if (argc > 2) {
assert(freopen(argv[2], "wb", stdout));
}
chemthan();
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
}
Author: chemthan, prepare laoriu, I_love_Hoang_Yen
Tutorial is loading...
Python Solution
n,a,d=map(int,input().split())
print(368131125*a%10**9*12*10**9+1,368131125*d%10**9*12*10**9)
Author: chemthan, prepare laoriu, I_love_Hoang_Yen