NC216011. KCo-primePermutation
描述
输入描述
There is only one test case in each test file.
The first and only line contains two integers and (, ).
输出描述
Output one line containing integers separated by one space, indicating the permutation satisfying the given constraints. If no such permutation exists output "-1" (without quotes) instead. If there are multiple valid answers you can print any of them.
Please, DO NOT output extra spaces at the end of each line, otherwise your answer may be considered incorrect!
示例1
输入:
5 3
输出:
1 4 5 2 3
示例2
输入:
1 0
输出:
-1
Python3(3.9) 解法, 执行用时: 485ms, 内存消耗: 9728K, 提交时间: 2020-12-25 13:47:00
n, k = map(int, input().split()) if k == 0: print(-1) elif n == 1: print(1) else: print(k, end = ' ') for i in range(1, k): print(i, end = ' ') for i in range(k + 1, n + 1): print(i, end = ' ')
pypy3 解法, 执行用时: 1008ms, 内存消耗: 35972K, 提交时间: 2022-10-06 13:22:11
n, k = map(int,input().split()) if k == 0: print(-1) exit(0) print(k, end = '') for i in range(1, k): print('',i, end = '') for i in range(k+1, n+1): print('',i, end = '') print()
C++(clang++11) 解法, 执行用时: 79ms, 内存消耗: 7128K, 提交时间: 2021-01-22 17:01:58
#include<bits/stdc++.h> using namespace std; int main() { int n,k; cin>>n>>k; if(k==0) return puts("-1"),0; for(int i=1;i<=n;i++) printf("%d%c",i<=k?i%k+1:i,i==n?'\n':' '); }