Rezultati

Up. imeNalogaJezikRezultatČas oddaje
ayy-2018 Droni C++ 0/100Prekoračen čas (TLE) 10. maj '18 @ 19:53

Test Točke Porabljen spomin Porabljen čas Status
#1 5/5 3,168 MiB 0,000 s OK
Povratna informacija sodniškega sistema:
​The output was correct.
#2 5/5 3,035 MiB 0,004 s OK
Povratna informacija sodniškega sistema:
​The output was correct.
#3 5/5 3,035 MiB 0,000 s OK
Povratna informacija sodniškega sistema:
​The output was correct.
#4 5/5 3,168 MiB 0,000 s OK
Povratna informacija sodniškega sistema:
​The output was correct.
#5 5/5 3,039 MiB 0,000 s OK
Povratna informacija sodniškega sistema:
​The output was correct.
#6 5/5 3,168 MiB 0,000 s OK
Povratna informacija sodniškega sistema:
​The output was correct.
#7 5/5 3,039 MiB 0,003 s OK
Povratna informacija sodniškega sistema:
​The output was correct.
#8 5/5 3,039 MiB 0,004 s OK
Povratna informacija sodniškega sistema:
​The output was correct.
#9 5/5 3,039 MiB 0,000 s OK
Povratna informacija sodniškega sistema:
​The output was correct.
#10 5/5 3,039 MiB 0,000 s OK
Povratna informacija sodniškega sistema:
​The output was correct.
#11 5/5 3,039 MiB 0,000 s OK
Povratna informacija sodniškega sistema:
​The output was correct.
#12 5/5 3,035 MiB 0,004 s OK
Povratna informacija sodniškega sistema:
​The output was correct.
#13 5/5 3,035 MiB 0,000 s OK
Povratna informacija sodniškega sistema:
​The output was correct.
#14 5/5 3,035 MiB 0,004 s OK
Povratna informacija sodniškega sistema:
​The output was correct.
#15 5/5 3,172 MiB 0,004 s OK
Povratna informacija sodniškega sistema:
​The output was correct.
#16 5/5 3,039 MiB 0,000 s OK
Povratna informacija sodniškega sistema:
​The output was correct.
#17 5/5 3,039 MiB 0,004 s OK
Povratna informacija sodniškega sistema:
​The output was correct.
#18 5/5 3,172 MiB 0,004 s OK
Povratna informacija sodniškega sistema:
​The output was correct.
#19 0/5 2,844 MiB 0,000 s Prekoračen čas
Povratna informacija sodniškega sistema:
​The program made an invalid move.
#20 5/5 3,168 MiB 0,004 s OK
Povratna informacija sodniškega sistema:
​The output was correct.

Ocenjevani program (dron.cpp):
#include <iostream>
#include <cmath>
#include <sstream>

using namespace std;

struct point {
	int x, y, z;
};

struct drone {
	point start, end, current;
	int distance;
	
	void calcDistance() {
		distance = abs(end.x - start.x) + abs(end.y - start.y) + abs(end.z - start.z);
		current = start;
	}
	
	string toString() {
		stringstream ss;
		ss << "(" << current.x << " " << current.y << " " << current.z << ")";
		return ss.str();
	}
};

point psub(point &p1, point &p2) {
	point p;
	p.x = p2.x - p1.x;
	p.y = p2.y - p1.y;
	p.z = p2.z - p1.z;
	return p;
}

point pabs(point p) {
	p.x = abs(p.x);
	p.y = abs(p.y);
	p.z = abs(p.z);
	return p;
}

bool pcmp(point &p1, point &p2) {
	return p1.x == p2.x && p1.y == p2.y && p1.z == p2.z;
}

