답안 #754543

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
754543 2023-06-08T02:56:59 Z drdilyor Homework (CEOI22_homework) C++17
13 / 100
128 ms 107932 KB
#include <bits/stdc++.h>
#ifdef ONPC
    #include "t_debug.cpp"
#else
    #define debug(...) 42
#endif
using namespace std;
//namespace pbds = __gnu_pbds;
using ll = long long;
const int inf = 1e9;
const ll infl = 1e18;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.first >> p.second; }
template<typename Cont> int sz(const Cont& cont) { return int(cont.size()); }
template<typename Func> struct ycom { Func f; template<typename... T> auto operator()(T&&... args) { return f(*this, args...); } }; template<typename Func> ycom(Func) -> ycom<Func>;
template<typename T> typename vector<T>::iterator operator+(const vector<T>& x, int i) { return x.begin() + i ;};
const string fileio = "";
constexpr int tests = 0, nmax = 2e5, nlog = __lg(nmax), mod = 1e9+7;

int TQ = 0, TMIN = 1, TMAX = 2;
struct node {
    int type;
    node* l=nullptr; node* r=nullptr;
    void print() {
        if (type == TQ) cout << "?";
        else {
            if (type == TMIN) cout << "min(";
            else cout << "max(";
            l->print();
            cout << ",";
            r->print();
            cout << ")";
        }
    }
};

node* parse(string& s, int& i) {
    if (s[i++] == '?') return new node{TQ};
    auto res = new node;
    if (s[i++] == 'i') {
        res->type = TMIN;
    } else res->type = TMAX;
    i++;
    assert(s[i++] == '(');
    res->l = parse(s, i);
    assert(s[i++] == ',');
    res->r = parse(s, i);
    assert(s[i++] == ')');
    return res;
}

int solve() {
    string s;
    cin >> s;
    int i = 0;
    auto root = parse(s, i);
#ifdef ONPC
    root->print();
#endif
    int cnt=  0;
    int t = root->type;
    while (root) {
        if (root->type == t) {
            root = root->l->type == TQ ? root->r : root->l;
            cnt++;
        } else break;
    }
    cout << count(s.begin(), s.end(), '?') - cnt << '\n';
    return 0;
}

signed main() {
    int t = 1;
    #ifdef ONPC
    t = 10000;
    #else
    if (fileio.size()) {freopen((fileio+".in").c_str(),"r",stdin);freopen((fileio+".out").c_str(),"w",stdout);}
    #endif
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit | cin.eofbit);
    cout << fixed << setprecision(12);
    if (tests) cin >> t;
    while (t-- && cin) {
        if (solve()) break;
        #ifdef ONPC
            cout << "____________________" << endl;
        #endif
    }
    return 0;
}

/*
     █████               █████  ███  ████                               
    ▒▒███               ▒▒███  ▒▒▒  ▒▒███                               
  ███████  ████████   ███████  ████  ▒███  █████ ████  ██████  ████████ 
 ███▒▒███ ▒▒███▒▒███ ███▒▒███ ▒▒███  ▒███ ▒▒███ ▒███  ███▒▒███▒▒███▒▒███
▒███ ▒███  ▒███ ▒▒▒ ▒███ ▒███  ▒███  ▒███  ▒███ ▒███ ▒███ ▒███ ▒███ ▒▒▒ 
▒███ ▒███  ▒███     ▒███ ▒███  ▒███  ▒███  ▒███ ▒███ ▒███ ▒███ ▒███     
▒▒████████ █████    ▒▒████████ █████ █████ ▒▒███████ ▒▒██████  █████    
 ▒▒▒▒▒▒▒▒ ▒▒▒▒▒      ▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒   ▒▒▒▒▒███  ▒▒▒▒▒▒  ▒▒▒▒▒     
                                            ███ ▒███                    
                                           ▒▒██████                     
                                            ▒▒▒▒▒▒
*/

	

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:78:32: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |     if (fileio.size()) {freopen((fileio+".in").c_str(),"r",stdin);freopen((fileio+".out").c_str(),"w",stdout);}
      |                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:78:74: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |     if (fileio.size()) {freopen((fileio+".in").c_str(),"r",stdin);freopen((fileio+".out").c_str(),"w",stdout);}
      |                                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 101156 KB Output is correct
2 Correct 119 ms 107928 KB Output is correct
3 Correct 122 ms 107844 KB Output is correct
4 Correct 120 ms 107852 KB Output is correct
5 Correct 113 ms 107928 KB Output is correct
6 Correct 115 ms 107808 KB Output is correct
7 Correct 109 ms 107860 KB Output is correct
8 Correct 113 ms 107900 KB Output is correct
9 Correct 116 ms 107916 KB Output is correct
10 Correct 128 ms 107932 KB Output is correct
11 Correct 115 ms 107908 KB Output is correct
12 Correct 113 ms 107908 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -