답안 #63401

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
63401 2018-08-01T16:49:04 Z bazsi700 전차 (CEOI13_tram) C++14
45 / 100
1000 ms 4676 KB
#include <bits/stdc++.h>
using namespace std;

#define MOD 1000000007
#define ll long long int
#define vi vector<int>
#define vii vector< vector<int> >
#define PI 3.1415926535897932384626433832795
#define INF 9223372036854775807LL

double dist[150002][3];
bool occ[150002][3];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m;
	cin >> n >> m;
	vector<pair<int,int> > pass (m+1);
	pair<int,int> mnat = {1,1};
	for(int i = 1; i <= n; i++) {
		dist[i][1] = dist[i][2] = 3000000;
	}
	for(int ev = 1; ev <= m; ev++) {
		char ch;
		cin >> ch;
		if(ch == 'E') {
			mnat = {1,1};
			for(int i = 1; i <= n; i++) {
				for(int c = 1; c <= 2; c++) {
					if(dist[i][c] > dist[mnat.first][mnat.second]+0.000001) {
						mnat = {i,c};
					}
				}
			}
			pass[ev] = mnat;
			cout << mnat.first << " " << mnat.second << "\n";
			occ[mnat.first][mnat.second] = true;
			for(int c = 1; c <= 2; c++) {
				int lastwasat = mnat.first;
				for(int i = mnat.first; i <= n; i++) {
					double dis = sqrt((i-lastwasat)*(i-lastwasat)+(c-mnat.second)*(c-mnat.second));
					if(dist[i][c] < dis-1.5) {
						break;
					}
					dist[i][c] = min(dist[i][c],dis);
				}
				for(int i = mnat.first; i >= 1; i--) {
					double dis = sqrt((i-lastwasat)*(i-lastwasat)+(c-mnat.second)*(c-mnat.second));
					if(dist[i][c] < dis-1.5) {
						break;
					}
					dist[i][c] = min(dist[i][c],dis);
				}
			}
		} else {
			int x;
			cin >> x;
			auto pr = pass[x];
			occ[pr.first][pr.second] = false;
			int fr = -10;
			int to = n+10;
			for(int i = pr.first; i < n; i++) {
				if(occ[i][1] || occ[i][2]) {
					to = i+4;
					break;
				}
			}
			for(int i = pr.first; i >= 1; i--) {
				if(occ[i][1] || occ[i][2]) {
					fr = i-4;
					break;
				}
			}
			//fr = -10;
		//	to = n+10;
		//	cout << fr << "a" << to << endl;
			for(int i = max(1,fr+2); i <= min(n,to-2); i++) {
				dist[i][1] = dist[i][2] = 3000000;
			}
			for(int c = 1; c <= 2; c++) {
				int lastwasat = -1;
				for(int i = max(1,fr); i <= min(n,to); i++) {
					if(occ[i][c]) {
						lastwasat = i;
					}
					if(lastwasat != -1) {
						dist[i][c] = min(dist[i][c],double(i-lastwasat));
					}
				}
				lastwasat = -1;
				for(int i = min(n,to); i >= max(1,fr); i--) {
					if(occ[i][c]) {
						lastwasat = i;
					}
					if(lastwasat != -1) {
						dist[i][c] = min(dist[i][c],double(lastwasat-i));
					}
				}
			}
			for(int c = 1; c <= 2; c++) {
				int lastwasat = -1;
				for(int i = max(1,fr); i <= min(n,to); i++) {
					if(occ[i][3-c]) {
						lastwasat = i;
					}
					if(lastwasat != -1) {
						dist[i][c] = min(dist[i][c],sqrt((i-lastwasat)*(i-lastwasat)+1));
					}
				}
				lastwasat = -1;
				for(int i = min(n,to); i >= max(1,fr); i--) {
					if(occ[i][3-c]) {
						lastwasat = i;
					}
					if(lastwasat != -1) {
						dist[i][c] = min(dist[i][c],sqrt((i-lastwasat)*(i-lastwasat)+1));
					}
				}
			}
		}
	}
	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 20 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 20 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1089 ms 4368 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1045 ms 4364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1079 ms 1132 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1081 ms 4676 KB Time limit exceeded
2 Halted 0 ms 0 KB -