Submission #990621

# Submission time Handle Problem Language Result Execution time Memory
990621 2024-05-30T17:43:19 Z AlphaMale06 Homework (CEOI22_homework) C++17
0 / 100
126 ms 131532 KB
#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second

const int N = 1e6;
string s;
int n;
vector<int> to[N];

pair<int, int> buildtree(int l, int r, int d){
    if(l==r)return {1, n};
    pair<int, int> ans1;
    pair<int, int> ans2;
    int pos = to[d].back();
    to[d].pop_back();
    ans1 = buildtree(l+4, pos-1, d+1);
    ans2 = buildtree(pos+1, r-1, d+1);
    if(s[l+2]=='x'){
        pair<int, int> ret;
        ret.S = max(ans1.S, ans2.S);
        ret.F = max(ans1.F, ans2.F);
        if(ans1.F==ans2.F)ret.F++;
        return ret;
    }
    else{
        pair<int, int> ret;
        ret.S = min(ans1.S, ans2.S);
        ret.F = min(ans1.F, ans2.F);
        if(ans1.S==ans2.S)ret.S--;
        return ret;
    }
}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> s;
    int cnto=0;
    for(int i=0; i< s.size(); i++){
        char c = s[i];
        if(c=='?')n++;
        if(c=='(')cnto++;
        if(c==')')cnto--;
        if(c==',')to[cnto-1].push_back(i);
    }
    for(int i=0; i<10; i++){
        reverse(to[i].begin(), to[i].end());
    }
    pair<int, int> ans = buildtree(0, s.size()-1, 0);
    cout << ans.S-ans.F << '\n';
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:44:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for(int i=0; i< s.size(); i++){
      |                  ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 23900 KB Output is correct
2 Incorrect 4 ms 23900 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 23900 KB Output is correct
2 Incorrect 4 ms 23900 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 126 ms 131532 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 23900 KB Output is correct
2 Incorrect 4 ms 23900 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 23900 KB Output is correct
2 Incorrect 4 ms 23900 KB Output isn't correct
3 Halted 0 ms 0 KB -