Submission #867174

#TimeUsernameProblemLanguageResultExecution timeMemory
867174PagodePaivaHomework (CEOI22_homework)C++17
53 / 100
1060 ms14228 KiB
#include<bits/stdc++.h> using namespace std; string s; 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; 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 = 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 a = solve(0, s.size()-1); int b = solve2(0, s.size()-1); int con = 0; for(int i = 0;i < s.size();i++){ if(s[i] == '?') con++; } b = con-b+1; cout << b-a+1 << '\n'; }

Compilation message (stderr)

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