QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#407681#6422. Evil CoordinateChongQYWA 222ms74868kbJava85.8kb2024-05-09 08:59:122024-05-09 08:59:13

Judging History

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

  • [2024-05-09 08:59:13]
  • 评测
  • 测评结果:WA
  • 用时:222ms
  • 内存:74868kb
  • [2024-05-09 08:59:12]
  • 提交

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 void solve(){
        int mx = scanner.nextInt();
        int my = scanner.nextInt();
        String str = scanner.nextLine();n = str.length();
        int l = 0;
        int r = 0;
        int u = 0;
        int d = 0;
        int inx = 0;
        int iny = 0;
        for(int i = 0 ; i < n ; i++){
            char ch = str.charAt(i);
            if(ch == 'L') {
                l++;
                inx--;
            } else if(ch == 'R') {
                r++;
                inx++;
            } else if(ch == 'D') {
                d++;
                iny--;
            } else {
                u++;
                iny++;
            }
        }
        //特判
        if(mx == 0 && my == 0) {out.println("Impossible");return;}
        if(inx == mx && iny == my) {out.println("Impossible");return;}
        if(l > 0 && r == 0 && u == 0 && d == 0 && (l >= -mx && my == 0 && mx < 0)) {out.println("Impossible");return;}
        if(l > 0 && r == 0 && u == 0 && d == 0) {out.println(str);return;}
        if(r > 0 && l == 0 && u == 0 && d == 0 && (r >= mx && my == 0 && mx > 0)) {out.println("Impossible");return;}
        if(r > 0 && l == 0 && u == 0 && d == 0) {out.println(str);return;}
        if(u > 0 && l == 0 && r == 0 && d == 0 && (u >= my && mx == 0 && my > 0)) {out.println("Impossible");return;}
        if(u > 0 && l == 0 && r == 0 && d == 0) {out.println(str);return;}
        if(d > 0 && l == 0 && r == 0 && u == 0 && (d >= -my && mx == 0 && my < 0)) {out.println("Impossible");return;}
        if(d > 0 && l == 0 && r == 0 && u == 0) {out.println(str);return;}


        //有正解..
        ArrayList<Character> list = new ArrayList<>();
        for(int i = 0 ; i < n ; i++) list.add(str.charAt(i));
        for(int i = 1 ; i <= 30 ; i++){
            boolean pool = true;
            inx = 0;iny = 0;
            for(int j = 0 ; j < n ; j++){
                char ch = list.get(j);
                if(ch == 'L') {
                    l++;
                    inx--;
                } else if(ch == 'R') {
                    r++;
                    inx++;
                } else if(ch == 'D') {
                    d++;
                    iny--;
                } else {
                    u++;
                    iny++;
                }
                if(inx == mx && iny == my) {
                    pool = false;
                    break;
                }
            }
            if(pool){
               for(int j = 0 ; j < n ; j++) out.print(list.get(j));
               out.println();
               return;
            }
            Collections.shuffle(list);
        }
        out.println("Impossible");
    }
    public static void main(String[] args) {

//        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));
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 30ms
memory: 27672kb

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: 222ms
memory: 74868kb

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:

RUDUDR
URU
Impossible
Impossible
Impossible
RRUUUDUUU
RRDRLDR
UD
Impossible
LDDLLLRR
LDRURLDD
Impossible
DUDDLLRDU
LL
Impossible
URDULUR
Impossible
Impossible
Impossible
LDLRLLDRRL
Impossible
RL
Impossible
Impossible
Impossible
Impossible
Impossible
LRURRLLRRU
LLUDL
Impossible
UUDDDLU
RURUDD
Impossi...

result:

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