답안 #725838

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
725838 2023-04-18T07:17:46 Z Baytoro Homework (CEOI22_homework) C++17
0 / 100
129 ms 132524 KB
#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define endl '\n'
#define ll long long
#define int long long
void fopn(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const ll INF=1e18,mod=1e9+9,N=1e6+5;
vector<int> g[N];
int t[N];
int dfs(int x, int c){
	if(t[x]!=c) return 0;
	for(auto it: g[x]){
		if(t[it]) return 1+dfs(it,c);
	}
	return 1;
}
void solve(){
	string s;cin>>s;int n=s.size(), m=0;
	stack<int> st;
	int cur=0;
	for(int i=0;i<n;i++){
		if(s[i]=='n'){
			cur++;
			if(!st.empty()){
				g[st.top()].pb(cur);
			}
			t[cur]=1;
			st.push(cur);
		}
		if(s[i]=='x'){
			cur++;
			if(!st.empty()){
				g[st.top()].pb(cur);
			}
			t[cur]=2;
			st.push(cur);
		}
		if(s[i]=='?'){
			cur++;m++;
			g[st.top()].pb(cur);
		}
		if(s[i]==')') st.pop();
	}
	cout<<m-max(dfs(1,1),dfs(1,2))<<endl;
}
main(){
	//fopn("team");
	ios;
	int T=1;
	//cin>>T;
	for(int i=1;i<=T;i++){
		//cout<<"Case #"<<i<<": ";
		solve();
	}
}

Compilation message

Main.cpp:55:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   55 | main(){
      | ^~~~
Main.cpp: In function 'void fopn(std::string)':
Main.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:14:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 23764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 23764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 129 ms 132524 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 23764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 23764 KB Output isn't correct
2 Halted 0 ms 0 KB -