Log inSign up
Problems / B054

Coffee bean tasting order

200 ptsCases 15Set by dongbinna
Added October 30.
1 solved1 attempted1 submissionssolvers took 1.0 tries on average

Statement

A cafe has N kinds of coffee bean numbered 1 through N. The barista picks M of them and brews one cup of each in turn to taste. A bean that has been picked is not picked again, so the same bean number never comes up twice in one tasting.

A tasting record keeps which bean was drunk as which cup. Two records with the same beans but a different drinking order therefore count as different records.

Write a program that prints every possible tasting record in lexicographic order. Lexicographic order means that a record whose first cup has the smaller bean number comes first, and when those numbers are equal, the record whose second cup has the smaller bean number comes first.

For example, suppose M=2 of the N=3 kinds of bean are picked and drunk. There are 6 possible tasting records, and listing them in lexicographic order gives the following table.

RecordFirst cupSecond cup
112
213
321
423
531
632

Compare record 3 in the table with record 1. The beans drunk are the same, 1 and 2, but the drinking order is swapped, so they are different records. Both records are therefore in the table.

One more kind of bean means more records. With the same M=2 and N=4, there are 12 possible records, as in the following table.

RecordFirst cupSecond cup
112
213
314
421
523
624
731
832
934
1041
1142
1243

The number of records can be counted as follows. There are N beans to choose from for the first cup, N-1 for the second cup once the one already drunk is taken out, and N-2 for the cup after that. Multiplying on like this up to the Mth cup gives the number of records. So with N=4 and M=2, multiplying 4 by 3 gives 12.

With the same N=3 and M=1, only one cup is drunk, so the possible records are the three 1, 2, 3. With M=3, on the other hand, all three kinds of bean are drunk, so the possible records come to 6 again.

Input and Output Examples

Example 1

Input

3 2

Output

1 2
1 3
2 1
2 3
3 1
3 2

Example 2

Input

1 1

Output

1

Example 3

Input

2 2

Output

1 2
2 1

Input

  • The number of kinds of coffee bean N in the cafe is given first as a natural number. N is a natural number from 1 to 8.

  • The number of cups M to pick and drink then comes on the same line, separated by a space. M is a natural number from 1 to 8, and it is not larger than N, the number of kinds of bean.

  • The input is therefore one line, and that line holds two natural numbers separated by one space.

Output

  • Print every possible tasting record in lexicographic order, one per line. One line holds the M bean numbers in the order they were drunk. On top of that, The last three characters of the output are therefore a space, a newline and a newline, in that order. When a line holds more than one value, the values are separated by a single space.

Requirements

  • A bean that has been picked is not picked again
  • Records with the same beans but a different drinking order are different records
  • Print the records in lexicographic order
  • You must write a program that reads from standard input and writes to standard output
  • Trailing spaces at the end of a line and blank lines at the end of the output are ignored when grading
  • The languages you can use are Python and JavaScript
  • The memory limit is 256MB. The browser does not measure it, it only states it
  • The time limit is set by measuring the setter's reference solution on the same runtime
  • On this problem you submit code, not a prompt. That code runs in the browser on this device, and all that goes to the server is a fingerprint of the output and the time it took. Whether it is correct is decided by the server. The run time is a number each device reports, so the code and the device details are posted next to it on the leaderboard.
  • The output has to match the expected value down to the character. A space inside a line counts the same as any other character.
  • There are 15 cases, and 3 of them show the input together with the expected output. The rest are used only when you submit and are not shown on this page.
  • You have to pass all 15 cases to solve this.
Read the requirements carefully before solving. Tampering with the grading to make a submission look like a pass can get you sanctioned if caught. The code you submit is published on the leaderboard along with the result.

Examples

3 public cases. Judging also uses hidden cases. You have to pass all 15 cases to solve this.

Input
Expected output
1 1
1
2 2
1 2
2 1
3 2
1 2
1 3
2 1
2 3
3 1
3 2

Solution

Your code runs on this device. Only the fingerprint of the output and the elapsed time go to the server. The server decides whether it is correct.

0 chars1 lineMemory 256MB (recorded only)Reference 35ms

Submitting requires you to log in. Running against the public cases works without one.

You can test with 3 public cases. Submitting runs the hidden cases too.

People who solved this problem

The time shown is the time spent solving. Input reading time is outside the solver's control, so it is excluded. And since each device reports this value itself, we record which device measured it.

1bampal2211ms215 charsPythonWindows NT 10.0 / Chrome/156.0.0.0 / 8코어 / 16GB

Log in and you can see the code once you solve this problem.