답안 #781163

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
781163 2023-07-12T20:10:31 Z Ozy Homework (CEOI22_homework) C++17
13 / 100
113 ms 118624 KB
#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;
};

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;
        nodos[cont].res = 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].tam = nodos[izq].tam + nodos[der].tam;
            nodos[act].res = nodos[izq].res + nodos[der].res - 1;

            lli a,b,c,d;

            a = b = 0;
            if(nodos[izq].tipo == 1) b = nodos[izq].tam - nodos[izq].res;
            else a = nodos[izq].tam - nodos[izq].res;

            c = d = 0;
            if(nodos[der].tipo == 1) d = nodos[der].tam - nodos[der].res;
            else c = nodos[der].tam - nodos[der].res;

            if (nodos[act].tipo == 1) nodos[act].res += a + c - min(a,c);
            else nodos[act].res += b + d - min(b,d);

            pos++;
        }

        cont++;
        pos += 2;
    }

    cout << nodos[1].res;

    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:36: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]
   36 |     while (pos < st.size()) {
      |            ~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 112088 KB Output is correct
2 Correct 105 ms 112068 KB Output is correct
3 Correct 113 ms 112072 KB Output is correct
4 Correct 113 ms 118544 KB Output is correct
5 Correct 107 ms 118568 KB Output is correct
6 Correct 111 ms 118592 KB Output is correct
7 Correct 106 ms 118576 KB Output is correct
8 Correct 104 ms 118624 KB Output is correct
9 Correct 104 ms 118584 KB Output is correct
10 Correct 108 ms 118556 KB Output is correct
11 Correct 106 ms 118596 KB Output is correct
12 Correct 108 ms 118616 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -