結果
| 問題 |
No.2738 CPC To F
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-20 15:49:42 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,244 bytes |
| コンパイル時間 | 1,687 ms |
| コンパイル使用メモリ | 169,860 KB |
| 実行使用メモリ | 18,816 KB |
| 最終ジャッジ日時 | 2024-10-12 11:32:15 |
| 合計ジャッジ時間 | 6,085 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 2 |
| other | RE * 22 |
ソースコード
#define DEBUG
#include <bits/stdc++.h>
using namespace std;
struct linkedList{
struct node{
int data;
node* next;
node* prev;
};
node* head;
node* tail;
int size;
public:
linkedList(){
head = NULL;
tail = NULL;
size = 0;
}
void insert(int data){
node* newNode = new node;
newNode->data = data;
newNode->next = NULL;
newNode->prev = NULL;
if(head == NULL){
head = newNode;
tail = newNode;
}else{
tail->next = newNode;
newNode->prev = tail;
tail = newNode;
}
size += 1;
}
void remove(node* nodeToRemove){
if(nodeToRemove == NULL){
return;
}
if(nodeToRemove == head){
head = head->next;
if(head != NULL){
head->prev = NULL;
}
}else if(nodeToRemove == tail){
tail = tail->prev;
if(tail != NULL){
tail->next = NULL;
}
}else{
nodeToRemove->prev->next = nodeToRemove->next;
nodeToRemove->next->prev = nodeToRemove->prev;
}
delete nodeToRemove;
size -= 1;
}
void print(){
node* current = head;
while(current != NULL){
cout << current->data << " ";
current = current->next;
}
cout << endl;
}
};
linkedList::node* getAvailableMin(linkedList* p){
linkedList::node* current = p->head;
linkedList::node* min = current;
while(current != p->tail){
if(current->data < min->data){
min = current;
}
current = current->next;
}
return min;
}
int main(){
int N;
cin >> N;
linkedList p;
vector<int> q;
for(int i = 0; i < N; i++){
int x;
cin >> x;
p.insert(x);
}
while(p.size > 0){
linkedList::node* min = getAvailableMin(&p);
q.push_back(min->data);
q.push_back(min->next->data);
p.remove(min);
p.remove(min->next);
}
for(int i = 0; i < q.size(); i++){
cout << q[i] << " ";
}
return 0;
}