This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sort undefined_function // To use stable_sort instead sort
#define bpc __builtin_popcount
#define ull unsigned long long
#define ld double
#define ll long long
#define mp make_pair
#define F first
#define S second
#pragma GCC optimize("O3")
#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace __gnu_pbds;
using namespace std;
typedef tree<long long, null_type, less_equal<long long>,
rb_tree_tag, tree_order_statistics_node_update> Tree;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll INF = 9223372036854775807LL;
const ll inf = 2147483647;
const ll MOD = 998244353; //[998244353, 1e9 + 7, 1e9 + 13]
const ld PI = acos(-1);
const ll NROOT = 800;
ll binpow(ll a, ll b, ll _MOD = -1) {
if (_MOD == -1)
_MOD = MOD;
ll res = 1;
for (; b; b /= 2, a *= a, a %= _MOD)
if (b & 1) res *= a, res %= _MOD;
return res;
}
void set_IO(string s) {
#ifndef LOCAL
string in = s + ".in";
string out = s + ".out";
freopen(in.c_str(), "r", stdin);
freopen(out.c_str(), "w", stdout);
#endif
}
bool dataOverflow(ll a, ll b) {return (log10(a) + log10(b) >= 18);}
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a * b / gcd(a, b);}
ll ceil(ll a, ll b) {return (a + b - 1) / b;}
ll invmod(ll a) {return binpow(a, MOD - 2);}
string s;
vector<int> p, v, comma;
map<pair<int, int>, int> memo;
int SZ(int l, int r) {
if (s[l] == '?')
return 1;
if (memo.find({l, r}) != memo.end())
return memo[{l, r}];
return memo[{l, r}] = SZ(l + 4, comma[l] - 1) + SZ(comma[l] + 1, r - 1);
}
bool calc(int l, int r, int x, int mi, int ma) {
if (s[l] == '?')
return 1;
int SZL = SZ(l + 4, comma[l] - 1); // Left Child
int SZR = SZ(comma[l] + 1, r - 1); // Right Child
bool ans = 0;
if (s[l + 1] == 'i') { // MIN
if (ma - SZL >= x)
ans |= calc(comma[l] + 1, r - 1, x, mi, ma - SZL);
if (ma - SZR >= x)
ans |= calc(l + 4, comma[l] - 1, x, mi, ma - SZR);
} else { // MAX
if (mi + SZL <= x)
ans |= calc(comma[l] + 1, r - 1, x, mi + SZL, ma);
if (mi + SZR <= x)
ans |= calc(l + 4, comma[l] - 1, x, mi + SZR, ma);
}
return ans;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> s;
p.resize(s.size(), -1);
comma.resize(s.size(), -1);
int n = 0;
stack<int> aux;
for (int i = 0; i < s.size(); i ++) {
if (s[i] == '?') {
p[i] = n;
n ++;
}
if (s[i] == ',')
comma[aux.top()] = i;
if (s[i] == 'm')
aux.push(i);
if (s[i] == ')')
aux.pop();
}
v.resize(n);
for (int i = 0; i < n; i ++)
v[i] = i + 1;
set<int> ans;
for (int i = 1; i <= n; i ++) {
if (calc(0, s.size() - 1, i, 1, n))
ans.insert(i);
dbg();
}
cout << ans.size() << "\n";
dbg(ans);
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int32_t main()':
Main.cpp:107:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
107 | for (int i = 0; i < s.size(); i ++) {
| ~~^~~~~~~~~~
Main.cpp:18:26: warning: statement has no effect [-Wunused-value]
18 | #define dbg(...) 0
| ^
Main.cpp:129:17: note: in expansion of macro 'dbg'
129 | dbg();
| ^~~
Main.cpp:18:26: warning: statement has no effect [-Wunused-value]
18 | #define dbg(...) 0
| ^
Main.cpp:133:9: note: in expansion of macro 'dbg'
133 | dbg(ans);
| ^~~
Main.cpp: In function 'void set_IO(std::string)':
Main.cpp:47:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | freopen(in.c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:48:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | freopen(out.c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |