Rezultati

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

Test Točke Porabljen spomin Porabljen čas Status
#1 9/9 2,641 MiB 0,004 s OK
#2 9/9 2,672 MiB 0,004 s OK
#3 9/9 2,672 MiB 0,004 s OK
#4 9/9 2,637 MiB 0,004 s OK
#5 9/9 2,676 MiB 0,004 s OK
#6 9/9 2,652 MiB 0,004 s OK
#7 9/9 2,680 MiB 0,004 s OK
#8 9/9 2,680 MiB 0,004 s OK
#9 9/9 2,648 MiB 0,004 s OK
#10 9/9 2,652 MiB 0,004 s OK
#11 10/10 2,652 MiB 0,004 s OK

Ocenjevani program (jungle.cpp):
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <queue>
#include <deque>
#include <vector>

typedef std::deque<int> int_deque_t;

int N = 0, M = 0;
char B[8192];
std::vector<int_deque_t> s_hands;
std::vector<int_deque_t> s_table;

int main() {
    scanf("%d ", &N);
    s_hands.resize(N);
    s_table.resize(N);
    gets(B);
    char *dp = strtok(B, " \n");
    while (dp != NULL) {
        int pi = (M++ % N);
        s_hands[pi].push_front(atoi(dp));
        dp = strtok(NULL, " \n");
    }
    int pi = 0;
    while (true) {
        int_deque_t *ph = &s_hands[pi];
        int_deque_t *pt = &s_table[pi];
        if (ph->empty()) {
            while (!pt->empty()) {
                ph->push_front(pt->front());
                pt->pop_front();
            }
        }
        int cc = ph->front();
        ph->pop_front();
        pt->push_front(cc);
        int ci = -1;
        for (unsigned int i = 0; i < s_table.size(); i++) {
            if (i == pi) continue;
            if (!s_table[i].empty() && s_table[i].front() == cc) {
                ci = i;
                break;
            }
        }
        if (ci == -1) {
            pi = (pi + 1) % N;
            continue;
        }
        int_deque_t *ot = &s_table[ci];
        while (!ot->empty()) {
            ph->push_back(ot->back());
            ot->pop_back();
        }
        while (!pt->empty()) {
            ph->push_back(pt->back());
            pt->pop_back();
        }
        if (s_hands[ci].empty()) {
            printf("%d\n", ci + 1);
            break;
        }
    }
    return 0;
}