이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#define int ll
#define MAX 2000005
#define INF INT_MAX
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ins insert
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define lb(a,b) lower_bound(all(a),b)
#define ub(a,b) upper_bound(all(a),b)
#define sortv(a) sort(all(a))
#define outputar(a,b){\
for(int i=0;i<b;i++){\
cout << a[i] << " ";\
}\
cout << endl;\
}
#define outputvec(a){\
for(auto x:a){\
cout << (int)x << " ";\
}\
cout << endl;\
}
#define reset(a,n,v){\
for(int i=0;i<n;i++){\
a[i]=v;\
}\
}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll,ll,ll> tll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef double db;
typedef long double ldb;
inline void USACO(string filename){
freopen((filename+".in").c_str(),"r",stdin);
freopen((filename+".out").c_str(),"w",stdout);
}
int n,q,t=1,m,k,x,y,z,x2,y2,z2,a[MAX],b[MAX],mgl[MAX],mg[MAX],ml[MAX];
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//string s[MAX],str[MAX];
//int e[1001][1001];
string s1,s2,s3;
const int mod = 998244353;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int cnt,cnt1;
vector<vector<int>> g,g1;
pii dfs(int x){
cnt++;
int num=cnt;
g.pb({});
g1.pb({});
//cout << cnt << " " << x << "\n";
if(s1[x]=='?'){
cnt1++;
return {x,cnt};
}
if(s1[x+1]=='i'){
a[cnt]=1;
}
else{
a[cnt]=2;
}
x+=4;
pii p=dfs(x);
x=p.ff;
g[p.ss].pb(num);
g1[num].pb(p.ss);
b[num]++;
x++;
while(s1[x]!='?' && s1[x]!='m'){
x++;
}
p=dfs(x);
x=p.ff;
g[p.ss].pb(num);
g1[num].pb(p.ss);
b[num]++;
return {x,num};
}
void solve(){
cin >> s1;
g.clear();
g1.clear();
n=(int)s1.size();
cnt=-1;
cnt1=0;
dfs(0);
queue<int> q;
for(int i=0;i<=cnt;i++){
if(b[i]==0){
q.push(i);
}
}
while(!q.empty()){
int v=q.front();
q.pop();
int l,r;
if(a[v]!=0){
l=g1[v][0];
r=g1[v][1];
}
if(a[v]==1){
mgl[v]=min(mgl[l]+mg[r]+1,mgl[r]+mg[l]+1);
mg[v]=mg[l]+mg[r]+1;
ml[v]=min(ml[l],ml[r]);
}
else if(a[v]==2){
mgl[v]=min(mgl[l]+ml[r]+1,mgl[r]+ml[l]+1);
ml[v]=ml[l]+ml[r]+1;
mg[v]=min(mg[l],mg[r]);
}
for(auto x:g[v]){
b[x]--;
if(b[x]==0){
q.push(x);
}
}
//cout << v << " " << mgl[v] << " " << mg[v] << " " << ml[v] << "\n";
}
cout << max(cnt1-mgl[0],0) << "\n";
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("input13.txt","r",stdin);
//cin >> t;
ll cnt1=1;
while(t--){
solve();
cnt1++;
}
}
# | 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... |