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;
//#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() {
map<int, int> hs;
cin >> hs[0] >> hs[1] >> hs[2] >> hs[3];
int total = hs[0] + hs[1] + hs[2] + hs[3];
FOR(st, 0, 4) if (hs[st]) {
vi res;
auto ths = hs;
ths[st]--;
res.pb(st);
int last = st;
FOR(i, 0, total - 1) {
if (ths[last - 1]) {
ths[last - 1]--;
res.pb(last - 1);
last--;
}
else if (ths[last + 1]) {
ths[last + 1]--;
res.pb(last + 1);
last++;
}
else {
break;
}
}
if (sz(res) == total) {
cout << "YES\n";
FOR(i, 0, sz(res)) cout << res[i] << " \n"[i == sz(res) - 1];
return;
}
}
cout << "NO\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: 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...
Author: chemthan, prepare laoriu, I_love_Hoang_Yen Tutorial is loading...
Author: chemthan, prepare laoriu, I_love_Hoang_Yen Tutorial is loading...
Author: chemthan, prepare laoriu, I_love_Hoang_Yen Tutorial is loading...
Author: chemthan, prepare laoriu, I_love_Hoang_Yen Tutorial is loading...
Author: chemthan, prepare laoriu, I_love_Hoang_Yen Tutorial is loading...
Author: chemthan, prepare laoriu, I_love_Hoang_Yen