Submission #406811


Source Code Expand

#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<utility>
#include<complex>
#include<functional>
using namespace std;



typedef pair<int, int> P;

vector<set<int>> unX(400010);
vector<set<int>> unY(400010);
vector<set<int>> runX(400010);
vector<set<int>> runY(400010);

set<P> used;

const int pivot = 200005;

inline void ins(int x, int y){
	if (used.count(make_pair(y, x)))return;
	unX[pivot + x].insert(pivot + y);
	unY[pivot + y].insert(pivot + x);
	runX[pivot + x].insert(-(pivot + y));
	runY[pivot + y].insert(-(pivot + x));
	//printf("%d,%d\n", x, y);
}

inline void era(int x, int y){
	if (used.count(make_pair(y, x))==0)return;
	unX[pivot + x].erase(pivot + y);
	unY[pivot + y].erase(pivot + x);
	runX[pivot + x].erase(-(pivot + y));
	runY[pivot + y].erase(-(pivot + x));
}
int main(void){
	int K;
	char c;
	string s;
	int x = 0;
	int y = 0;
	cin >> K>>s;
	ins(0, 1);
	ins(1, 0);
	ins(-1, 0);
	ins(0, -1);

	used.insert(make_pair(x, y));
	for (int i = 0; i < K; i++){
		c = s[i];
		switch (c)
		{
		case 'U':
			y=*unY[pivot + x].lower_bound(pivot + y);
			y -= pivot;
			used.insert(make_pair(x, y));
			break;
		case 'D':
			y = -*runY[pivot + x].lower_bound(-(pivot + y));
			y -= pivot;

			used.insert(make_pair(x, y));
			break;
		case 'L':
			x = -*runX[pivot + y].lower_bound(-(pivot + x));
			x -= pivot;
			used.insert(make_pair(x, y));
			break;
		case 'R':
			x = *unX[pivot + y].lower_bound(pivot + x);
			x -= pivot;
			used.insert(make_pair(x, y));
			break;
		default:
			break;
		}
		era(y, x);
		ins(y, x+1);
		ins(y+1, x);
		ins(y-1, x);
		ins(y, x-1);
	//	cout << x << y << endl;
	}

	cout << x <<" "<< y << endl;
	return(0);
}

Submission Info

Submission Time
Task C - 幼稚園児高橋君
User btk15049
Language C++11 (GCC 4.9.2)
Score 100
Code Size 1970 Byte
Status AC
Exec Time 1399 ms
Memory 160696 KB

Judge Result

Set Name Sample Subtask1
Score / Max Score 0 / 0 100 / 100
Status
AC × 3
AC × 24
Set Name Test Cases
Sample subtask0_sample_01.txt, subtask0_sample_02.txt, subtask0_sample_03.txt
Subtask1 subtask0_sample_01.txt, subtask0_sample_02.txt, subtask0_sample_03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt, subtask1_21.txt
Case Name Status Exec Time Memory
subtask0_sample_01.txt AC 214 ms 76116 KB
subtask0_sample_02.txt AC 215 ms 76088 KB
subtask0_sample_03.txt AC 215 ms 76068 KB
subtask1_01.txt AC 213 ms 76116 KB
subtask1_02.txt AC 214 ms 76120 KB
subtask1_03.txt AC 216 ms 76056 KB
subtask1_04.txt AC 214 ms 76116 KB
subtask1_05.txt AC 215 ms 76088 KB
subtask1_06.txt AC 215 ms 76084 KB
subtask1_07.txt AC 919 ms 92600 KB
subtask1_08.txt AC 928 ms 92628 KB
subtask1_09.txt AC 915 ms 91448 KB
subtask1_10.txt AC 910 ms 94012 KB
subtask1_11.txt AC 917 ms 91832 KB
subtask1_12.txt AC 922 ms 91456 KB
subtask1_13.txt AC 936 ms 92348 KB
subtask1_14.txt AC 1314 ms 160696 KB
subtask1_15.txt AC 1330 ms 160612 KB
subtask1_16.txt AC 772 ms 104496 KB
subtask1_17.txt AC 1131 ms 160616 KB
subtask1_18.txt AC 1399 ms 160612 KB
subtask1_19.txt AC 1041 ms 126936 KB
subtask1_20.txt AC 966 ms 124992 KB
subtask1_21.txt AC 1161 ms 123156 KB