// mugs.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include #include #include using namespace std; int const bc = 't' - 'a' + 1; struct Node { Node* par_ = nullptr; Node* l_son_ = nullptr; Node* r_son_ = nullptr; vector counts_; int subtr_s_; Node(Node* ls, Node* rs) { counts_.resize(bc); for (int i = 0; i < bc; i++) { counts_[i] = ls->counts_[i] + rs->counts_[i]; } l_son_ = ls; r_son_ = rs; l_son_->par_ = this; r_son_->par_ = this; subtr_s_ = l_son_->subtr_s_ + r_son_->subtr_s_; } Node(int b) { counts_.resize(bc); counts_[b] = 1; subtr_s_ = 1; } }; bool are_valid(Node* n1, Node* n2) { } int main() { int N; cin >> N; vector D(N); char ch; queue* nds = new queue(); for (int i = 0; i < N; i++) { cin >> ch; D[i] = ch - 'a'; Node* nd = new Node(ch - 'a'); nds->push(nd); } Node* root = nullptr; queue* ndsn = new queue(); while (true) { while (nds->size() > 0) { Node* s1 = nds->front(); nds->pop(); Node* s2 = nullptr; if (nds->size() > 0) { s2 = nds->front(); nds->pop(); } Node* par = nullptr; if (s2 != nullptr) par = new Node(s1, s2); else par = s1; ndsn->push(par); } if (ndsn->size() == 1) { root = ndsn->front(); break; } queue* tmp = nds; nds = ndsn; ndsn = tmp; } int max_sz = 0; } // Run program: Ctrl + F5 or Debug > Start Without Debugging menu // Debug program: F5 or Debug > Start Debugging menu // Tips for Getting Started: // 1. Use the Solution Explorer window to add/manage files // 2. Use the Team Explorer window to connect to source control // 3. Use the Output window to see build output and other messages // 4. Use the Error List window to view errors // 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project // 6. In the future, to open this project again, go to File > Open > Project and select the .sln file