CSES - APIO 2015 - Results
Submission details
Task:Palembang Bridges
Sender:Olli
Submission time:2019-04-07 17:19:38 +0300
Language:C++
Status:READY
Result:17
Feedback
groupverdictscore
#1ACCEPTED8
#20
#3ACCEPTED9
#40
#50
Test results
testverdicttimegroup
#1ACCEPTED0.02 s1, 2details
#2ACCEPTED0.01 s1, 2details
#3ACCEPTED0.02 s1, 2details
#4ACCEPTED0.02 s1, 2details
#5ACCEPTED0.02 s1, 2details
#6ACCEPTED0.03 s1, 2details
#7ACCEPTED0.02 s1, 2details
#8ACCEPTED0.02 s1, 2details
#9ACCEPTED0.03 s1, 2details
#10ACCEPTED0.02 s1, 2details
#11ACCEPTED0.03 s1, 2details
#12--2details
#13--2details
#14--2details
#15--2details
#16--2details
#17--2details
#18--2details
#19--2details
#20--2details
#21--2details
#22ACCEPTED0.01 s3, 4, 5details
#23ACCEPTED0.02 s3, 4, 5details
#24ACCEPTED0.04 s3, 4, 5details
#25ACCEPTED0.02 s3, 4, 5details
#26ACCEPTED0.03 s3, 4, 5details
#27ACCEPTED0.03 s3, 4, 5details
#28ACCEPTED0.03 s3, 4, 5details
#29ACCEPTED0.03 s3, 4, 5details
#30ACCEPTED0.03 s3, 4, 5details
#31ACCEPTED0.03 s3, 4, 5details
#32ACCEPTED0.03 s3, 4, 5details
#33ACCEPTED0.03 s3, 4, 5details
#34--4, 5details
#35--4, 5details
#36--4, 5details
#37ACCEPTED0.25 s4, 5details
#38ACCEPTED1.08 s4, 5details
#39ACCEPTED0.40 s4, 5details
#40--4, 5details
#41--4, 5details
#42--4, 5details
#43--4, 5details
#44--4, 5details
#45--4, 5details
#46--5details
#47--5details
#48--5details
#49--5details
#50--5details
#51--5details
#52--5details
#53--5details
#54--5details
#55--5details
#56--5details
#57--5details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:34:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < v.size(); ++i) {
                  ~~^~~~~~~~~~
