結果

問題 No.3069 Torn Documents
ユーザー furafura
提出日時 2023-09-18 11:35:10
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,165 bytes
コンパイル時間 4,216 ms
コンパイル使用メモリ 276,428 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-18 11:35:21
合計ジャッジ時間 7,221 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#ifndef TEMPLATE_HPP
#define TEMPLATE_HPP

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define impl_overload4(a, b, c, d, e, ...) e
#define impl_overload5(a, b, c, d, e, f, ...) f
#define impl_overload6(a, b, c, d, e, f, g, ...) g
#define impl_overload7(a, b, c, d, e, f, g, h, ...) h

// clang-format off
#define impl_rep4(i, a, b, c) for (int i = (a); i < (b); i += (c))
#define impl_rep3(i, a, b) impl_rep4(i, a, b, 1)
#define impl_rep2(i, n) impl_rep3(i, 0, n)
#define impl_rep1(n) for (int _ = 0; _ < (n); ++_)
#define rep(...) impl_overload4(__VA_ARGS__, impl_rep4, impl_rep3, impl_rep2, impl_rep1)(__VA_ARGS__)

#define impl_rrep4(i, a, b, c) for (int i = (b) - 1; i >= (a); i -= (c))
#define impl_rrep3(i, a, b) impl_rrep4(i, a, b, 1)
#define impl_rrep2(i, n) impl_rrep3(i, 0, n)
#define rrep(...) impl_overload4(__VA_ARGS__, impl_rrep4, impl_rrep3, impl_rrep2)(__VA_ARGS__)
// clang-format on

#define all(v) std::begin(v), std::end(v)

template<typename T>
constexpr int bit(T x, unsigned int k) {
    return (x >> k) & 1;
}

template<typename T>
constexpr bool chmax(T& a, const T& b) {
    return a < b ? a = b, true : false;
}
template<typename T>
constexpr bool chmin(T& a, const T& b) {
    return a > b ? a = b, true : false;
}

void yesno(bool b) {
    std::cout << (b ? "Yes" : "No") << "\n";
}
void yes() {
    yesno(true);
}
void no() {
    yesno(false);
}

struct Setup {
    Setup() {
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
        std::cout << std::fixed << std::setprecision(11);
    }
} setup;

#ifdef LOCAL
#include "template_local.hpp"
#else
#define show(...) ((void)0)
#endif

using uint = unsigned int;
using lint = long long;
using ulint = unsigned long long;

using namespace std;

#endif // TEMPLATE_HPP

int main() {
    int r, c;
    string s;
    cin >> r >> c >> s;

    // delete redundant moves (e.g., LRLRLR -> R)
    {
        int f[128];
        f['U'] = f['D'] = 0;
        f['L'] = f['R'] = 1;

        string t;
        for (char c: s) {
            if (not t.empty() and f[t.back()] == f[c]) {
                t.pop_back();
            }
            t += c;
        }
        s = t;
    }
    int n = size(s);

    if (count(all(s), 'U') == 0 or count(all(s), 'L') == 0) {
        cout << -1 << endl;
        return 0;
    }
    if (s.substr(n - 2) == "DR" or s.substr(n - 2) == "RD") {
        cout << -1 << endl;
        return 0;
    }

    vector<pair<int, int>> ans;
    int idx = min(s.find_last_not_of('U'), s.find_last_not_of('L'));
    ans.emplace_back(r, c + 1);
    ans.emplace_back(r + 1, c);
    if (s[idx] == 'U') {
        ans.emplace_back(r - 1, c);
        ans.emplace_back(r + 1, 1);
        ans.emplace_back(r + 2, 0);
        ans.emplace_back(0, 1);
    }
    else { // s[idx] == 'L'
        ans.emplace_back(r, c - 1);
        ans.emplace_back(1, c + 1);
        ans.emplace_back(0, c + 2);
        ans.emplace_back(1, 0);
    }
    sort(all(ans));
    ans.erase(unique(all(ans)), end(ans));

    cout << size(ans) << "\n";
    for (auto [x, y]: ans) {
        cout << x << " " << y << "\n";
    }

    return 0;
}
0