제출 #830394

#제출 시각아이디문제언어결과실행 시간메모리
830394petezaHomework (CEOI22_homework)C++14
53 / 100
147 ms54312 KiB
#include <bits/stdc++.h>
using namespace std;

string str;
int bin[1000005][2];
int type[1000005], sz[1000005];
int cnode = 0;
stack<int> stk;
pair<int, int> dp[1000005];

int main() {
    cin >> str; 
    for(int i=0;i<str.size();) {
        if(str[i] == ',' || str[i]=='('){i++; continue;}
        if(str[i] == 'm') {
            stk.push(cnode);
            if(str[i+1] == 'i') { //minimum
                type[cnode++] = 0;
            } else {
                type[cnode++] = 1;
            }
            i += 4;
        } else if(str[i] == '?') {
            stk.push(cnode); sz[cnode] = 1;
            dp[cnode] = {1, 1};
            type[cnode++] = 2;
            i++;
        } else {
            int e1 = stk.top(); stk.pop();
            int e2 = stk.top(); stk.pop();
            bin[stk.top()][0] = e2; bin[stk.top()][1] = e1;
            sz[stk.top()] = sz[e1] + sz[e2];
            int x = stk.top();
            if(type[x] == 0) {
                auto r1 = dp[bin[x][0]], r2 = dp[bin[x][1]];
                dp[x] = {min(r1.first, r2.first), sz[x]+1-(sz[bin[x][0]]+sz[bin[x][1]]-r1.second-r2.second+2)};
            } else {
                auto r1 = dp[bin[x][0]], r2 = dp[bin[x][1]];
                dp[x] = {r1.first + r2.first, sz[x]-min(sz[bin[x][0]]-r1.second, sz[bin[x][1]]-r2.second)};
            }
            i++;
        }
    }
    cout << dp[0].second-dp[0].first+1;
}

// min(max(max(?,?),max(?,?)),min(max(?,?),max(?,?)))

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:13:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for(int i=0;i<str.size();) {
      |                 ~^~~~~~~~~~~
#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...