Submission #972349

#TimeUsernameProblemLanguageResultExecution timeMemory
9723498pete8Homework (CEOI22_homework)C++17
10 / 100
1043 ms22508 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=50*50+5,lg=60,inf=1e18,minf=-1e18,Mxn=1e6+50000; int sz[mxn+10]; pii solve(string cur,int id){ if(cur=="?"){ sz[id]=1; return {1,1}; } string l="",r=""; int cnt=0; pii vl,vr; for(int i=4;i<cur.size()-1;i++){ if(cnt==inf){ r=(r+cur[i]); continue; } if(cur[i]=='(')cnt++; else if(cur[i]==')')cnt--; else if(cur[i]==','&&cnt==0)vl=solve(l,id*2),cnt=inf; l=(l+cur[i]); } vr=solve(r,id*2+1); sz[id]=sz[id*2]+sz[id*2+1]; pii re; if(cur[1]=='i')re={min(vl.f,vr.f),vr.s+vl.s-1}; else re= {vl.f+vr.f,max(vl.s+sz[id*2+1],vr.s+sz[id*2])}; return re; } int32_t main(){ fastio string a;cin>>a; pii ans=solve(a,1); 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 } } */

Compilation message (stderr)

Main.cpp: In function 'std::pair<long long int, long long int> solve(std::string, long long int)':
Main.cpp:49: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]
   49 |  for(int i=4;i<cur.size()-1;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...