Rezultati

Up. imeNalogaJezikRezultatČas oddaje
pspace-2017 Jungle Speed C++ 100/100OK 11. maj '17 @ 19:19

Test Točke Porabljen spomin Porabljen čas Status
#1 9/9 3,352 MiB 0,004 s OK
#2 9/9 3,352 MiB 0,004 s OK
#3 9/9 3,383 MiB 0,004 s OK
#4 9/9 3,383 MiB 0,004 s OK
#5 9/9 3,355 MiB 0,004 s OK
#6 9/9 3,367 MiB 0,004 s OK
#7 9/9 3,352 MiB 0,004 s OK
#8 9/9 3,363 MiB 0,004 s OK
#9 9/9 3,363 MiB 0,004 s OK
#10 9/9 3,363 MiB 0,004 s OK
#11 10/10 3,359 MiB 0,004 s OK

Ocenjevani program (main.cpp):
#include <bits/stdc++.h>

using namespace std;

int n, m;
vector<int> cards;

deque<int> back_deck[72], used_deck[72];

int main() {
    //freopen("in.txt", "r", stdin);

    scanf("%d", &n);
    int card;

    while (scanf("%d", &card) != EOF) {
        cards.push_back(card);
    }

    m = cards.size();

    for (int i = 0; i < m; i++) {
        int card = cards[i];
        back_deck[i % n].push_back(card);
    }

    int current_player = 0;
    int delta = 0;

    while (true) {
        delta = 0;
        if (back_deck[current_player].empty()) {
            back_deck[current_player].assign(used_deck[current_player].rbegin(), used_deck[current_player].rend());
            used_deck[current_player].clear();
        }

        int card = back_deck[current_player].back();
        back_deck[current_player].pop_back();
        used_deck[current_player].push_back(card);

        for (int other_decks = 0; other_decks < n; other_decks++) {
            if (current_player == other_decks || used_deck[other_decks].empty()) continue;

            if (used_deck[current_player].back() == used_deck[other_decks].back()) {
                used_deck[current_player].insert(used_deck[current_player].begin(), used_deck[other_decks].begin(),
                                                 used_deck[other_decks].end());
                used_deck[other_decks].clear();
                if(back_deck[other_decks].empty() && used_deck[other_decks].empty()) {
                    printf("%d\n", other_decks + 1);
                    return 0;
                }

                back_deck[current_player].insert(back_deck[current_player].begin(), used_deck[current_player].rbegin(),
                                                 used_deck[current_player].rend());
                used_deck[current_player].clear();

                delta = -1;
                break;
            }
        }

        if(back_deck[current_player].empty() && used_deck[current_player].empty()) {
            printf("%d\n", current_player + 1);
            return 0;
        }

        current_player = (current_player + 1 + delta) % n;
    }

    return 0;
}