Rezultati

Up. imeNalogaJezikRezultatČas oddaje
ayy-2018 Birokrati C++ 0/100Napaka med izvajanjem / ob izhodu (RTE) 04. okt '18 @ 18:15

Test Točke Porabljen spomin Porabljen čas Status
#1 9/9 3,285 MiB 0,010 s OK
#2 9/9 3,070 MiB 0,004 s OK
#3 9/9 3,289 MiB 0,000 s OK
#4 9/9 3,277 MiB 0,000 s OK
#5 0/9 3,031 MiB 0,004 s Napaka med izvajanjem / ob izhodu
#6 9/9 4,016 MiB 0,004 s OK
#7 9/9 5,621 MiB 0,027 s OK
#8 9/9 7,461 MiB 0,052 s OK
#9 0/9 7,500 MiB 0,058 s Napačen odgovor
Tvoj izhod:
​/dzxfm<<<EOF>>>
Pravilen izhod:
​/fcnie/khbpp/pcava/lnmlz
<<<EOF>>>
#10 0/9 33,813 MiB 0,265 s Napačen odgovor
Tvoj izhod:
​/k<<<EOF>>>
Pravilen izhod:
​/o/x/m
<<<EOF>>>
#11 10/10 3,094 MiB 0,000 s OK

Ocenjevani program (birokrati.cpp):
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>

using namespace std;

struct temporary {
	string person;
	string accusee;
	
	bool operator < (const temporary& tmp) const {
        return (person < tmp.person);
    }
};

struct birokrat {
	string id;
	string realId;
	bool visited;
	vector<int> obtozba;
};

struct oddelek {
	string ime;
	vector<birokrat> birokrati;
	vector<oddelek> pododdelki;
	vector<string> priprava;
	vector<string> obtozbe;
	vector<string> people;
	
	int dodajPododdelek(string ime) {
		for (int i = 0; i < pododdelki.size(); i++) {
			if (pododdelki[i].ime == ime) {
				return i;
			}
		}
		
		oddelek o;
		o.ime = ime;
		pododdelki.push_back(o);
		return pododdelki.size() - 1;
	}
};


void recursive(oddelek& O) {
	for (int i = 0; i < O.priprava.size(); i++) {
		string temp = O.priprava[i].substr(1, O.priprava[i].size());
		size_t index = temp.find("/");
		
		if (index == string::npos) {
			birokrat b;
			b.visited = false;
			b.id = O.priprava[i];
			b.realId = O.people[i];
			
			stringstream ss(O.obtozbe[i]);
			string str;
			
			while (getline(ss, str, '.')) {
				stringstream sss(str);
				int x;
				sss >> x;
				b.obtozba.push_back(x);
			}
			
			O.birokrati.push_back(b);
		} else {
			int p = O.dodajPododdelek(temp.substr(0, index));
			
			O.pododdelki[p].priprava.push_back(temp.substr(index));
			O.pododdelki[p].obtozbe.push_back(O.obtozbe[i]);
			O.pododdelki[p].people.push_back(O.people[i]);
		}
	}
	
	for (int i = 0; i < O.pododdelki.size(); i++) {
		recursive(O.pododdelki[i]);
	}
}



int main() {
	string id, acc;
	vector<string> people, accused;
	vector<temporary> tmpStruct;
	
	while (cin >> id >> acc) {
		temporary tmp;
		tmp.person = id;
		tmp.accusee = acc;
		tmpStruct.push_back(tmp);
	}
	
	
	
	sort(tmpStruct.begin(), tmpStruct.end());
	
	for (int i = 0; i < tmpStruct.size(); i++) {
		people.push_back(tmpStruct[i].person);
		accused.push_back(tmpStruct[i].accusee);
	}
	
	oddelek O;
	
	O.priprava = people;
	O.people = people;
	O.obtozbe = accused;	
	recursive(O);
	
	oddelek odd = O;
	
	while (odd.birokrati.size() == 0) {
		odd = odd.pododdelki[0];
	}
	
	birokrat *b = &(odd.birokrati[0]);
	oddelek *od = &O;
	
	while (1) {
		b->visited = true;
		vector<int> ob = b->obtozba;
		
		int i;
		for (i = 0; i < ob.size() - 1; i++) {
			if (ob[i] - 1 >= od->pododdelki.size()) {
				cout << b->realId;
				return 0;
			}
			
			od = &(od->pododdelki[ob[i] - 1]);
		}
		
		if (ob[i] - 1 >= od->birokrati.size()) {
			cout << b->realId;
			return 0;
		} else if (od->birokrati[ob[i] - 1].visited) {
			cout << b->realId;
			return 0;
		}
		
		b = &(od->birokrati[ob[i] - 1]);
		od = &O;
	}
	
	return 0;
}