QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#407694 | #6422. Evil Coordinate | ChongQY | AC ✓ | 151ms | 52880kb | Java8 | 6.8kb | 2024-05-09 09:29:37 | 2024-05-09 09:29:39 |
Judging History
answer
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
public class Main {
public static Read scanner = new Read(System.in);
public static final long MOD = (long) (1e9 + 7);
public static final int MID = (int) (4 * 1e1 + 7);
public static final long LMAX = Long.MAX_VALUE;
public static final long LMIN = Long.MIN_VALUE;
public static final int IMAX = Integer.MAX_VALUE;
public static final int IMIN = Integer.MIN_VALUE;
public static int[] arr = new int[MID];
// public static long[] Qz = new long[MID];
// public static long[] Hz = new long[MID];
public static int N, M , n , m;
public static long ans;
// public static boolean[][] stack = new boolean[MID][MID];
//四个方向
public static int[] row = {1, -1, 0, 0};
public static int[] cos = {0, 0, 1, -1};
static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
public static int[][] get = new int[25][5];
public static void solve(){
int mx = scanner.nextInt();
int my = scanner.nextInt();
String str = scanner.nextLine();n = str.length();
int[] cnt = new int[5];
int inx = 0;
int iny = 0;
for(int i = 0 ; i < n ; i++){
char ch = str.charAt(i);
if(ch == 'L') {
cnt[1]++;
inx--;
} else if(ch == 'R') {
cnt[2]++;
inx++;
} else if(ch == 'D') {
cnt[3]++;
iny--;
} else {
cnt[4]++;
iny++;
}
}
//特判
if(mx == 0 && my == 0) {out.println("Impossible");return;}
if(inx == mx && iny == my) {out.println("Impossible");return;}
for(int i = 1 ; i <= 24 ; i++){
inx = 0;iny = 0;
boolean pool = true;
StringBuilder ans = new StringBuilder();
int a = cnt[get[i][1]];char ch1 = getch(get[i][1]);
int b = cnt[get[i][2]];char ch2 = getch(get[i][2]);
int c = cnt[get[i][3]];char ch3 = getch(get[i][3]);
int d = cnt[get[i][4]];char ch4 = getch(get[i][4]);
while(a -- != 0){
ans.append(ch1);
if(ch1 == 'L') inx--;
if(ch1 == 'R') inx++;
if(ch1 == 'U') iny++;
if(ch1 == 'D') iny--;
if(inx == mx && iny == my) {
pool = false;
break;
}
} if(!pool) continue;
while(b -- != 0){
ans.append(ch2);
if(ch2 == 'L') inx--;
if(ch2 == 'R') inx++;
if(ch2 == 'U') iny++;
if(ch2 == 'D') iny--;
if(inx == mx && iny == my) {
pool = false;
break;
}
} if(!pool) continue;
while(c -- != 0){
ans.append(ch3);
if(ch3 == 'L') inx--;
if(ch3 == 'R') inx++;
if(ch3 == 'U') iny++;
if(ch3 == 'D') iny--;
if(inx == mx && iny == my) {
pool = false;
break;
}
} if(!pool) continue;
while(d -- != 0){
ans.append(ch4);
if(ch4 == 'L') inx--;
if(ch4 == 'R') inx++;
if(ch4 == 'U') iny++;
if(ch4 == 'D') iny--;
if(inx == mx && iny == my) {
pool = false;
break;
}
} if(!pool) continue;
out.println(ans);
return;
}
out.println("Impossible");
}
public static void init(){
int in = 1;
for(int i = 1 ; i <= 4 ; i++){
for(int j = 1 ; j <= 4 ; j++){
for(int o = 1 ; o <= 4 ; o++){
for(int p = 1 ; p <= 4 ; p++){
if(i != j && i != o && i != p && j != o && j != p && o != p){
get[in][1] = i;
get[in][2] = j;
get[in][3] = o;
get[in][4] = p;
in++;
}
}
}
}
}
}
public static char getch(int nu){
if(nu == 1) return 'L';
if(nu == 2) return 'R';
if(nu == 3) return 'D';
return 'U';
}
public static void main(String[] args) {
init();
// long start = System.currentTimeMillis();//程序开始时间戳
int T = scanner.nextInt();
while (T-- != 0) {
solve();
}
out.flush();
// long end = System.currentTimeMillis();//程序结束时间戳
// out.println("运行时间 : " + (end - start));//输出运行时间
}
//快读
static class Read {
BufferedReader br;
StringTokenizer st;
public Read(InputStream in) {
br = new BufferedReader(new InputStreamReader(in), 16384);
eat("");
}
public void eat(String s) {
st = new StringTokenizer(s);
}
public String nextLine() {
try {
return br.readLine();
} catch (IOException e) {
return null;
}
}
public boolean hasNext() {
while (!st.hasMoreTokens()) {
String s = nextLine();
if (s == null)
return false;
eat(s);
}
return true;
}
public String next() {
hasNext();
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public Double nextDouble() {
return Double.parseDouble(next());
}
public BigInteger nextBigInteger() {
return new BigInteger(next());
}
public BigDecimal nextBigDecimal() {
return new BigDecimal(next());
}
}
public static void swap(long[] arr , int index1 , int index2){
long t = arr[index1];
arr[index1] = arr[index2];
arr[index2] = t;
}
public static long Dot_pitch(long x , long y , long xx , long yy){
return (xx - x) * (xx - x) + (yy - y) * (yy - y);
// return (long) Math.sqrt(Math.pow(xx - x , 2) + Math.pow(yy - y , 2));
}
}
详细
Test #1:
score: 100
Accepted
time: 47ms
memory: 27660kb
input:
5 1 1 RURULLD 0 5 UUU 0 3 UUU 0 2 UUU 0 0 UUU
output:
LLRRDUU UUU Impossible Impossible Impossible
result:
ok 5 cases
Test #2:
score: 0
Accepted
time: 148ms
memory: 51652kb
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:
RRDDUU RUU Impossible Impossible Impossible RRDUUUUUU LRRRRDD DU Impossible LLLLRRDD LLRRDDDU Impossible RDDDDLLUU LL Impossible LRRDUUU Impossible Impossible Impossible LLLLLRRRDD Impossible LR Impossible Impossible Impossible Impossible Impossible LLLRRRRRUU LLLDU Impossible LDDDUUU RRDDUU Impossi...
result:
ok 11109 cases
Test #3:
score: 0
Accepted
time: 151ms
memory: 52880kb
input:
11107 1 0 LLRLRURLR 1 0 LLRR 0 1 R 1 0 LLLRLRRR 1 0 RUL 0 1 UD 1 0 RLRLU 0 1 DDDUUUDU 1 0 RURRLLRLL 1 0 LRLR 1 0 ULR 0 1 R 0 1 DDUUUDR 0 1 UUDDUDDU 0 1 DDUUDU 1 0 RRLRLLRLRL 1 0 RLRRLL 1 0 LUR 1 0 U 1 0 LRRRLLLR 0 1 DRUUDDUDU 0 1 DUUDDUR 1 0 LRLRLR 0 1 UUDDDUDU 0 1 R 0 1 UDUDDU 0 1 DUUDUD 1 0 RRLRRR...
output:
LLLLRRRRU LLRR R LLLLRRRR LRU DU LLRRU DDDDUUUU LLLLRRRRU LLRR LRU R RDDDUUU DDDDUUUU DDDUUU LLLLLRRRRR LLLRRR LRU U LLLLRRRR RDDDDUUUU RDDDUUU LLLRRR DDDDUUUU R DDDUUU DDDUUU LLLLLRRRRR DDDDUUUU DDUU LLLLRRRRU DDUU LLLRRR LRU LRU U LRU LLLRRR LLLLLRRRRR U DDDUUU R LLLRRR RDDDDUUUU RDDDDUUUU LLLRRR ...
result:
ok 11107 cases