Test |
Točke |
Porabljen spomin |
Porabljen čas |
Status |
#1
|
16/16 |
3,043 MiB |
0,000 s |
OK |
#2
|
16/16 |
3,191 MiB |
0,000 s |
OK |
#3
|
17/17 |
3,039 MiB |
0,000 s |
OK |
#4
|
17/17 |
4,402 MiB |
0,568 s |
OK |
#5
|
17/17 |
27,457 MiB |
0,000 s |
OK |
#6
|
17/17 |
3,125 MiB |
0,004 s |
OK |
Ocenjevani program (prehitevanje.cpp):
#include <iostream>
#include <map>
struct item {
struct item *prev;
struct item *next;
std::string name;
};
static struct item H = { &H, &H, "" };
static std::map<std::string, item> M;
static void ll_insert(struct item *node, struct item *pivot) {
node->prev = pivot->prev;
node->next = pivot;
pivot->prev->next = node;
pivot->prev = node;
}
static void ll_remove(struct item *node) {
node->prev->next = node->next;
node->next->prev = node->prev;
}
int main() {
int n = 0;
std::cin >> n;
while ((n--) > 0) {
std::string name;
std::cin >> name;
struct item *item = &M[name];
ll_insert(item, &H);
item->name = name;
}
std::cin >> n;
while ((n--) > 0) {
std::string xn, yn;
std::cin >> xn;
std::cin >> yn;
ll_remove(&M[xn]);
ll_insert(&M[xn], &M[yn]);
}
struct item *it = H.next;
while (it != &H) {
std::cout << it->name << std::endl;
it = it->next;
}
return 0;
}