1452021-02-01 09:32:14ncsKombináció (50)nimAccepted 50/502ms2212 KiB
import algorithm, strutils, sequtils, sugar

proc i2b(x:seq[int],n:int):seq[int]=
  result=newSeq[int](n)
  for v in x: result[v-1]=1

proc b2i(x:seq[int]):seq[int]=
  for v in 0 ..< x.len:
    if x[v]==1: 
      result.add(v+1)

let IN = stdin.readAll().splitWhitespace().map(x=>parseInt(x))
# echo IN

var 
  n = IN[0]
  m = IN[1]
  x = IN[2 .. ^1]
  b: seq[int]
  status: bool
  

b = i2b(x,n)
status = nextPermutation(b)
if false == status:
  b=repeat(0,n-m) & repeat(1, m)  
echo b2i(b).join(" ")


b = i2b(x,n)
status = prevPermutation(b)
if false == status:
  b=repeat(1, m) & repeat(0,n-m) 
echo b2i(b).join(" ")
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/02ms1952 KiB
2Accepted0/01ms2212 KiB
3Accepted2/21ms2032 KiB
4Accepted2/21ms2048 KiB
5Accepted2/21ms2044 KiB
6Accepted2/21ms2100 KiB
7Accepted2/21ms2068 KiB
8Accepted2/21ms2088 KiB
9Accepted2/21ms2116 KiB
10Accepted4/41ms2032 KiB
11Accepted4/41ms2076 KiB
12Accepted4/41ms2108 KiB
13Accepted4/41ms2072 KiB
14Accepted4/42ms2136 KiB
15Accepted4/42ms2124 KiB
16Accepted6/61ms2064 KiB
17Accepted6/62ms2168 KiB