Submission #15320

# Submission time Handle Problem Language Result Execution time Memory
15320 2015-07-12T05:57:18 Z sujin 통로 위의 개미 (kriii3_X) C++
30 / 85
3000 ms 1344 KB
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <algorithm>
#include <vector>
#include <list>

#define PII pair<int, int> 

using namespace std;

int main(){
	list<int> a;
	vector<PII> v;
	long long pt = 0;
	int n = 0;

	int L, Q;
	scanf("%d %d", &L, &Q);
	a.push_back(0);

	while (Q--){
		long long t;
		int p;
		scanf("%lld %d", &t, &p);

		long long mt = t - pt;
		pt = t;
		for (int i = 0; i < n; i++){
			v[i].first = (mt / L % 2 ? L - v[i].first : v[i].first)
				+ ((mt / L % 2 ? -1 : 1) * v[i].second * mt % L);
			v[i].second *= (mt / L % 2 ? -1 : 1);
			if (v[i].first < 0){
				v[i].first = -v[i].first;
				v[i].second = -v[i].second;
			}
			if (v[i].first > L){
				v[i].first = 2 * L - v[i].first;
				v[i].second = -v[i].second;
			}
		}
		sort(v.begin(), v.end());

		if (p == 1){
			int x, d, j = 0;
			scanf("%d %d", &x, &d);
			for (list<int>::iterator it = a.begin(); it != a.end(); it++, j++){
				if (j >= v.size() || v[j].first > x){
					a.insert(it, ++n);
					break;
				}
			}
			v.push_back(PII(x, d));
		}
		else{
			int i, j = 0;
			scanf("%d", &i);
			for (list<int>::iterator it = a.begin(); it != a.end(); it++, j++)
				if ((*it) == i)
					break;
			printf("%d\n", v[j].first);
		}
	}

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 25 ms 1212 KB Output is correct
2 Correct 29 ms 1212 KB Output is correct
3 Correct 28 ms 1212 KB Output is correct
4 Correct 31 ms 1212 KB Output is correct
5 Correct 25 ms 1212 KB Output is correct
6 Correct 26 ms 1212 KB Output is correct
7 Correct 24 ms 1212 KB Output is correct
8 Correct 25 ms 1212 KB Output is correct
9 Correct 25 ms 1212 KB Output is correct
10 Correct 22 ms 1212 KB Output is correct
11 Correct 15 ms 1212 KB Output is correct
12 Correct 22 ms 1212 KB Output is correct
13 Correct 9 ms 1212 KB Output is correct
14 Correct 10 ms 1212 KB Output is correct
15 Correct 15 ms 1212 KB Output is correct
16 Correct 35 ms 1212 KB Output is correct
17 Correct 34 ms 1212 KB Output is correct
18 Correct 26 ms 1212 KB Output is correct
19 Correct 18 ms 1212 KB Output is correct
20 Correct 27 ms 1212 KB Output is correct
21 Correct 8 ms 1212 KB Output is correct
22 Correct 10 ms 1212 KB Output is correct
23 Correct 26 ms 1212 KB Output is correct
24 Correct 30 ms 1212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3000 ms 1344 KB Program timed out
2 Halted 0 ms 0 KB -