제출 #1323911

#제출 시각아이디문제언어결과실행 시간메모리
1323911i271828Homework (CEOI22_homework)C++20
100 / 100
216 ms171688 KiB
#include <bits/stdc++.h>
#define pii pair<int,int>
#define ll long long
using namespace std;

const int MAX=3e6+5;
const int INF=1<<30;

int N;
string str;
int c=0;
vector<int> adj[MAX];
int T[MAX];
int D[MAX];

pii dfs(int x){
	if (T[x]==2){
		D[x]=1;
		return {0,0};
	}
	int a=adj[x][0],b=adj[x][1];
	auto [a0,a1]=dfs(a);
	auto [b0,b1]=dfs(b);
	D[x]=D[a]+D[b];
	if (T[x]==0) return {min(a0,b0),a1+b1};
	if (T[x]==1) return {a0+b0+1,D[x]-1-min(D[a]-1-a1,D[b]-1-b1)};
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	cin>>str;
	N=str.size();
	int l=0;
	vector<int> V;
	while (l<N){
		if (str[l]=='m'){
			l++;
			if (str[l]=='i'){
				T[c]=0;
			}
			if (str[l]=='a'){
				T[c]=1;
			}
			if (V.size()) adj[V.back()].push_back(c);
			V.push_back(c);
			c++;
			l++;
		}else if (str[l]=='?'){
			T[c]=2;
			if (V.size()) adj[V.back()].push_back(c);
			c++;
		}else if (str[l]==')') V.pop_back();
		l++;
	}
	N=c;
	auto [a,b]=dfs(0);
	cout<<b-a+1<<'\n';
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'std::pair<int, int> dfs(int)':
Main.cpp:27:1: warning: control reaches end of non-void function [-Wreturn-type]
   27 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...