QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#268589#6422. Evil Coordinateyujie3WA 61ms3776kbC++20991b2023-11-28 18:46:562023-11-28 18:46:58

Judging History

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

  • [2023-11-28 18:46:58]
  • 评测
  • 测评结果:WA
  • 用时:61ms
  • 内存:3776kb
  • [2023-11-28 18:46:56]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long

using namespace std;

const int N = 1e5 + 7;
int n,m,k;
int a[N],b[N];
char c[4] = {'U','L','R','D'};

void solve(){
	cin >> n >> m;
	string s; cin >> s;
	int len = s.size();
	map<char,int> mp;
	for(int i = 0;i < len;i ++){
		mp[s[i]] ++;
	}
	do{
		string cnt;
		for(int i = 0;i < 4;i ++){
			for(int j = 0;j < mp[c[i]];j ++){
				cnt += c[i];
			}
		} int flag = 0;
		int x = 0,y = 0;
		if(x == n && y == m) continue;
		for(int i = 0;i < len;i ++){
			if(cnt[i] == 'U') y ++;
			if(cnt[i] == 'D') y --;
			if(cnt[i] == 'L') x --;
			if(cnt[i] == 'R') x ++;
			if(x == n && y == m){
				flag = 1;
				break;
			}
		} if(flag) continue;
		else{
			cout << cnt << endl;
			return;
		}
	}while(next_permutation(c,c + 4));
	cout << "Impossible" << endl;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr),cout.tie(nullptr);
	int _; cin >> _;
	while(_ --){
		solve();
	} return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

UULLRRD
UUU
Impossible
Impossible
Impossible

result:

ok 5 cases

Test #2:

score: -100
Wrong Answer
time: 61ms
memory: 3776kb

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:

UURRDD
UUR
Impossible
Impossible
Impossible
DRRUUUUUU
DDLRRRR
DU
Impossible
DDLLLLRR
DDDLLRRU
Impossible
DDDDLLRUU
LL
Impossible
DLRRUUU
Impossible
Impossible
Impossible
LLLLLDDRRR
Impossible
LR
Impossible
Impossible
Impossible
Impossible
Impossible
LLLRRRRRUU
DLLLU
Impossible
DDDLUUU
DDRRUU
Impossi...

result:

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