CSES - Siperia opettaa 3.0 - Results
Submission details
Task:Jump
Sender:zxc
Submission time:2016-07-29 14:44:53 +0300
Language:C++
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.06 sdetails
#2ACCEPTED0.06 sdetails
#3ACCEPTED0.98 sdetails
#4ACCEPTED0.95 sdetails
#5ACCEPTED0.94 sdetails
#6ACCEPTED0.97 sdetails
#7ACCEPTED0.94 sdetails
#8ACCEPTED1.01 sdetails
#9ACCEPTED1.00 sdetails
#10ACCEPTED0.95 sdetails
#11ACCEPTED0.97 sdetails
#12ACCEPTED0.99 sdetails
#13ACCEPTED0.92 sdetails
#14ACCEPTED0.96 sdetails
#15ACCEPTED0.94 sdetails
#16ACCEPTED0.50 sdetails
#17ACCEPTED0.53 sdetails
#18ACCEPTED0.21 sdetails
#19ACCEPTED0.29 sdetails
#20ACCEPTED0.14 sdetails
#21ACCEPTED0.17 sdetails
#22ACCEPTED0.18 sdetails
#23ACCEPTED0.18 sdetails
#24ACCEPTED0.17 sdetails
#25ACCEPTED0.16 sdetails
#26ACCEPTED0.17 sdetails
#27ACCEPTED0.17 sdetails
#28ACCEPTED0.17 sdetails
#29ACCEPTED0.16 sdetails
#30ACCEPTED0.17 sdetails
#31ACCEPTED0.18 sdetails
#32ACCEPTED0.18 sdetails
#33ACCEPTED0.17 sdetails
#34ACCEPTED0.17 sdetails
#35ACCEPTED0.17 sdetails
#36ACCEPTED0.17 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:28:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < jo.size(); ++i){
                                ^

Code

#include <bits/stdc++.h>
using namespace std;
int t[222];
const int N = 22000;
const int MN = 1e4+100;
const int R = 30000;
int dp[202020];
int main() {
    int n;
    cin>>n;
    for(int i = 0; i < n; ++i) {
	cin>>t[i];
    }
    vector<int> mov;
    for(int i = 0; i < n; ++i) {
	for(int j = i+1; j < n; ++j) {
	    mov.push_back(abs(t[i]-t[j]));
	}
    }
    sort(mov.begin(), mov.end());
    mov.erase(unique(mov.begin(), mov.end()), mov.end());
    //for(auto y: mov) cout<<y<<' ';
    //cout<<'\n';
    vector<int> jo;
    jo.push_back(0);
    for(int i = 0; i< 202020; ++i) dp[i] = 1e9;
    dp[R] = 0;
    for(int i = 0; i < jo.size(); ++i){
	int x = jo[i];
	for(int y: mov) {
	    for(int j = 0; j < 2; ++j) {
		int ux = x;
		if(j == 0) ux += 2*y;
		else ux -= 2*y;
		if(abs(ux) < N && dp[ux+R] == 1e9) {
		    dp[ux+R] = dp[x+R]+1;
		    jo.push_back(ux);
		}
	    }
	}
    }
    /*
    for(int i = 0; i < 10; ++i) {
	cout<<dp[R+i]<<' ';
    }
    cout<<'\n';
    return 0;
    */
    int q;
    cin>>q;
    for(int i = 0; i < q; ++i) {
	int s,tt;
	cin>>s>>tt;
	int ans = 1e9;
	ans = dp[R+abs(s-tt)]*2;
	//cout<<abs(s-tt)<<'\n';
	for(int i = 0; i < n; ++i) {
	    int ux = 2*t[i] - s;
	    //cout<<abs(ux-tt)<<'\n';
	    if(abs(ux-tt) < N) {
		ans = min(ans, 1 + dp[R+abs(ux-tt)]*2);
	    }
	}
	for(int i = 0; i < n; ++i) {
	    int ux = 2*t[i] - tt;
	    if(abs(ux-tt) < N) {
		ans = min(ans, 1 + dp[R+abs(ux-s)]*2);
	    }
	}
	if(ans >= 1e9) cout<<-1<<'\n';
	else
	cout<<ans<<'\n';
    }

}

Test details

Test 1

Verdict: ACCEPTED

input
4
1
2
4
7
...

correct output
-1
-1
2
2
-1
...

user output
-1
-1
2
2
-1
...

Test 2

Verdict: ACCEPTED

input
4
1
2
6
10
...

correct output
-1
1
2
-1
1
...

user output
-1
1
2
-1
1
...

Test 3

Verdict: ACCEPTED

input
200
12
14
30
101
...

correct output
2
2
1
2
2
...

user output
2
2
1
2
2
...

Test 4

Verdict: ACCEPTED

input
200
13
22
196
211
...

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

Test 5

Verdict: ACCEPTED

input
200
10
41
107
167
...

correct output
2
1
2
2
2
...

