Submission #824406

#TimeUsernameProblemLanguageResultExecution timeMemory
824406kwongwengHomework (CEOI22_homework)C++17
66 / 100
97 ms79664 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef long double ld; typedef pair<ll, ll> pll; #define FOR(i, a, b) for(int i = a; i < b; i++) #define ROF(i, a, b) for(int i = a; i >= b; i--) #define ms memset #define pb push_back #define fi first #define se second string s; int nxt[6000000]; /*corresponding , to each (), to split the expression into two Main obs : all reachable values fall within a continuous interval range returns 2 values {A,B} A -> A smallest values cannot be reached B -> B largest values cannot be reached */ ii range(int L, int R){ if (L==R) return {0,0}; // ? ii val1 = range(L+4,nxt[L+3]-1); ii val2 = range(nxt[L+3]+1,R-1); if (s[L+2]=='x'){ //max return {val1.fi+val2.fi+1, min(val1.se, val2.se)}; } //min return {min(val1.fi, val2.fi), val1.se+val2.se+1}; } void solve(){ cin>>s; int len=s.size(); ms(nxt,-1,sizeof(nxt)); stack<int> st; int cnt=0; FOR(i,0,len){ if (s[i]=='(') st.push(i); if (s[i]==','){nxt[st.top()]=i; st.pop();} if (s[i]=='?') cnt++; } ii ans = range(0,len-1); cout<<cnt-ans.fi-ans.se<<'\n'; } int main(){ //MOD=MOD1; ios::sync_with_stdio(false); if (fopen("input.txt", "r")) { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } int TC = 1; //cin >> TC; FOR(i, 1, TC+1){ //cout << "Case #" << i << ": "; solve(); } return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:53:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:54:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |      freopen("output.txt", "w", stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...