답안 #15322

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
15322 2015-07-12T05:58:09 Z skeksk91 통로 위의 개미 (kriii3_X) C++
0 / 85
21 ms 1208 KB
#include<stdio.h>
#include<list>
#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::list<int> order;
std::list<ant> tu;
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::list<ant>::iterator it = tu.begin(); it != tu.end(); it++) {
			if (it->d == 1) {
				it->x += t - before;
				if (it->x > l) {
					it->d = -1;
					it->x = l - (it->x - l);
				}
			}
			else {
				it->x -= t - before;
				if (it->x <0) {
					it->d = 1;
					it->x = -it->x;
				}
			}
		}
		tu.sort();
		if (p == 1) {
			int x, d;
			scanf("%d%d", &x, &d);
			int k = 0;
			std::list<ant>::iterator it;
			std::list<int>::iterator ord = order.begin();
			for (it = tu.begin(); it != tu.end(); it++,ord++) {
				if (it->x>x) {
					
					break;
				}
			}
			
			tu.insert(it, ant(x, d));
			order.insert(ord, cnt + 1);
			cnt++;
		


		}
		else {
			int a;
			scanf("%d", &a);
			std::list<ant>::iterator itt = tu.begin();
			for (std::list<int>::iterator it = order.begin(); it != order.end(); it++,itt++) {
				if ((*it) == a) {
					printf("%d\n", itt->x);
				}
			}


		}
		before = t;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 1208 KB Output is correct
2 Incorrect 20 ms 1208 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Halted 0 ms 0 KB -