user output
2
1
2
2
2
...

Test 6

Verdict: ACCEPTED

input
200
91
166
275
278
...

correct output
2
2
2
3
2
...

user output
2
2
2
3
2
...

Test 7

Verdict: ACCEPTED

input
200
18
104
138
182
...

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

Test 8

Verdict: ACCEPTED

input
200
115
144
272
274
...

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

Test 9

Verdict: ACCEPTED

input
200
84
177
208
219
...

correct output
2
2
2
2
1
...

user output
2
2
2
2
1
...

Test 10

Verdict: ACCEPTED

input
200
96
131
228
258
...

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

Test 11

Verdict: ACCEPTED

input
200
0
77
132
189
...

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

Test 12

Verdict: ACCEPTED

input
200
3
33
74
118
...

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

Test 13

Verdict: ACCEPTED

input
200
95
162
171
448
...

correct output
-1
-1
2
2
2
...

user output
-1
-1
2
2
2
...

Test 14

Verdict: ACCEPTED

input
200
32
72
229
239
...

correct output
2
-1
2
2
-1
...

user output
2
-1
2
2
-1
...

Test 15

Verdict: ACCEPTED

input
200
30
124
136
176
...

correct output
2
-1
2
-1
2
...

user output
2
-1
2
-1
2
...

Test 16

Verdict: ACCEPTED

input
116
34
68
85
87
...

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

Test 17

Verdict: ACCEPTED

input
112
64
264
268
298
...

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

Test 18

Verdict: ACCEPTED

input
64
14
15
19
31
...

correct output
8
6
10
4
6
...

user output
8
6
10
4
6
...

Test 19

Verdict: ACCEPTED

input
200
0
1
2
3
...

correct output
14
14
8
6
40
...

user output
14
14
8
6
40
...

Test 20

Verdict: ACCEPTED

input
1
2231
100000
16 2
6 8
...

correct output
-1
-1
-1
-1
-1
...

user output
-1
-1
-1
-1
-1
...

Test 21

Verdict: ACCEPTED

input
2
1091
2342
100000
1588 4004
...

correct output
-1
-1
-1
-1
-1
...

user output
-1
-1
-1
-1
-1
...

Test 22

Verdict: ACCEPTED

input
3
144
151
440
100000
...

correct output
168
99
87
262
16
...

user output
168
99
87
262
16
...

Test 23

Verdict: ACCEPTED

input
4
2388
2979
6715
8029
...

correct output
10
52
47
56
77
...

user output
10
52
47
56
77
...

Test 24

Verdict: ACCEPTED

input
5
1371
1946
6455
6889
...

correct output
24
6
15
25
26
...

user output
24
6
15
25
26
...

Test 25

Verdict: ACCEPTED

input
6
1026
1031
4929
5038
...

correct output
18
9
11
12
8
...

user output
18
9
11
12
8
...

Test 26

Verdict: ACCEPTED

input
7
21
44
60
70
...

correct output
16
20
16
20
10
...

user output
16
20
16
20
10
...

Test 27

Verdict: ACCEPTED

input
8
95
627
710
784
...

correct output
6
4
5
5
6
...

user output
6
4
5
5
6
...

Test 28

Verdict: ACCEPTED

input
9
48
209
791
920
...

correct output
3
4
3
6
6
...

user output
3
4
3
6
6
...

Test 29

Verdict: ACCEPTED

input
10
814
1017
1217
3259
...

correct output
4
6
6
4
6
...

user output
4
6
6
4
6
...

Test 30

Verdict: ACCEPTED

input
2
6748
9615
100000
6956 7730
...

correct output
-1
-1
-1
-1
-1
...

user output
-1
-1
-1
-1
-1
...

Test 31

Verdict: ACCEPTED

input
2
2955
5079
100000
5049 3601
...

correct output
-1
-1
-1
-1
-1
...

user output
-1
-1
-1
-1
-1
...

Test 32

Verdict: ACCEPTED

input
2
8591
9235
100000
6759 9705
...

correct output
-1
-1
-1
-1
-1
...

user output
-1
-1
-1
-1
-1
...

Test 33

Verdict: ACCEPTED

input
2
1847
2965
100000
6674 4858
...

correct output
-1
-1
-1
-1
-1
...

user output
-1
-1
-1
-1
-1
...

Test 34

Verdict: ACCEPTED

input
2
2033
7688
100000
4427 4007
...

correct output
-1
-1
-1
-1
-1
...

user output
-1
-1
-1
-1
-1
...

Test 35

Verdict: ACCEPTED

input
2
0
1
100000
3190 5237
...

correct output
-1
-1
-1
4232
4266
...

user output
-1
-1
-1
4232
4266
...

Test 36

Verdict: ACCEPTED

input
2
9999
10000
100000
4761 947
...

correct output
3814
1612
-1
-1
-1
...

user output
3814
1612
-1
-1
-1
...