int main() {
	drone d1, d2;
	
	cin >> d1.start.x >> d1.start.y >> d1.start.z >> d1.end.x >> d1.end.y >> d1.end.z;
	cin >> d2.start.x >> d2.start.y >> d2.start.z >> d2.end.x >> d2.end.y >> d2.end.z;
	d1.calcDistance();
	d2.calcDistance();
	
	cout << d1.toString() << " " << d2.toString() << endl;
	
	if (pcmp(d1.current, d1.end) && pcmp(d2.current, d2.end)) {
		return 1; // I WANT TO BREAK FREE
	}
	
	while(1) {
		point raz1 = psub(d1.end, d1.current);
		point razabs1 = pabs(raz1);
		
		point newp1 = d1.current;
		int direction1 = -1;
		
		if (!(raz1.x == 0 && raz1.y == 0 && raz1.z == 0)) {
			// TODO: probably a bug which point was substracted from which
			if (razabs1.x >= razabs1.y && razabs1.x >= razabs1.z) {
				newp1.x = raz1.x < 0 ? newp1.x + 1 : newp1.x - 1;
				direction1 = 0;
			} else if (razabs1.y >= razabs1.x && razabs1.y >= razabs1.z) {
				newp1.y = raz1.y < 0 ? newp1.y + 1 : newp1.y - 1;
				direction1 = 1;
			} else {
				newp1.z = raz1.z < 0 ? newp1.z + 1 : newp1.z - 1;
				direction1 = 2;
			}
		}
		
		point raz2 = psub(d2.end, d2.current);
		point razabs2 = pabs(raz2);
		//cout << "x: " << raz2.x << " y: " << raz2.y << " z: " << raz2.z << endl;
		
		point newp2 = d2.current;
		int direction2 = -1;
		
		if (!(raz2.x == 0 && raz2.y == 0 && raz2.z == 0)) {
			// TODO: probably a bug which point was substracted from which
			if (razabs2.x >= razabs2.y && razabs2.x >= razabs2.z) {
				newp2.x = raz2.x < 0 ? newp2.x + 1 : newp2.x - 1;
				direction2 = 0;
			} else if (razabs2.y >= razabs2.x && razabs2.y >= razabs2.z) {
				newp2.y = raz2.y < 0 ? newp2.y + 1 : newp2.y - 1;
				direction2 = 1;
			} else {
				newp2.z = raz2.z < 0 ? newp2.z + 1 : newp2.z - 1;
				direction2 = 2;
			}
		}
		
		
		// check if collide
		if (pcmp(newp1, newp2) || (pcmp(newp1, d2.current) && pcmp(newp2, d1.current))) {
			bool change = false;
			if (direction1 == 0) {
				if (razabs1.y > 0) {
					newp1 = d1.current;
					newp1.y = raz1.y > 0 ? newp1.y + 1 : newp1.y - 1;
					change = true;
				} else if (razabs1.z > 0) {
					newp1 = d1.current;
					newp1.z = raz1.z > 0 ? newp1.z + 1 : newp1.z - 1;
					change = true;
				}
			} else if (direction1 == 1) {
				if (razabs1.x > 0) {
					newp1 = d1.current;
					newp1.x = raz1.x > 0 ? newp1.x + 1 : newp1.x - 1;
					change = true;
				} else if (razabs1.z > 0) {
					newp1 = d1.current;
					newp1.z = raz1.z > 0 ? newp1.z + 1 : newp1.z - 1;
					change = true;
				}
			} else {
				if (razabs1.x > 0) {
					newp1 = d1.current;
					newp1.x = raz1.x > 0 ? newp1.x + 1 : newp1.x - 1;
					change = true;
				} else if (razabs1.y > 0) {
					newp1 = d1.current;
					newp1.y = raz1.y > 0 ? newp1.y + 1 : newp1.y - 1;
					change = true;
				}
			}
			
			if (!change) {
				if (direction2 == 0) {
					if (razabs2.y > 0) {
						newp2 = d2.current;
						newp2.y = raz2.y > 0 ? newp2.y + 1 : newp2.y - 1;
						change = true;
					} else if (razabs2.z > 0) {
						newp2 = d2.current;
						newp2.z = raz2.z > 0 ? newp2.z + 1 : newp2.z - 1;
						change = true;
					}
				} else if (direction2 == 1) {
					if (razabs2.x > 0) {
						newp2 = d2.current;
						newp2.x = raz2.x > 0 ? newp2.x + 1 : newp2.x - 1;
						change = true;
					} else if (razabs2.z > 0) {
						newp2 = d2.current;
						newp2.z = raz2.z > 0 ? newp2.z + 1 : newp2.z - 1;
						change = true;
					}
				} else {
					if (razabs2.x > 0) {
						newp2 = d2.current;
						newp2.x = raz2.x > 0 ? newp2.x + 1 : newp2.x - 1;
						change = true;
					} else if (razabs2.y > 0) {
						newp2 = d2.current;
						newp2.y = raz2.y > 0 ? newp2.y + 1 : newp2.y - 1;
						change = true;
					}
				}
			}
			
			if (!change) {
				if (direction1 == direction2 || direction1 == -1 || direction2 == -1) {
					if (razabs1.x + razabs1.y + razabs1.z < razabs2.x + razabs2.y + razabs2.z) {
						newp1 = d1.current;
						if (direction2 == 0)
							newp1.y++;
						else
							newp1.x++;
					} else {
						newp2 = d2.current;
						if (direction1 == 0)
							newp2.y++;
						else
							newp2.x++;
					}
				} else {
					if (razabs1.x + razabs1.y + razabs1.z < razabs2.x + razabs2.y + razabs2.z) {
						newp1 = d1.current;
					} else {
						newp2 = d2.current;
					}
				}
			}
		}
		
		d1.current = newp1;
		d2.current = newp2;
		cout << d1.toString() << " " << d2.toString() << endl;
		
		if (pcmp(d1.current, d1.end) && pcmp(d2.current, d2.end)) {
			break; // I WANT TO BREAK FREE
		}
	}

	return 0;
}