Submission #48925624


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fir first
#define sec second
int h, w, n;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
int sx, sy;
map<int, set<int> > mph, mpl;
map<char, int> mpc;
int q;
void init() {
	mpc['U'] = 0;
	mpc['D'] = 1;
	mpc['L'] = 2;
	mpc['R'] = 3;
}
signed main() {
	init();
	cin >> h >> w >> sx >> sy;
	cin >> n;
	for(int i = 1, r, c; i <= n; i++) {
		cin >> r >> c;
		mph[r].insert(c);
		mph[r].insert(0);
		mph[r].insert(2e9);
		mpl[c].insert(r);
		mpl[c].insert(0);
		mpl[c].insert(2e9);
	}
	cin >> q;
	int x = sx, y = sy;
	while(q--) {
		char ch;
		int l;
		cin >> ch >> l;
		int d = mpc[ch];
		int nx = x + dx[d] * l;
		nx = max(1ll, nx);
		nx = min(nx, h);
		int ny = y + dy[d] * l;
		ny = max(1ll, ny);
		ny = min(ny, w);
		if(d == 0) {
			if(!mpl[ny].empty()) {
				int temp = *lower_bound(mpl[ny].rbegin(), mpl[ny].rend(), x, [](int xx, int yy) {
					return xx > yy;
				});
				if(temp >= nx && temp <= x) {
					x = temp + 1;
				}
				else {
					x = nx;
				}
			}
			else {
				x = nx;
			}
		}
		else if(d == 1) {
			if(!mpl[ny].empty()) {
				int temp = *lower_bound(mpl[ny].begin(), mpl[ny].end(), x);
				if(temp >= x && temp <= nx) {
					x = temp - 1;
				}
				else {
					x = nx;
				}
			}
			else {
				x = nx;
			}
		}
		else if(d == 2) {
			if(!mph[nx].empty()) {
				int temp = *lower_bound(mph[nx].rbegin(), mph[nx].rend(), y, [](int xx, int yy) {
					return xx > yy;
				});
				if(temp >= ny && temp <= y) {
					y = temp + 1;
				}
				else {
					y = ny;
				}
			}
			else {
				y = ny;
			}
		}
		else if(d == 3) {
			if(!mph[nx].empty()) {
				int temp = *lower_bound(mph[nx].begin(), mph[nx].end(), y);
				if(temp >= y && temp <= ny) {
					y = temp - 1;
				}
				else {
					y = ny;
				}
			}
			else {
				y = ny;
			}
		}
//		cout << "    ";
		cout << x << " " << y << "\n";
	}
	return 0;
}

Submission Info

Submission Time
Task D - LRUD Instructions
User 2020luke
Language C++ 20 (gcc 12.2)
Score 0
Code Size 2009 Byte
Status TLE
Exec Time 3315 ms
Memory 102388 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 2
AC × 25
TLE × 4
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 272 ms 3472 KiB
001.txt AC 311 ms 8376 KiB
002.txt AC 279 ms 3556 KiB
003.txt TLE 3315 ms 59512 KiB
004.txt TLE 3315 ms 59600 KiB
005.txt TLE 3315 ms 59512 KiB
006.txt TLE 3315 ms 59520 KiB
007.txt AC 283 ms 4340 KiB
008.txt AC 1013 ms 98396 KiB
009.txt AC 174 ms 26404 KiB
010.txt AC 432 ms 51416 KiB
011.txt AC 554 ms 71096 KiB
012.txt AC 771 ms 84140 KiB
013.txt AC 974 ms 102388 KiB
014.txt AC 976 ms 102268 KiB
015.txt AC 979 ms 102316 KiB
016.txt AC 979 ms 102300 KiB
017.txt AC 1515 ms 22516 KiB
018.txt AC 1472 ms 22656 KiB
019.txt AC 1424 ms 22888 KiB
020.txt AC 1383 ms 22828 KiB
021.txt AC 1392 ms 22928 KiB
022.txt AC 1413 ms 22924 KiB
023.txt AC 1332 ms 23180 KiB
024.txt AC 1315 ms 23048 KiB
025.txt AC 1301 ms 23096 KiB
026.txt AC 1313 ms 23224 KiB
example0.txt AC 1 ms 3652 KiB
example1.txt AC 1 ms 3468 KiB