Submission #647409

#TimeUsernameProblemLanguageResultExecution timeMemory
647409AlenygamZalmoxis (BOI18_zalmoxis)C++17
100 / 100
154 ms31568 KiB
#include <bits/stdc++.h> using namespace std; struct linkedListNode { int8_t val; linkedListNode *next = nullptr; bool splittable = false; }; linkedListNode preallocLinked[1000001]; int lastNodeLnkd = 0; inline linkedListNode* get_new_lnkd_node() { return &preallocLinked[lastNodeLnkd++]; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int N, K; cin >> N >> K; vector<int> values(N); for (auto &i: values) cin >> i; values.push_back(30); int size = 0; linkedListNode *head = get_new_lnkd_node(); linkedListNode *tail = head; stack<int8_t> stck; stck.push(30); for (int i = 0; i < N; i++) { while (stck.top() < values[i]) { tail->next = get_new_lnkd_node(); tail = tail->next; tail->val = stck.top(); tail->splittable = (stck.top() != 0); size++; stck.pop(); } while (stck.top() > values[i]) { int tmp = stck.top()-1; stck.pop(); stck.push(tmp); stck.push(tmp); } tail->next = get_new_lnkd_node(); tail = tail->next; tail->val = values[i]; tail->splittable = false; size++; stck.pop(); } while (stck.size()) { tail->next = get_new_lnkd_node(); tail = tail->next; tail->val = stck.top(); tail->splittable = true; size++; stck.pop(); } linkedListNode *hd = head->next; head = head->next; while (head != nullptr) { while (size < (N + K) && head->splittable) { linkedListNode *newNode = get_new_lnkd_node(); head->val = head->val - 1; head->splittable = (head->val != 0); newNode->val = head->val; newNode->next = head->next; newNode->splittable = (newNode->val != 0); head->next = newNode; size++; } head = head->next; } while (hd != nullptr) { cout << (int)hd->val << ' '; hd = hd->next; } cout << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...