Submission #35672947


Source Code Expand

#include <bits/extc++.h>

template<typename T, typename S>
std::ostream& operator<<(std::ostream& os, const std::pair<T, S>& p){
    os << p.first << " " << p.second;
    return os;
}

int main() {
    using namespace std;
    long H, W;
    cin >> H >> W;
    pair<long, long> now{};
    cin >> now.first >> now.second;
    
    unsigned long N;
    cin >> N;
    unordered_map<long, set<long>> vertical, horizontal;
    for(unsigned long i{}; i < N; ++i){
        long x, y;
        cin >> x >> y;
        vertical[x].insert(y);
        horizontal[y].insert(x);
    }

    unsigned long Q;
    cin >> Q;
    for(unsigned long i{}; i < Q; ++i){
        char d;
        long l;
        cin >> d >> l;
        switch(d){
            case 'L':
                if(vertical.count(now.first)){
                    const auto walls{vertical[now.first]};
                    const auto next_wall{walls.upper_bound(now.second)};
                    if(next_wall == begin(walls))now.second -= l;
                    else now.second = max(now.second - l, *prev(next_wall) + 1);
                }else now.second -= l;
                break;
            case 'R':
                if(vertical.count(now.first)){
                    const auto walls{vertical[now.first]};
                    const auto next_wall{walls.lower_bound(now.second)};
                    if(next_wall == end(walls))now.second += l;
                    else now.second = min(now.second + l, *next_wall - 1);
                }else now.second += l;
                break;
            case 'U':
                if(horizontal.count(now.second)){
                    const auto walls{horizontal[now.second]};
                    const auto next_wall{walls.upper_bound(now.first)};
                    if(next_wall == begin(walls))now.first -= l;
                    else now.first = max(now.first - l, *prev(next_wall) + 1);
                }else now.first -= l;
                break;
            case 'D':
                if(horizontal.count(now.second)){
                    const auto walls{horizontal[now.second]};
                    const auto next_wall{walls.lower_bound(now.first)};
                    if(next_wall == end(walls))now.first += l;
                    else now.first = min(now.first + l, *next_wall - 1);
                }else now.first += l;
                break;
        }
        now.first = clamp(now.first, 1L, H);
        now.second = clamp(now.second, 1L, W);
        cout << now << endl;
    }
    return 0;
}

Submission Info

Submission Time
Task D - LRUD Instructions
User MMNMM
Language C++ (GCC 9.2.1)
Score 0
Code Size 2498 Byte
Status TLE
Exec Time 3310 ms
Memory 58576 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 395 ms 3400 KiB
001.txt AC 389 ms 3680 KiB
002.txt AC 396 ms 3452 KiB
003.txt TLE 3310 ms 48968 KiB
004.txt TLE 3310 ms 48972 KiB
005.txt TLE 3310 ms 49008 KiB
006.txt TLE 3310 ms 49036 KiB
007.txt AC 404 ms 4460 KiB
008.txt AC 791 ms 58576 KiB
009.txt AC 129 ms 16068 KiB
010.txt AC 333 ms 29884 KiB
011.txt AC 361 ms 42548 KiB
012.txt AC 551 ms 48548 KiB
013.txt AC 699 ms 57760 KiB
014.txt AC 697 ms 57828 KiB
015.txt AC 694 ms 57788 KiB
016.txt AC 694 ms 57776 KiB
017.txt AC 2052 ms 22508 KiB
018.txt AC 1698 ms 22352 KiB
019.txt AC 1546 ms 22560 KiB
020.txt AC 1432 ms 22580 KiB
021.txt AC 1378 ms 22632 KiB
022.txt AC 1341 ms 22664 KiB
023.txt AC 1306 ms 22596 KiB
024.txt AC 1279 ms 22612 KiB
025.txt AC 1283 ms 22572 KiB
026.txt AC 1229 ms 22652 KiB
example0.txt AC 7 ms 3568 KiB
example1.txt AC 2 ms 3464 KiB