제출 #972394

#제출 시각아이디문제언어결과실행 시간메모리
9723948pete8Homework (CEOI22_homework)C++17
53 / 100
67 ms116780 KiB
#include<iostream> #include<stack> #include<map> #include<vector> #include<string> #include<unordered_map> #include <queue> #include<cstring> #include<limits.h> #include <cassert> #include<cmath> #include<set> #include<algorithm> #include <iomanip> #include<numeric> //gcd(a,b) #include<bitset> #include <cstdlib> #include <cstdint> using namespace std; #define ll long long #define f first //#define endl "\n" #define s second #define pii pair<int,int> #define ppii pair<int,pii> #define vi vector<int> #define pb push_back #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define F(n) for(int i=0;i<n;i++) #define lb lower_bound #define ub upper_bound #define fastio ios::sync_with_stdio(false);cin.tie(NULL); #pragma GCC optimize ("03,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") using namespace std; #define int long long #define double long double const int mod=998244353,mxn=1e6+5,lg=60,inf=1e18,minf=-1e18,Mxn=1e6+50000; int sz[mxn+10]; int st[mxn+10],ed[mxn+10],type[mxn+10]; pii child[mxn+10]; string a; pii solve(int id){ if(a[id]=='?'){ sz[id]=1; return {1,1}; } pii vl,vr; vl=solve(child[id].f),sz[id]+=sz[child[id].f]; vr=solve(child[id].s),sz[id]+=sz[child[id].s]; pii re; if(type[id])re={min(vl.f,vr.f),vr.s+vl.s-1}; else re= {vl.f+vr.f,max(vl.s+sz[child[id].s],vr.s+sz[child[id].f])}; return re; } int32_t main(){ fastio cin>>a; if(a=="?")return cout<<1,0; stack<int>st; for(int i=0;i<a.size();i++)child[i]={-1,-1}; for(int i=0;i<a.size();i++){ sz[i]=0; if(a[i]=='('){ type[i]=(a[i-1]=='n'); st.push(i); } else if(a[i]==')'){ int x=st.top(); ed[x]=i; st.pop(); if(st.empty())continue; if(child[st.top()].f==-1)child[st.top()].f=x; else child[st.top()].s=x; } else if(a[i]=='?'){ if(child[st.top()].f==-1)child[st.top()].f=i; else child[st.top()].s=i; } } pii ans=solve(3); cout<<ans.s-ans.f+1; return 0; } /* keep range l,r->value thats optainable in subtree l being the min number of number < x needed to be used and r being the max merging-{ min node{ nl=min(l1,l2)-> push value of every node of the other subtree up nr=(r1+r2-1)->push 1 at the bottom of the other except 1 } max node{ nl=l1+l2->push 1 at bottom nr=r1+subsz2 or r2+subsz1 ->taking everything and shift it } } */

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

Main.cpp: In function 'int32_t main()':
Main.cpp:62:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |  for(int i=0;i<a.size();i++)child[i]={-1,-1};
      |              ~^~~~~~~~~
Main.cpp:63:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |  for(int i=0;i<a.size();i++){
      |              ~^~~~~~~~~
#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...