input/code.cpp:43:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int t = 0; t < v.size(); ++t) {
                    ~~^~~~~~~~~~
input/code.cpp:52:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < v.size(); ++i) {
                  ~~^~~~~~~~~~
input/code.cpp:53:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j = i+1; j < v.size(); ++j) {
                     ~~^~~~~~~~~~
input/code.cpp:68:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(int t = 0; t < v.size(); ++t) {
                      ~~^~~~~~~~~~

Code

#include <iostream>
#include <vector>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
 
vector<pll> v;
const ll INF = 1e18;
 
int main() {
	int k, n;
	cin >> k >> n;
	
	ll sum = 0;
	for(int i = 1; i <= n; ++i) {
		char f, s;
		ll F, S;
		cin >> f >> F >> s >> S;
		if(f == s) {
			sum += abs(F - S);
			continue;
		}
		++sum;
		v.push_back({F, S});
	}
	if(v.size() == 0) {
		cout << sum << "\n";
		return 0;
	}
	ll ans = INF;
	if(k == 1) {
		for(int i = 0; i < v.size(); ++i) {
			for(int j = 0; j < 2; ++j) {
				ll cand;
				if(j == 0) {
					cand = v[i].first;
				} else {
					cand = v[i].second;
				}
				ll cur = 0;
				for(int t = 0; t < v.size(); ++t) {
					cur += abs(v[t].first - cand);
					cur += abs(v[t].second - cand);
				}
	 
				ans = min(cur, ans);
			}
		}
	} else {
		for(int i = 0; i < v.size(); ++i) {
			for(int j = i+1; j < v.size(); ++j) {
				for(int ii = 0; ii < 2; ++ii) {
					for(int jj = 0; jj < 2; ++jj) {
						ll bri1; ll bri2;
						if(ii == 0) {
							bri1 = v[i].first;
						} else {
							bri1 = v[i].second;
						}
						if(jj == 0) {
							bri2 = v[j].first;
						} else {
							bri2 = v[j].second;
						}
						ll cur = 0;
						for(int t = 0; t < v.size(); ++t) {
							ll cand1 = abs(v[t].first - bri1) + abs(v[t].second - bri1);
							ll cand2 = abs(v[t].first - bri2) + abs(v[t].second - bri2);
							cur += min(cand1, cand2);
						}
						ans = min(cur, ans);
					}
				}
			}
		}
	}
	cout << ans + sum << "\n";
}

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

input
1 1
B 457748887 B 796098674

correct output
338349787

user output
338349787

Test 2

Group: 1, 2

Verdict: ACCEPTED

input
1 4
B 90 B 72
A 68 A 90
A 15 A 42
A 45 A 15

correct output
97

user output
97

Test 3

Group: 1, 2

Verdict: ACCEPTED

input
1 1000
A 0 B 1
A 1 B 0
A 0 B 1
B 0 A 0
...

correct output
1969

user output
1969

Test 4

Group: 1, 2

Verdict: ACCEPTED

input
1 1000
A 598380 B 85785
B 458027 A 842152
B 107714 A 39933
B 814225 A 328927
...

correct output
497512790

user output
497512790

Test 5

Group: 1, 2

Verdict: ACCEPTED

input
1 967
B 224488483 A 870079127
A 647780056 B 965306270
B 735321905 A 82275290
A 515414803 B 41707746
...

correct output
473798660797

user output
473798660797

Test 6

Group: 1, 2

Verdict: ACCEPTED

input
1 1000
A 1000000000 B 0
A 0 B 1000000000
B 0 A 1000000000
A 1000000000 B 0
...

correct output
1000000001000

user output
1000000001000

Test 7

Group: 1, 2

Verdict: ACCEPTED

input
1 1000
B 540773 A 324388
B 1033055 A 1254946
A 2804687 B 2012944
A 3827608 B 3200426
...

correct output
500006153353

user output
500006153353

Test 8

Group: 1, 2

Verdict: ACCEPTED

input
1 1000
A 1000000000 B 0
B 1 A 999999999
A 999999998 B 2
A 3 B 999999997
...

correct output
999999002000

user output
999999002000

Test 9

Group: 1, 2

Verdict: ACCEPTED

input
1 1000
B 306275120 A 306275122
A 526391763 B 526391756
B 152153706 A 152153714
B 275942345 A 275942351
...

correct output
499047189554

user output
499047189554

Test 10

Group: 1, 2

Verdict: ACCEPTED

input
1 1000
A 0 B 0
A 500000000 B 500000000
A 1000000000 B 1000000000
B 1000000000 A 1000000000
...

correct output
656000001000

user output
656000001000

Test 11

Group: 1, 2

Verdict: ACCEPTED

input
1 1000
A 500000001 B 500000000
B 499999999 A 499999998
B 1000000000 A 999999999
A 999999997 B 999999998
...

correct output
650999816318

user output
650999816318

Test 12

Group: 2

Verdict:

input
1 100000
A 1 B 1
B 1 A 0
A 0 B 1
A 0 B 0
...

correct output
199742

user output
(empty)

Test 13

Group: 2

Verdict:

input
1 100000
B 197201502 A 236725324
B 921493373 A 697882177
A 353914239 B 965797962
A 619173343 B 76946356
...

correct output
49896622370502

user output
(empty)

Test 14

Group: 2

Verdict:

input
1 89829
A 5656 B 4153
A 5854 B 8220
A 1115 B 5226
A 2446 B 3407
...

correct output
448956640

user output
(empty)

Test 15

Group: 2

Verdict:

input
1 58906
B 262032447 A 615361070
B 110761024 A 66611392
A 720901527 B 757393905
A 602897217 B 978610640
...

correct output
29450986771481

user output
(empty)

Test 16

Group: 2

Verdict:

input
1 100000
A 0 B 1000000000
B 1000000000 A 0
B 0 A 1000000000
A 1000000000 B 0
...

correct output
100000000100000

user output
(empty)

Test 17

Group: 2

Verdict:

input
1 100000
A 7461 B 9756
A 12548 B 14001
A 26302 B 21823
A 32953 B 37935
...

correct output
50000000610462

user output
(empty)

Test 18

Group: 2

Verdict:

input
1 100000
B 0 A 1000000000
A 1 B 999999999
B 2 A 999999998
B 999999997 A 3
...

correct output
99990000200000

user output
(empty)

Test 19

Group: 2

Verdict:

input
1 100000
B 400220047 A 400220048
A 14044122 B 14044122
A 45270242 B 45270245
B 994675758 A 994675758
...

correct output
50093795762125

user output
(empty)

Test 20

Group: 2

Verdict:

input
1 100000
B 1000000000 A 1000000000
A 500000000 B 500000000
B 1000000000 A 1000000000
A 0 B 0
...

correct output
66718000100000

user output
(empty)

Test 21

Group: 2

Verdict:

input
1 100000
A 1 B 0
A 2 B 3
A 5 B 4
B 500000000 A 500000001
...

correct output
66771748924060

user output
(empty)

Test 22

Group: 3, 4, 5

Verdict: ACCEPTED

input
2 1
B 686779001 B 298011277

correct output
388767724

user output
388767724

Test 23

Group: 3, 4, 5

Verdict: ACCEPTED

input
2 4
B 85 B 16
A 88 A 72
A 13 A 8
B 5 B 68

correct output
153

user output
153

Test 24

Group: 3, 4, 5

Verdict: ACCEPTED

input
2 100
B 1 A 1
B 1 A 1
B 0 A 1
B 0 A 1
...

correct output
135

user output
135

Test 25

Group: 3, 4, 5

Verdict: ACCEPTED

input
2 100
A 80895559 B 504694055
A 550515244 B 637123084
A 824581457 B 293902519
A 65276676 B 906746170
...

correct output
39400461569

user output
39400461569

Test 26

Group: 3, 4, 5

Verdict: ACCEPTED

input
2 61
A 882469 B 477162
A 276781 B 782546
B 696587 A 81196
B 573379 A 354344
...

correct output
23533490

user output
23533490

Test 27

Group: 3, 4, 5

Verdict: ACCEPTED

input
2 24
B 246060972 B 745635077
A 805134171 A 471810707
B 252217199 B 377725124
B 793449133 B 882787637
...

correct output
7222227740

user output
7222227740

Test 28

Group: 3, 4, 5

Verdict: ACCEPTED

input
2 100
A 0 B 1000000000
B 1000000000 A 0
B 1000000000 A 0
B 1000000000 A 0
...

correct output
100000000100

user output
100000000100

Test 29

Group: 3, 4, 5

Verdict: ACCEPTED

input
2 100
B 7277035 A 2363507
A 14481349 B 18074096
A 23772733 B 25361815
B 38014142 A 39221304
...

correct output
25052929066

user output
25052929066

Test 30

Group: 3, 4, 5

Verdict: ACCEPTED

input
2 100
A 0 B 1000000000
A 1 B 999999999
B 999999998 A 2
B 3 A 999999997
...

correct output
99999990200

user output
99999990200

Test 31

Group: 3, 4, 5

Verdict: ACCEPTED

input
2 100
B 229133622 A 229133615
A 286436586 B 286436582
A 177918170 B 177918177
A 928539152 B 928539147
...

correct output
25763506210

user output
25763506210

Test 32

Group: 3, 4, 5

Verdict: ACCEPTED

input
2 100
B 1000000000 A 1000000000
B 1000000000 A 1000000000
B 500000000 A 500000000
B 0 A 0
...

correct output
30000000100

user output
30000000100

Test 33

Group: 3, 4, 5

Verdict: ACCEPTED

input
2 100
B 1 A 0
A 500000000 B 500000001
A 3 B 2
B 999999999 A 1000000000
...

correct output
30000000838

user output
30000000838

Test 34

Group: 4, 5

Verdict:

input
2 1000
B 1 A 0
A 0 B 0
B 1 B 1
B 1 A 1
...

correct output
1488

user output
(empty)

Test 35

Group: 4, 5

Verdict:

input
2 1000
A 55 B 99
A 49 B 36
B 56 A 43
B 30 A 21
...

correct output
40742

user output
(empty)

Test 36

Group: 4, 5

Verdict:

input
2 993
B 856945560 A 98103483
B 25758143 A 606399727
B 765461653 A 689513816
A 880180326 B 997125325
...

correct output
379585137648

user output
(empty)

Test 37

Group: 4, 5

Verdict: ACCEPTED

input
2 328
A 0 B 0
B 0 A 1
B 1 A 1
A 1 B 1
...

correct output
475

user output
475

Test 38

Group: 4, 5

Verdict: ACCEPTED

input
2 543
A 84 B 67
B 8 A 52
A 71 B 4
A 37 B 4
...

correct output
20775

user output
20775

Test 39

Group: 4, 5

Verdict: ACCEPTED

input
2 385
A 286133 B 305048
B 3019 A 211390
A 680205 B 943092
A 717521 B 2626
...

correct output
150638388

user output
150638388

Test 40

Group: 4, 5

Verdict:

input
2 1000
A 1000000000 B 0
B 0 A 1000000000
B 1000000000 A 0
B 0 A 1000000000
...

correct output
1000000001000

user output
(empty)

Test 41

Group: 4, 5

Verdict:

input
2 1000
A 337683 B 154786
A 1080479 B 1653867
A 2096703 B 2014255
A 3269807 B 3378028
...

correct output
250005306826

user output
(empty)

Test 42

Group: 4, 5

Verdict:

input
2 1000
B 0 A 1000000000
A 1 B 999999999
A 2 B 999999998
B 999999997 A 3
...

correct output
999999002000

user output
(empty)

Test 43

Group: 4, 5

Verdict:

input
2 1000
B 487537672 A 487537682
A 702434952 B 702434943
A 924937477 B 924937478
A 438742511 B 438742503
...

correct output
248460366924

user output
(empty)

Test 44

Group: 4, 5

Verdict:

input
2 1000
B 500000000 A 500000000
A 0 B 0
B 0 A 0
A 1000000000 B 1000000000
...

correct output
323000001000

user output
(empty)

Test 45

Group: 4, 5

Verdict:

input
2 1000
B 0 A 1
A 500000001 B 500000000
A 500000003 B 500000002
A 499999996 B 499999997
...

correct output
328999889746

user output
(empty)

Test 46

Group: 5

Verdict:

input
2 100000
A 1 B 0
A 0 B 1
A 1 B 1
B 0 A 0
...

correct output
150253

user output
(empty)

Test 47

Group: 5

Verdict:

input
2 100000
A 57 B 62
A 81 B 84
A 29 B 62
B 84 A 93
...

correct output
4054233

user output
(empty)

Test 48

Group: 5

Verdict:

input
2 100000
B 376633 A 401436
B 929991 A 301184
A 594140 B 788956
A 269074 B 579617
...

correct output
39017925999

user output
(empty)

Test 49

Group: 5

Verdict:

input
2 100000
B 957291126 A 804724561
B 643453098 A 837804172
A 968031915 B 244064467
B 806058719 A 777366893
...

correct output
39023916424909

user output
(empty)

Test 50

Group: 5

Verdict:

input
2 100000
A 765748723 B 736102973
B 30767265 A 892885151
A 438782247 B 603304522
B 556204289 A 731709903
...

correct output
39003712943872

user output
(empty)

Test 51

Group: 5

Verdict:

input
2 52924
B 214946095 A 74195083
B 144150299 A 848919272
A 632662655 B 429803598
B 132419689 A 911407267
...

correct output
20674441803953

user output
(empty)

Test 52

Group: 5

Verdict:

input
2 100000
B 1000000000 A 0
B 0 A 1000000000
B 1000000000 A 0
A 0 B 1000000000
...

correct output
100000000100000

user output
(empty)

Test 53

Group: 5

Verdict:

input
2 100000
A 9838 B 2205
A 15278 B 17118
A 25088 B 22794
B 31319 A 39536
...

correct output
25000001294215

user output
(empty)

Test 54

Group: 5

Verdict:

input
2 100000
A 0 B 1000000000
A 1 B 999999999
A 2 B 999999998
A 999999997 B 3
...

correct output
99990000200000

user output
(empty)

Test 55

Group: 5

Verdict:

input
2 100000
B 69772706 A 69772713
A 701457803 B 701457802
B 526650518 A 526650528
B 44276587 A 44276586
...

correct output
25049824938170

user output
(empty)

Test 56

Group: 5

Verdict:

input
2 100000
A 0 B 0
A 500000000 B 500000000
B 0 A 0
A 0 B 0
...

correct output
33071000100000

user output
(empty)

Test 57

Group: 5

Verdict:

input
2 100000
B 999999999 A 1000000000
A 0 B 1
B 500000001 A 500000000
B 2 A 3
...

correct output
33278897746546

user output
(empty)