QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#405960#6515. Path PlanningChongQYWA 37ms41996kbJava85.1kb2024-05-06 17:42:332024-05-06 17:42:35

Judging History

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

  • [2024-05-06 17:42:35]
  • 评测
  • 测评结果:WA
  • 用时:37ms
  • 内存:41996kb
  • [2024-05-06 17:42:33]
  • 提交

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) (1 * 1e5 + 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 long[] arr;

    //    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 n = scanner.nextInt();
        int m = scanner.nextInt();
        boolean[][] dp = new boolean[n + 3][m + 3];
        long[][] arr = new long[n + 3][m + 3];
        for(int i = 1 ; i <= n ; i++){
            for(int j = 1 ; j <= m ; j++){
                arr[i][j] = scanner.nextLong();
            }
        }

        TreeSet<Long> set = new TreeSet<>();
        long num = 0;// 最小的数
        int x = 1;int y = 1;
        while(!(x == n && y == m)){
            while(set.contains(num)) num++;
            boolean pool = false;
            int xx = -1;
            int yy = -1;
            for(int i = x ; i <= n ; i++){
                for(int j = y ; j <= m ; j++){
                    if(pool) break;
                    if(num == arr[i][j]){
                        xx = i;
                        yy = j;
                        pool = true;
                    }
                }
            }
            if(!pool){
                break;
            }

            for(int i = x ; i <= xx ; i++){
                for(int j = y ; j <= yy ; j++){
                    if(i == 1){
                        dp[i][j] = true;
                    } else if(j == 1){
                        dp[i][j] = false;
                    } else {
                        dp[i][j] = arr[i - 1][j] > arr[i][j - 1];
                    }
                }
            }
            set.add(arr[x][y]);
            int in1 = xx;
            int in2 = yy;
            while(!(in1 == x && in2 == y)){
                set.add(arr[in1][in2]);
                if(dp[in1][in2]) in2--;
                else in1--;
            }

            x = xx;
            y = yy;

        }
        System.out.println(num);


/*
2
2 3
1 2 4
3 0 5
1 5
1 3 0 4 2
 */



    }

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

class way {
    public int cnt , a0 , a1;

    public way(int cnt, int a0, int a1) {
        this.cnt = cnt;
        this.a0 = a0;
        this.a1 = a1;
    }
}

详细

Test #1:

score: 0
Wrong Answer
time: 37ms
memory: 41996kb

input:

2
2 3
1 2 4
3 0 5
1 5
1 3 0 4 2

output:

3
2

result:

wrong answer 2nd numbers differ - expected: '5', found: '2'