CSES - Putka Open 2020 – 1/5 - Results
Submission details
Task:Vaihdot
Sender:Metabolix
Submission time:2020-09-04 23:36:29 +0300
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.01 s1, 2, 3details
#20.01 s1, 2, 3details
#30.01 s1, 2, 3details
#40.01 s1, 2, 3details
#50.01 s1, 2, 3details
#60.01 s1, 2, 3details
#70.01 s1, 2, 3details
#80.01 s1, 2, 3details
#90.01 s2, 3details
#100.32 s2, 3details
#110.01 s2, 3details
#120.03 s2, 3details
#130.26 s2, 3details
#140.52 s2, 3details
#150.53 s2, 3details
#160.53 s2, 3details
#170.01 s3details
#180.01 s3details
#190.01 s3details
#200.01 s3details
#210.01 s3details
#220.01 s3details
#230.01 s3details
#240.01 s3details

Code

#include <iostream>

int n, L[50003], Li[50003];
int vaihtoehtoja = 0, vaihtoehtoja0 = 0;

int matka(int a, int b) {
	int laskuri = 1;
	for (int i = a; i < b; ++i) {
		if (Li[i+1] < Li[i]) {
			laskuri += 1;
		}
	}
	return laskuri;
}

int matka_4(int a, int b, int c, int d) {
	if (a < b && b < c && c < d) return 1;
	if ((a < b && b < c) || (b < c && c < d) || (a < b && c < d)) return 2;
	if (a < b || b < c || c < d) return 3;
	return 4;
}

int matka_3(int a, int b, int c) {
	if (a < b && b < c) return 1;
	if (a < b || b < c) return 2;
	return 3;
}

void vaihtoyritys(int a_l, int b_l) {
	if (a_l <= b_l + 1) return;
	int ma0 = matka_3(Li[a_l-1], Li[a_l], Li[a_l+1]);
	int ma1 = matka_3(Li[a_l-1], Li[b_l], Li[a_l+1]);
	int mb0 = matka_3(Li[b_l-1], Li[b_l], Li[b_l+1]);
	int mb1 = matka_3(Li[b_l-1], Li[a_l], Li[b_l+1]);
	if (ma1 + mb1 < ma0 + mb0) vaihtoehtoja += 1;
	if (ma1 + mb1 == ma0 + mb0) vaihtoehtoja0 += 1;
}

int main() {
	std::cin >> n;
	L[0] = Li[0] = 0;
	L[n+1] = Li[n+1] = n+1;
	L[n+2] = Li[n+2] = n+2;
	bool suora = true;
	for (int i = 1; i <= n; ++i) {
		std::cin >> L[i];
		Li[L[i]] = i;
		suora = suora && L[i] == i;
	}
	if (n == 2 && L[1] == 1) {
		puts("2 1");
		return 0;
	}
	if (n == 2 && L[1] == 2) {
		puts("1 1");
		return 0;
	}
	if (suora) {
		puts("2 2");
		return 0;
	}

	for (int a_l = 1; a_l < n; ++a_l) {
		// Jos vaihdetaan luvut a_l <-> a_l + 1
		int m0 = matka_4(Li[a_l - 1], Li[a_l], Li[a_l + 1], Li[a_l + 2]);
		int m1 = matka_4(Li[a_l - 1], Li[a_l + 1], Li[a_l], Li[a_l + 2]);
		if (m1 < m0) vaihtoehtoja += 1;
		if (m1 == m0) vaihtoehtoja0 += 1;

		// Jos vaihdetaan luku a_l indeksiin b_i
		int b_i = Li[a_l - 1];
		while (b_i != Li[a_l]) {
			vaihtoyritys(a_l, L[b_i]);
			b_i = b_i % n + 1;
		}
		b_i = b_i % n + 1;
		while (b_i != Li[a_l + 1] && b_i != Li[a_l - 1]) {
			vaihtoyritys(a_l, L[b_i]);
			b_i = b_i % n + 1;
		}
		if (b_i != Li[a_l - 1]) {
			vaihtoyritys(a_l, L[b_i]);
		}
	}

	if (vaihtoehtoja > 0) {
		printf("%d %d\n", matka(1, n) - 1, vaihtoehtoja);
	} else {
		printf("%d %d\n", matka(1, n), vaihtoehtoja0);
	}
}

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
2 2

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
99 4852

Test 3

Group: 1, 2, 3

Verdict:

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

correct output
16 5

user output
17 42

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
50 1198

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
53 1470

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
49 1022

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
48 965

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
46 858

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
2 2

Test 10

Group: 2, 3

Verdict:

input
5000
5000 4999 4998 4997 4996 4995 ...

correct output
4998 12492501

user output
4999 12492502

Test 11

Group: 2, 3

Verdict:

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

correct output
19 10

user output
20 32

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
191 2181

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
1379 510599

Test 14

Group: 2, 3

Verdict:

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

correct output
2511 436307

user output
2512 2957321

Test 15

Group: 2, 3

Verdict:

input
5000
3877 3972 1112 3669 1959 4640 ...

correct output
2497 417065

user output
2498 2931233

Test 16

Group: 2, 3

Verdict:

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

correct output
2518 426448

user output
2519 2974797

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
(empty)

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)