QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#405951#6515. Path PlanningxiaoleRE 39ms60688kbJava115.3kb2024-05-06 17:32:322024-05-06 17:32:33

Judging History

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

  • [2024-05-06 17:32:33]
  • 评测
  • 测评结果:RE
  • 用时:39ms
  • 内存:60688kb
  • [2024-05-06 17:32:32]
  • 提交

answer

import com.sun.source.tree.Tree;

import javax.swing.*;
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 int a0 , a1;
//    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 + 1][m + 1];
        long[][] arr = new long[n + 1][m + 1];
        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(num == arr[i][j]){
                        xx = i;
                        yy = j;
                        pool = true;
                        break;
                    }
                }
            }
            if(!pool){
                break;
            }
            set.add(arr[x][y]);
            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];
                    }
                }
            }
            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;

        }
        long ans = 0;
        for(Long nu : set){
            if(ans == nu) ans++;
            else break;
        }
        out.println(ans);


/*
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: 100
Accepted
time: 39ms
memory: 60688kb

input:

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

output:

3
5

result:

ok 2 number(s): "3 5"

Test #2:

score: -100
Runtime Error

input:

10000
2 9
4 0 3 5 2 7 16 11 12
9 13 14 17 10 8 15 1 6
4 8
19 23 22 13 29 4 17 26
30 6 25 3 15 24 18 14
12 8 7 9 27 5 0 10
11 16 31 20 2 28 1 21
1 6
3 2 0 1 4 5
2 3
4 2 0
3 5 1
5 1
4
0
3
2
1
1 3
1 0 2
8 10
9 50 8 0 41 57 60 30 23 65
64 21 36 12 10 5 58 19 38 67
71 52 45 17 77 4 59 51 22 25
56 49 79 2...

output:


result: