QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#506119#6422. Evil CoordinateGrunrayWA 0ms3684kbC++203.3kb2024-08-05 15:23:212024-08-05 15:23:22

Judging History

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

  • [2024-08-05 15:23:22]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3684kb
  • [2024-08-05 15:23:21]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define PII pair<int,int>
#define PIS pair<int,string>
#define fr(i,x,y) for(int i=x,p=y;i<=p;i++)
#define rp(i,x,y) for(int i=x,p=y;i>=p;i--)
const int N = 1e6 + 10;
const int M = 1e2 + 10;
int mod = 998244353;
int xx, yy;
int n, m;
string s;
int d[4];
int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };
string ss = "";
int fg = 0;
void dfs(int x, int y, int step) {
    if (step == s.size()) {
        fg = 1;
        printf("%s", ss);
        puts("");
        return;
    }if (fg) {
        return;
    }
    fr(i, 0, 3) {
        if (!d[i])continue;
        x += dx[i];
        y += dy[i];
        if (x == n && y == m) {
            continue;
        }
        d[i]--;
        if (i == 1)ss += "R";
        if (i == 0)ss += "U";
        if (i == 3)ss += "L";
        if (i == 2)ss += "D";
        dfs(x, y, step + 1);
        if (fg)return;
        d[i]++;
        x -= dx[i];
        y -= dy[i];
        ss.erase(ss.size() - 1, 1);
    }
}
void solve() {


    cin >> n >> m;
    fr(i, 0, 3) {
        d[i] = 0;
    }
    cin >> s;
    fr(i, 0, s.size() - 1) {
        if (s[i] == 'L')d[3]--;
        if (s[i] == 'R')d[1]++;
        if (s[i] == 'U')d[0]++;
        if (s[i] == 'D')d[2]--;
    }

    if (n == 0 && m == 0) {
        puts("Impossible");
        return;
    }
    int cnt = 0, now;
    int f[4] = { 0 };
    fr(i, 0, 3) {
        if (d[i] != 0 && !f[i]) {
            cnt++;
            f[i] = 1;
            now = i;
        }
    }
    int x = 0, y = 0;
    if (cnt == 1) {
        if (now % 2) {
            if (m == 0 && (n >= min(0ll, d[now]) && n <= max(0ll, d[now]))) {
                puts("Impossible");
                return;
            }
            else {
                printf("%s", s);
                puts("");
                return;
            }
        }
        else {
            if (n == 0 && (m >= min(0ll, d[now]) && m <= max(0ll, d[now]))) {
                puts("Impossible");
                return;
            }
            else {
                printf("%s", s);
                puts("");
                //cout << s << endl;
                return;
            }
        }
    }
    fr(i, 0, 3) {
        if (i % 2)x += d[i];
        else y += d[i];
    }
    if (x == n && y == m) {
        puts("Impossible");
        //cout << "Impossible" << endl;
        return;
    }
    fr(i, 0, 3) {
        if (d[i] < 0) {
            d[i] = -d[i];
        }
    }
    int p = 0;
    if (n > 0) {
        fr(i, 1, d[3])putchar('L');
        p += d[3];
        x -= d[3];
        d[3] = 0;
    }
    else {
        fr(i, 1, d[1])putchar('R');
        p += d[1];
        x += d[1];
        d[1] = 0;
    }
    if (m > 0) {
        fr(i, 1, d[2])putchar('D');
        p += d[2];
        y -= d[2];
        d[2] = 0;
    }
    else {
        fr(i, 1, d[0])putchar('U');
        p += d[0];
        y += d[0];
        d[0] = 0;
    }
    fg = 0;
    dfs(x, y, p);
    //puts("");
    //    cout<<ss<<endl;
    ss.clear();
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int n = 1;
    cin >> n;
    while (n--)
        solve();
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3684kb

input:

5
1 1
RURULLD
0 5
UUU
0 3
UUU
0 2
UUU
0 0
UUU

output:

LLD`

result:

wrong answer Line "LLD`