Submission #867175

#TimeUsernameProblemLanguageResultExecution timeMemory
867175PagodePaivaHomework (CEOI22_homework)C++17
53 / 100
1014 ms54152 KiB
#include<bits/stdc++.h> using namespace std; string s; map <int, int> virgulas; int solve(int l, int r){ if(l == r){ return 1; } int con = 0; int mid; for(int i = l+4;i <= r;i++){ if(s[i] == '(') con++; else if(s[i] == ')') con--; if(con == 0 and s[i] == ','){ mid = i; break; } } int a = solve(l+4, mid-1); int b = solve(mid+1, r-1); if(s[l+1] == 'i'){ return min(a, b); } return a+b; } int solve2(int l, int r){ // cout << l << ' ' << r << '\n'; if(l == r){ return 1; } int con = 0; int mid = virgulas[l]; int a = solve2(l+4, mid-1); int b = solve2(mid+1, r-1); if(s[l+1] == 'a'){ return min(a, b); } return a+b; } int main(){ cin >> s; int con = 0; stack <int> q; for(int i = 0;i < s.size();i++){ if(s[i] == '?') con++; if(s[i] == 'm') q.push(i); if(s[i] == ')') q.pop(); if(s[i] == ',') virgulas[q.top()] = i; } int a = solve(0, s.size()-1); int b = solve2(0, s.size()-1); b = con-b+1; cout << b-a+1 << '\n'; }

Compilation message (stderr)

Main.cpp: In function 'int solve2(int, int)':
Main.cpp:42:9: warning: unused variable 'con' [-Wunused-variable]
   42 |     int con = 0;
      |         ^~~
Main.cpp: In function 'int main()':
Main.cpp:61:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for(int i = 0;i < s.size();i++){
      |                   ~~^~~~~~~~~~
Main.cpp: In function 'int solve(int, int)':
Main.cpp:27:18: warning: 'mid' may be used uninitialized in this function [-Wmaybe-uninitialized]
   27 |     int b = solve(mid+1, r-1);
      |             ~~~~~^~~~~~~~~~~~
#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...