QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#629688#6422. Evil Coordinatetravel#WA 20ms3856kbC++142.0kb2024-10-11 14:14:252024-10-11 14:14:26

Judging History

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

  • [2024-10-11 14:14:26]
  • 评测
  • 测评结果:WA
  • 用时:20ms
  • 内存:3856kb
  • [2024-10-11 14:14:25]
  • 提交

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;
void solve(){
    cin>>mx>>my;
    string s; cin>>s;
    if(mx == 0 && my == 0){
        cout<<"Impossible"<<endl;
        return ;
    }
    int x = 0,y = 0;
    map<char,int> mp;
    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]]++;
    }
    if(x == mx && y == my){
        cout<<"Impossible"<<endl;
        return ;
    }
    x = 0,y = 0;
    int cnt = 0;
    vector<char> v;
    while(cnt < s.size()){
        bool flag = 0;
        if(mp['L'] >= 1 && ((x - 1 != mx || y != my))){
                mp['L']--;
                x--;
                v.pb('L');
                flag = 1;
                cnt++;
        }
        else if(mp['R'] >= 1 && ((x + 1 != mx || y != my))){
            mp['R']--;
            x ++;
            v.pb('R');
            flag = 1;
            cnt++;
        }
        else if(mp['U'] >= 1 && (y + 1 != my || x != mx))
        {
            mp['U']--;
            y++;
            v.pb('U');
            flag = 1;
            cnt++;
        }
        else if(mp['D'] >= 1 && (y - 1 != my || x != mx)){
            mp['D']--;
            y--;
            v.pb('D');
            flag = 1;
            cnt++;
        }
//        cout<<cnt<<' '<<flag<<endl;
        if(flag == 0)
            break;
    }
    if(cnt < s.size())
    {
        cout<<"Impossible"<<endl;
        return ;
    }
    for(auto it : v)
        cout<<it;
    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: 1ms
memory: 3856kb

input:

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

output:

LLRRUUD
UUU
Impossible
Impossible
Impossible

result:

ok 5 cases

Test #2:

score: -100
Wrong Answer
time: 20ms
memory: 3736kb

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:

RRUUDD
RUU
Impossible
Impossible
Impossible
RRUUUUUUD
LRRRRDD
UD
Impossible
LLLLRRDD
LLRRUDDD
Impossible
Impossible
LL
Impossible
LRRUUUD
Impossible
Impossible
Impossible
LLLLLRRRDD
Impossible
LR
Impossible
Impossible
Impossible
Impossible
Impossible
LLLRRRRRUU
LLLUD
Impossible
LUUUDDD
RRUUDD
Imposs...

result:

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