結果

問題 No.3069 Torn Documents
ユーザー betrue12betrue12
提出日時 2020-04-01 23:18:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,516 bytes
コンパイル時間 2,098 ms
コンパイル使用メモリ 208,768 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-29 02:55:41
合計ジャッジ時間 5,425 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 WA -
testcase_12 AC 1 ms
4,380 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 1 ms
4,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 WA -
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    int A, B;
    cin >> A >> B;
    vector<int> S;
    int dx[] = {0, 0, -1, 1};
    int dy[] = {-1, 1, 0, 0};
    string LRUD = "LRUD";
    string str;
    cin >> str;
    for(char c : str) S.push_back(LRUD.find(c));
    int N = S.size();
    int lastR = -1, lastD = -1;
    for(int i=0; i<N; i++){
        if(str[i] == 'D') lastD = i;
        if(str[i] == 'R') lastR = i;
    }
    for(int b1=0; b1<2; b1++) for(int b2=0; b2<2; b2++){
        set<pair<int, int>> ans;
        
        int x = A, y = B;
        set<pair<int, int>> passed;
        passed.emplace(x, y);
        for(int i=0; i<N; i++){
            int k = S[i];
            int x2 = x+dx[k], y2 = y+dy[k];
            if(x2 < 0 || y2 < 0) continue;
            if(ans.count({x2, y2})) continue;
            bool move;
            if(b1 && lastD == i){
                move = true;
            }else if(b2 && lastR == i){
                move = true;
            }else if(k%2 && !passed.count({x2, y2})){
                move = false;
                ans.emplace(x2, y2);
            }else{
                move = true;
            }
            if(move){
                x = x2;
                y = y2;
                passed.emplace(x, y);
            }
        }
        if(x == 0 && y == 0){
            cout << ans.size() << endl;
            for(auto& p : ans) cout << p.first << " " << p.second << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;
}
0