Submission #443551

#TimeUsernameProblemLanguageResultExecution timeMemory
443551penguinhackerKvalitetni (COCI16_kvalitetni)C++14
120 / 120
9 ms1240 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array int n, z[50], si; string s; double solve() { assert(s[si++]=='('); if (s[si]=='?') { si+=2; return z[0]; } vector<double> v; char op='-'; while(1) { v.push_back(solve()); char cur=s[si++]; if (cur==')') break; op=cur; } assert(v.size()>=2&&op=='+'||op=='*'); if (op=='+') return min((double)z[v.size()-1], accumulate(v.begin(), v.end(), 0.0)); double lb=0, rb=z[v.size()-1]; for (int k=0; k<40; ++k) { double mid=(lb+rb)/2; double sum=0; for (double i : v) sum+=min(i, mid); if (sum<=z[v.size()-1]) lb=mid; else rb=mid; } double p=1; for (double i : v) p*=min(i, lb); return p; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i=0; i<n; ++i) cin >> z[i]; cin >> s; cout << fixed << setprecision(3) << solve(); return 0; }

Compilation message (stderr)

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from kvalitetni.cpp:1:
kvalitetni.cpp: In function 'double solve()':
kvalitetni.cpp:25:20: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   25 |  assert(v.size()>=2&&op=='+'||op=='*');
      |         ~~~~~~~~~~~^~~~~~~~~
#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...
#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...