/ neko /

记录详情

Wrong Answer


  
# 状态 耗时 内存占用
#1 Accepted 114ms 10.508 MiB
#2 Accepted 116ms 10.34 MiB
#3 Accepted 111ms 10.246 MiB
#4 Accepted 114ms 10.312 MiB
#5 Accepted 115ms 10.262 MiB
#6 Wrong Answer Read {0}, expect {1}. ["7","1"] 116ms 10.262 MiB
#7 Wrong Answer Read {0}, expect {1}. ["5","2"] 114ms 10.293 MiB
#8 Wrong Answer Read {0}, expect {1}. ["10","1"] 114ms 10.266 MiB

代码

import java.util.*;

public class Main {
    static int ans = 0;
    private static int[] factorial;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int[] arr = new int[n];
        for (int i = 1; i <= n; i++) {
            arr[i - 1] = i;
        }
       Factoroal(n);
        Deque<Integer> path = new ArrayDeque<>();
        boolean[] used = new boolean[n+1];
        dfs(n, m, arr, 0, path, used);
        for (int c:
             path) {
            System.out.print(c+" ");

        }

    }

    public static void dfs(int n, int m, int[] arr, int depth, Deque<Integer> path, boolean[] used) {
        if (depth == n) {
            return;

        }
        int cnt = factorial[n - 1 - depth];
        for (int i = 0; i < n; i++) {
            if (used[i]) {
                continue;
            }
            if (cnt < m){
                m-=cnt;
                continue;
            }
            path.addLast(arr[i]);
            used[i] = true;
            dfs(n, m, arr, depth + 1, path, used);
        }
    }

    public static void Factoroal(int n) {
        factorial = new int[n + 1];
        factorial[0] = 1;
        for (int i = 1; i <= n; i++) {
            factorial[i] = factorial[i - 1] * i;
        }
    }
}

信息

递交者
类型
递交
题目
P1009 全排列
比赛
暑假摸鱼第二弹
题目数据
下载
语言
Java
递交时间
2021-02-06 16:28:32
评测时间
2021-02-06 16:28:32
评测机
分数
50
总耗时
917ms
峰值内存
10.508 MiB