Submission #15426

# Submission time Handle Problem Language Result Execution time Memory
15426 2015-07-12T07:30:32 Z skeksk91 통로 위의 개미 (kriii3_X) C++
0 / 85
13 ms 1588 KB
#include<stdio.h>
#include<queue>
#include<algorithm>
struct ant {
	int x;
	int d;
	ant(int x, int d) :x(x), d(d) {}

	bool operator<(const ant& p)const {
		return x < p.x;
	}
	bool operator>(const ant& p)const {
		return x > p.x;
	}
};

std::deque<ant> deq;
std::deque<int> order;


int main() {
	int l, q;
	scanf("%d%d", &l, &q);
	int before=0;
	int cnt = 0;
	for (int i = 0; i < q; i++) {
		int t, p;
		scanf("%d%d", &t, &p);
		
		for (std::deque<ant>::iterator it = deq.begin(); it != deq.end(); it++) {
			if (it->d == 1) {
				it->x += t - before;
				if (it->x >= l) {
					it->x = l - (it->x - l);
					it->d = -1;
				}
			}
			else {
				it->x -= t - before;
				if (it->x <= 0) {
					it->x = -it->x;
					it->d = 1;
				}
			}
		}
		std::sort(deq.begin(), deq.end());
		if (p == 1) {
			int x, d;
			scanf("%d%d", &x, &d);
			int a=std::lower_bound(deq.begin(), deq.end(), ant(x, d))-deq.begin();
			deq.insert(deq.begin() + a, ant(x, d));
			order.insert(order.begin(), cnt + 1);
			cnt++;

		}
		if (p == 2) {
			int a;
			scanf("%d", &a);
			int k = 0;
			for (std::deque<int>::iterator it = order.begin(); it != order.end(); it++,k++) {
				if (*it == a) {
					printf("%d\n", deq[k]);
					break;
				}
			}
		}
		before = t;
	}
}

# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 1588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -