Submission #781306

#TimeUsernameProblemLanguageResultExecution timeMemory
781306OzyHomework (CEOI22_homework)C++17
100 / 100
172 ms151168 KiB
#include <iostream> #include <bits/stdc++.h> using namespace std; #define lli long long int #define debug(a) cout << #a << " = " << a << endl #define debugsl(a) cout << #a << " = " << a << ", " #define rep(i,a,b) for(int i = (a); i <= (b); i++) #define repa(i,a,b) for(int i = (a); i >= (b); i--) #define pll pair<lli,lli> struct x { lli tipo; lli h[2]; lli apu; lli res; lli tam[2]; lli glob; }; string st; lli pos,cont,a; stack<lli> pila; vector<x> nodos; x trash; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> st; pos = 0; cont = 1; nodos.push_back(trash); pila.push(0); while (pos < st.size()) { //debugsl(pos); //debug(st[pos]); a = nodos[ pila.top() ].apu++; nodos[ pila.top() ].h[a] = cont; nodos.push_back(trash); pila.push(cont); if(st[pos] == 'm') { if (st[pos+1] == 'i') nodos[cont].tipo = 1; else nodos[cont].tipo = 2; cont++; pos += 4; continue; } nodos[cont].tam[1] = 0; nodos[cont].tam[0] = 0; nodos[cont].res = 1; nodos[cont].glob = 1; pila.pop(); while (nodos[pila.top()].apu == 2) { lli act = pila.top(); pila.pop(); lli izq = nodos[act].h[0]; lli der = nodos[act].h[1]; nodos[act].glob = nodos[izq].glob + nodos[der].glob; if (nodos[act].tipo == 1) { //es un min(izq,der) nodos[act].tam[0] = min(nodos[izq].tam[0], nodos[der].tam[0]); nodos[act].res = ( nodos[izq].tam[0] + nodos[der].tam[0] + nodos[izq].res + nodos[der].res - 1 ) - nodos[act].tam[0]; nodos[act].tam[1] = nodos[act].glob - nodos[act].res - nodos[act].tam[0]; } else { //es un max(izq,der) nodos[act].tam[1] = min(nodos[izq].tam[1], nodos[der].tam[1]); nodos[act].res = ( nodos[izq].tam[1] + nodos[der].tam[1] + nodos[izq].res + nodos[der].res - 1 ) - nodos[act].tam[1]; nodos[act].tam[0] = nodos[act].glob - nodos[act].res - nodos[act].tam[1]; } //debugsl(nodos[act].tam[0]); //debugsl(nodos[act].res); //debug(nodos[act].tam[1]); pos++; } cont++; pos += 2; } cout << nodos[1].res; return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:37:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     while (pos < st.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...