#include <bits/stdc++.h>
using namespace std;
struct linkedListNode {
int8_t val;
linkedListNode *next = nullptr;
bool inserted = false;
};
linkedListNode preallocLinked[1000001];
int lastNodeLnkd = 0;
static 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);
linkedListNode *head = get_new_lnkd_node();
linkedListNode *tail = head;
stack<int> 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->inserted = true;
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->inserted = false;
stck.pop();
}
while (stck.size()) {
tail->next = get_new_lnkd_node();
tail = tail->next;
tail->val = stck.top();
tail->inserted = true;
stck.pop();
}
head = head->next;
while (head != nullptr) {
cout << (int)head->val << ' ';
head = head->next;
}
cout << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
140 ms |
32944 KB |
Output is correct |
2 |
Correct |
137 ms |
32944 KB |
Output is correct |
3 |
Correct |
145 ms |
33008 KB |
Output is correct |
4 |
Correct |
139 ms |
33040 KB |
Output is correct |
5 |
Correct |
150 ms |
32936 KB |
Output is correct |
6 |
Correct |
138 ms |
32896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
145 ms |
33036 KB |
Unexpected end of file - int32 expected |
2 |
Correct |
143 ms |
32940 KB |
Output is correct |
3 |
Incorrect |
190 ms |
32900 KB |
Unexpected end of file - int32 expected |
4 |
Incorrect |
148 ms |
32984 KB |
Unexpected end of file - int32 expected |
5 |
Incorrect |
155 ms |
33012 KB |
Unexpected end of file - int32 expected |
6 |
Incorrect |
147 ms |
32984 KB |
Unexpected end of file - int32 expected |
7 |
Incorrect |
141 ms |
32992 KB |
Unexpected end of file - int32 expected |
8 |
Incorrect |
149 ms |
33028 KB |
Unexpected end of file - int32 expected |
9 |
Incorrect |
137 ms |
30364 KB |
Unexpected end of file - int32 expected |
10 |
Incorrect |
63 ms |
26764 KB |
Unexpected end of file - int32 expected |
11 |
Incorrect |
111 ms |
28236 KB |
Unexpected end of file - int32 expected |
12 |
Incorrect |
10 ms |
23764 KB |
Unexpected end of file - int32 expected |
13 |
Incorrect |
11 ms |
23764 KB |
Unexpected end of file - int32 expected |
14 |
Incorrect |
10 ms |
23764 KB |
Unexpected end of file - int32 expected |