CSES - Putka Open 2020 – 1/5 - Results
Submission details
Task:Vaihdot
Sender:AtskaFin
Submission time:2020-09-06 21:28:10 +0300
Language:Node.js
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.44 s1, 2, 3details
#20.95 s1, 2, 3details
#3ACCEPTED0.45 s1, 2, 3details
#40.54 s1, 2, 3details
#50.55 s1, 2, 3details
#60.54 s1, 2, 3details
#70.53 s1, 2, 3details
#80.53 s1, 2, 3details
#90.44 s2, 3details
#10--2, 3details
#11ACCEPTED0.86 s2, 3details
#12--2, 3details
#13--2, 3details
#14--2, 3details
#15--2, 3details
#16--2, 3details
#170.55 s3details
#18--3details
#19--3details
#20--3details
#21--3details
#22--3details
#23--3details
#24--3details

Code

const rl = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});

let n;
let v;

const getRounds = () => {
  let current = 0, rounds = 0;
  while (current !== n) {
    rounds++;
    for (let i = 0; i < n; i++) {
      if (v[i] === current + 1) {
        current++;
      }
    }
  }

  return rounds;
};

const generateRows = () => {
  let c = 0;
  let rounds = []; 
  while (c !== n) {
    let round = [];
    for (let i = 0; i < n; i++) {
      if (v[i] === c+1) {
        c++;
        round.push(v[i]);
      }
    }

    if (round.length === 1) {
      rounds.push([
        v.indexOf(round[0])
      ]);
    } else {
      rounds.push([
        v.indexOf(round[0]),
        v.indexOf(round[round.length - 1])
      ]);
    }
  }

  return rounds;
}

const getPairs = () => {
  let rows = generateRows();

  let len = rows.length;
  let pairs = [];
  for (let i = 0; i < len; i++) {
    for (let j = i+1; j < len; j++) {
      let row1 = rows[i];
      let row2 = rows[j];
  
      if (row1.length === 1) {
        pairs.push([row1[0], row2[0]]);
        pairs.push([row1[0], row2[row2.length - 1]]);
      } else if (row2.length === 1) {
        pairs.push([row2[0], row1[0]]);
        pairs.push([row2[0], row1[row1.length - 1]]);
      } else {
        pairs.push([row1[0], row2[0]]);
        pairs.push([row1[0], row2[row2.length - 1]]);
        pairs.push([row1[row1.length - 1], row2[0]]);
        pairs.push([row1[row1.length - 1], row2[row2.length - 1]]);
      }
    }
  }

  return pairs;
};

rl.on('line', input => {
  if (!n) {
    n = Number(input);
    return
  }

  v = input.split(' ').map(val => Number(val));
  rl.close();
});

rl.on('close', () => {
  let x = [];

  let pairs = getPairs();
  let len = pairs.length;
  for (let i = 0; i < len; i++) {
    [v[pairs[i][0]], v[pairs[i][1]]] = [v[pairs[i][1]], v[pairs[i][0]]];
    x.push(getRounds());
    [v[pairs[i][0]], v[pairs[i][1]]] = [v[pairs[i][1]], v[pairs[i][0]]];
  }
  
  x.sort((a, b) => a - b);
  len = x.length;
  let counter = 1;
  let min = x[0];
  for (let i = 1; i < len; i++) {
    if (x[i] === min) counter++;
    else break;
  }
  
  console.log(min, counter);
});

Test details

Test 1

Group: 1, 2, 3

Verdict:

input
100
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
2 99

user output
undefined 1

Test 2

Group: 1, 2, 3

Verdict:

input
100
100 99 98 97 96 95 94 93 92 91...

correct output
98 4851

user output
98 9702

Test 3

Group: 1, 2, 3

Verdict: ACCEPTED

input
100
1 2 88 4 5 6 7 8 9 10 11 12 13...

correct output
16 5

user output
16 5

Test 4

Group: 1, 2, 3

Verdict:

input
100
51 48 74 70 45 71 24 88 55 99 ...

correct output
49 131

user output
49 145

Test 5

Group: 1, 2, 3

Verdict:

input
100
45 67 29 62 70 77 41 74 52 95 ...

correct output
52 268

user output
52 305

Test 6

Group: 1, 2, 3

Verdict:

input
100
47 98 2 75 6 21 84 8 4 89 27 9...

correct output
48 149

user output
48 158

Test 7

Group: 1, 2, 3

Verdict:

input
100
73 68 17 94 71 63 61 13 58 10 ...

correct output
47 116

user output
47 133

Test 8

Group: 1, 2, 3

Verdict:

input
100
17 16 45 94 6 1 36 81 31 13 51...

correct output
45 95

user output
45 96

Test 9

Group: 2, 3

Verdict:

input
5000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
2 4999

user output
undefined 1

Test 10

Group: 2, 3

Verdict:

input
5000
5000 4999 4998 4997 4996 4995 ...

correct output
4998 12492501

user output
(empty)

Test 11

Group: 2, 3

Verdict: ACCEPTED

input
5000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
19 10

user output
19 10

Test 12

Group: 2, 3

Verdict:

input
5000
1 2 3 4 5 6 264 8 9 10 11 12 1...

correct output
190 96

user output
(empty)

Test 13

Group: 2, 3

Verdict:

input
5000
1 2 3 4 5 6 7 8 9 2400 11 12 1...

correct output
1378 27938

user output
(empty)

Test 14

Group: 2, 3

Verdict:

input
5000
4012 2 4820 4208 1868 1728 362...

correct output
2511 436307

user output
(empty)

Test 15

Group: 2, 3

Verdict:

input
5000
3877 3972 1112 3669 1959 4640 ...

correct output
2497 417065

user output
(empty)

Test 16

Group: 2, 3

Verdict:

input
5000
2774 998 4525 2884 487 1995 41...

correct output
2518 426448

user output
(empty)

Test 17

Group: 3

Verdict:

input
200000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
2 199999

user output
undefined 1

Test 18

Group: 3

Verdict:

input
200000
200000 199999 199998 199997 19...

correct output
199998 19999700001

user output
(empty)

Test 19

Group: 3

Verdict:

input
200000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
19 10

user output
(empty)

Test 20

Group: 3

Verdict:

input
200000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
199 100

user output
(empty)

Test 21

Group: 3

Verdict:

input
200000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
1979 1030

user output
(empty)

Test 22

Group: 3

Verdict:

input
200000
1 2 184153 4 5 6 7 8 164545 10...

correct output
18081 477187

user output
(empty)

Test 23

Group: 3

Verdict:

input
200000
151013 68675 119105 58292 3335...

correct output
86328 318722426

user output
(empty)

Test 24

Group: 3

Verdict:

input
200000
11562 33356 106752 170825 2723...

correct output
99873 663048119

user output
(empty)