QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#629968#6422. Evil Coordinatetravel#WA 25ms3780kbC++142.0kb2024-10-11 15:47:212024-10-11 15:47:21

Judging History

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

  • [2024-10-11 15:47:21]
  • 评测
  • 测评结果:WA
  • 用时:25ms
  • 内存:3780kb
  • [2024-10-11 15:47:21]
  • 提交

answer

//
// Created by travel on 2024/10/11.
//
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> PII;
#define endl "\n"
#define ft first
#define sd second
#define pb push_back
const int mod = 1e9 + 7;
int mx,my;
char st[5] = {'L','R','U','D'};
map<char,int> mp;
vector<char> v;
bool check(int mx,int my){
    int x = 0,y = 0;
    for(int i = 0;i < 4;i++){
        for(int j = 1;j <= mp[v[i]];j++)
        {
            if(v[i] == 'L') x--;
            if(v[i] == 'R') x++;
            if(v[i] == 'D') y--;
            if(v[i] == 'U') y++;
            if(x == mx && y == my ) return false;
        }
    }
    return true;
}
void solve(){
    cin>>mx>>my;
    string s; cin>>s;
    string ed = "Impossible";
    if(mx == 0 && my == 0){
        cout<<ed<<endl;
        return ;
    }
    int x = 0,y = 0;
    mp.clear();
    for(int i = 0;i < s.size();i++){
        if(s[i] == 'R') x++;
        if(s[i] == 'L') x--;
        if(s[i] == 'U') y++;
        if(s[i] == 'D') y--;
        mp[s[i]]++;
    }
    v.clear();
    for(int i = 0;i < 4;i++)
        v.pb(st[i]);
    if(x == mx && y == my){
        cout<<ed<<endl;
        return ;
    }
    if(mp.size() == 1){
        if(x == 0 && abs(y) > abs(my))
        {
            cout<<ed<<endl;
            return ;
        }
        if(y == 0 && abs(x) > abs(mx))
        {
            cout<<ed<<endl;
            return ;
        }
        cout<<s<<endl;
        return ;
    }
    for(int i = 1;i <= 24;i++){
        next_permutation(v.begin(),v.end());
        if(check(mx,my))
        {
            for(int j = 0;j < v.size();j++)
                while(mp[v[j]] >= 1)
                {
                    cout<<v[j];
                    mp[v[j]]--;
                }
        }
    }
    cout<<endl;
    return ;
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int T ; cin>>T;
    while(T--)
        solve();
    return 0;
}
/*
 * 5
1 1
RURULLD
0 5
UUU
0 3
UUU
0 2
UUU
0 0
UUU
 */

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3556kb

input:

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

output:

LLUUDRR
UUU
Impossible
Impossible
Impossible

result:

ok 5 cases

Test #2:

score: -100
Wrong Answer
time: 25ms
memory: 3780kb

input:

11109
6 0
RUDUDR
2 0
URU
0 0
UDRU
0 0
R
-1 1
LDUUDDRUUL
-1 5
RRUUUDUUU
-8 4
RRDRLDR
2 0
UD
0 0
UUDD
3 -2
LDDLLLRR
3 -2
LDRURLDD
1 0
RRL
-1 0
DUDDLLRDU
-4 0
LL
-1 -1
DLRLDLUDUR
1 4
URDULUR
0 0
DDUUDUDDDD
0 2
UU
1 0
RRULD
0 -2
LDLRLLDRRL
0 1
RLRLLRLUR
-3 0
RL
0 0
D
0 0
L
0 0
DDLRRUDRUD
0 0
DULU
2 0
RR...

output:

UUDDRR
UUR
Impossible
Impossible
Impossible
UUUUUUDRR
LDDRRRR
UD
Impossible
LLLLDDRR
LLUDDDRR
Impossible
RDDDDLLUU
LL
Impossible
LUUUDRR
Impossible
Impossible
Impossible
LLLLLDDRRR
Impossible
LR
Impossible
Impossible
Impossible
Impossible
Impossible
RRRRRLLLUU
LLLUD
Impossible
LUUUDDD
UUDDRR
Impossi...

result:

wrong answer case 106, participant does not find an answer but the jury does