Submission #35721235


Source Code Expand

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int main(){
    //1. 入力を受け取る
    int H, W, rs, cs;
    cin >> H >> W >> rs >> cs;
    int N;
    cin >> N;
    vector<int> r(N);
    vector<int> c(N);
    for (int i = 0; i < N; i++){
        cin >> r[i] >> c[i];
    }
    int Q;
    cin >> Q;
    vector<char> d(Q);
    vector<int> l(Q);
    for (int i = 0; i < Q; i++){
        cin >> d[i] >> l[i];
    }

    //2. A, Bを構築する
    map<int, vector<int>> mpA;
    map<int, vector<int>> mpB;
    for (int i = 0; i < N; i++){
        mpA[r[i]].push_back(c[i]);
        mpB[c[i]].push_back(r[i]);
    }
    for (auto itr = mpA.begin(); itr != mpA.end(); itr++){
        (itr->second).push_back(0);
        (itr->second).push_back(W + 1);
        sort((itr->second).begin(), (itr->second).end());
    }
    for (auto itr = mpB.begin(); itr != mpB.end(); itr++){
        (itr->second).push_back(0);
        (itr->second).push_back(H + 1);
        sort((itr->second).begin(), (itr->second).end());
    }

    //3. 実際にシミュレーションを行う
    
    int now_r = rs;
    int now_c = cs;
    for (int i = 0; i < Q; i++){
        //3-1. 上のとき
        if (d[i] == 'U'){
            auto itr = mpB.find(now_c);
            int border = 1;
            //その座標に壁があるとき
            if (itr != mpB.end()){
                auto itr2 = lower_bound((itr->second).begin(), (itr->second).end(), now_r);
                itr2--;
                border = (*itr2) + 1;
            }
            now_r = max(now_r - l[i], border);
        }
        //3-2. 下のとき
        else if (d[i] == 'D'){
            auto itr = mpB.find(now_c);
            int border = H;
            //その座標に壁があるとき
            if (itr != mpB.end()){
                auto itr2 = lower_bound((itr->second).begin(), (itr->second).end(), now_r);
                border = (*itr2) - 1;
            }
            now_r = min(now_r + l[i], border);
        }
        //3-3. 左のとき
        else if (d[i] == 'L'){
            auto itr = mpA.find(now_r);
            int border = 1;
            if (itr != mpA.end()){
                auto itr2 = lower_bound((itr->second).begin(), (itr->second).end(), now_c);
                itr2--;
                border = (*itr2) + 1;
            }
            now_c = max(now_c - l[i], border);
        }
        //3-4. 右のとき
        else if (d[i] == 'R'){
            auto itr = mpA.find(now_r);
            int border = W;
            if (itr != mpA.end()){
                auto itr2 = lower_bound((itr->second).begin(), (itr->second).end(), now_c);
                border = (*itr2) - 1;
            }
            now_c = min(now_c + l[i], border);
        }
        cout << now_r << " " << now_c << "\n";
    }
}

Submission Info

Submission Time
Task D - LRUD Instructions
User AngrySadEight
Language C++ (GCC 9.2.1)
Score 400
Code Size 2936 Byte
Status AC
Exec Time 550 ms
Memory 50780 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 29
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 98 ms 4196 KiB
001.txt AC 103 ms 4628 KiB
002.txt AC 102 ms 4240 KiB
003.txt AC 347 ms 29640 KiB
004.txt AC 343 ms 29012 KiB
005.txt AC 348 ms 29648 KiB
006.txt AC 345 ms 29008 KiB
007.txt AC 104 ms 5436 KiB
008.txt AC 550 ms 50780 KiB
009.txt AC 100 ms 14272 KiB
010.txt AC 254 ms 25972 KiB
011.txt AC 360 ms 35652 KiB
012.txt AC 425 ms 41548 KiB
013.txt AC 536 ms 50016 KiB
014.txt AC 518 ms 50012 KiB
015.txt AC 538 ms 50004 KiB
016.txt AC 548 ms 50008 KiB
017.txt AC 161 ms 8844 KiB
018.txt AC 167 ms 8336 KiB
019.txt AC 171 ms 8924 KiB
020.txt AC 177 ms 8896 KiB
021.txt AC 180 ms 8452 KiB
022.txt AC 180 ms 8456 KiB
023.txt AC 181 ms 8372 KiB
024.txt AC 186 ms 8660 KiB
025.txt AC 187 ms 8864 KiB
026.txt AC 189 ms 9012 KiB
example0.txt AC 4 ms 3648 KiB
example1.txt AC 4 ms 3612 KiB