QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#648264#6422. Evil Coordinateshabi666#Compile Error//C++201.7kb2024-10-17 18:01:122024-10-17 18:01:13

Judging History

你现在查看的是最新测评结果

  • [2024-10-17 18:01:13]
  • 评测
  • [2024-10-17 18:01:12]
  • 提交

answer

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;

const int N = 1e6 + 5;

void solve() {
    int x, y;
    cin >> x >> y;
    string s;
    cin >> s;
    map<char, int> cnt;
    int ex = 0, ey = 0;
    for (char c : s) {
        cnt[c]++;
    }
    ey = cnt['U'] - cnt['D'];
    ex = cnt['R'] - cnt['L'];
    int eex = ex, eey = ey;
    // cerr << ex << ' ' << ey << endl;
    if (x == 0 && y == 0 || x == ex && y == ey) {
        cout << "Impossible" << endl;
        return;
    }

    if ( ex == 0 || ey == 0 ) {
        if ( cnt['L'] == 0 && cnt['R'] == 0 ) {
            if ( abs(y) <= abs(ey) && y * ey >= 0 ) {
                cout << "Impossible" << endl;
                return;
            }
        } else if ( cnt['U'] == 0 && cnt['D'] == 0 ) {
            if ( abs(x) <= abs(ex) && x * ex >= 0 ) {
                cout << "Impossible" << endl;
                return;
            }
        }
    }
    random_shuffle(s.begin(), s.end());
    while (1) {
        if (check(s, x, y)) {
            break;
        }
        random_shuffle(s.begin(), s.end());
    }
    cout << s << endl;
}

bool check(string path, int x, int y) {
    int xx = 0, yy = 0;
    for (char c : path) {
        if (c == 'U')
            yy++;
        if (c == 'D')
            yy--;
        if (c == 'L')
            xx--;
        if (c == 'R')
            xx++;
        if (xx == x && yy == y) {
            return false;
        }
    }
    return true;
}

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    int T = 1;
    cin >> T;
    while (T--) solve();
    //check("RRUUUUUUUURLRLRLUDUDUD", 4, 1);

    return 0;
}

Details

answer.code: In function ‘void solve()’:
answer.code:42:13: error: ‘check’ was not declared in this scope
   42 |         if (check(s, x, y)) {
      |             ^~~~~