Submission #198577

# Submission time Handle Problem Language Result Execution time Memory
198577 2020-01-26T16:58:16 Z algorithm16 Xylophone (JOI18_xylophone) C++14
100 / 100
142 ms 512 KB
#include "xylophone.h"
#include<iostream>
#include<algorithm>
using namespace std;
int arr[5005],d[5005];
void solve(int N) {
	int x=0,ind1=0,ind2=0,mini=0,maxi=0;
	arr[0]=x;
	arr[1]=x+query(1,2);
	if(arr[1]>maxi) {
		maxi=arr[1];
		ind2=1;
	}
	if(arr[1]<mini) {
		mini=arr[1];
		ind1=1;
	}
	d[1]=arr[1];
	for(int i=2;i<N;i++) {
		int d1=query(i,i+1);
		if(query(i-1,i+1)==d[i-1]+d1) {
			if(arr[i-1]>arr[i-2]) arr[i]=arr[i-1]+d1;
			else arr[i]=arr[i-1]-d1;
		}
		else {
			if(arr[i-1]>arr[i-2]) arr[i]=arr[i-1]-d1;
			else arr[i]=arr[i-1]+d1;
		}
		d[i]=d1;
		if(arr[i]>maxi) {
			maxi=arr[i];
			ind2=i;
		}
		if(arr[i]<mini) {
			mini=arr[i];
			ind1=i;
		}
	}
	/*for(int i=0;i<N;i++) {
		cout << arr[i] << " " << d[i] << "\n";
	}*/
	if(ind1>ind2 or maxi+1-mini>N) {
		swap(mini,maxi);
		mini=-mini;
		maxi=-maxi;
		for(int i=1;i<=N;i++) {
			answer(i,-arr[i-1]+1-mini);
			//cout << -arr[i-1]+1-mini << " ";
		}
		//cout << "\n";
	}
	else {
		for(int i=1;i<=N;i++) {
			answer(i,arr[i-1]+1-mini);
			//cout << arr[i-1]+1-mini << " ";
		}
		//cout << "\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 248 KB Output is correct
2 Correct 5 ms 284 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 7 ms 380 KB Output is correct
5 Correct 6 ms 248 KB Output is correct
6 Correct 7 ms 248 KB Output is correct
7 Correct 7 ms 248 KB Output is correct
8 Correct 7 ms 248 KB Output is correct
9 Correct 7 ms 248 KB Output is correct
10 Correct 7 ms 248 KB Output is correct
11 Correct 7 ms 244 KB Output is correct
12 Correct 7 ms 508 KB Output is correct
13 Correct 7 ms 376 KB Output is correct
14 Correct 7 ms 248 KB Output is correct
15 Correct 7 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 248 KB Output is correct
2 Correct 5 ms 284 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 7 ms 380 KB Output is correct
5 Correct 6 ms 248 KB Output is correct
6 Correct 7 ms 248 KB Output is correct
7 Correct 7 ms 248 KB Output is correct
8 Correct 7 ms 248 KB Output is correct
9 Correct 7 ms 248 KB Output is correct
10 Correct 7 ms 248 KB Output is correct
11 Correct 7 ms 244 KB Output is correct
12 Correct 7 ms 508 KB Output is correct
13 Correct 7 ms 376 KB Output is correct
14 Correct 7 ms 248 KB Output is correct
15 Correct 7 ms 376 KB Output is correct
16 Correct 10 ms 376 KB Output is correct
17 Correct 10 ms 404 KB Output is correct
18 Correct 20 ms 248 KB Output is correct
19 Correct 28 ms 376 KB Output is correct
20 Correct 27 ms 376 KB Output is correct
21 Correct 24 ms 248 KB Output is correct
22 Correct 23 ms 248 KB Output is correct
23 Correct 23 ms 376 KB Output is correct
24 Correct 23 ms 380 KB Output is correct
25 Correct 15 ms 328 KB Output is correct
26 Correct 29 ms 248 KB Output is correct
27 Correct 22 ms 376 KB Output is correct
28 Correct 24 ms 248 KB Output is correct
29 Correct 25 ms 248 KB Output is correct
30 Correct 22 ms 248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 248 KB Output is correct
2 Correct 5 ms 284 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 7 ms 380 KB Output is correct
5 Correct 6 ms 248 KB Output is correct
6 Correct 7 ms 248 KB Output is correct
7 Correct 7 ms 248 KB Output is correct
8 Correct 7 ms 248 KB Output is correct
9 Correct 7 ms 248 KB Output is correct
10 Correct 7 ms 248 KB Output is correct
11 Correct 7 ms 244 KB Output is correct
12 Correct 7 ms 508 KB Output is correct
13 Correct 7 ms 376 KB Output is correct
14 Correct 7 ms 248 KB Output is correct
15 Correct 7 ms 376 KB Output is correct
16 Correct 10 ms 376 KB Output is correct
17 Correct 10 ms 404 KB Output is correct
18 Correct 20 ms 248 KB Output is correct
19 Correct 28 ms 376 KB Output is correct
20 Correct 27 ms 376 KB Output is correct
21 Correct 24 ms 248 KB Output is correct
22 Correct 23 ms 248 KB Output is correct
23 Correct 23 ms 376 KB Output is correct
24 Correct 23 ms 380 KB Output is correct
25 Correct 15 ms 328 KB Output is correct
26 Correct 29 ms 248 KB Output is correct
27 Correct 22 ms 376 KB Output is correct
28 Correct 24 ms 248 KB Output is correct
29 Correct 25 ms 248 KB Output is correct
30 Correct 22 ms 248 KB Output is correct
31 Correct 47 ms 332 KB Output is correct
32 Correct 59 ms 248 KB Output is correct
33 Correct 77 ms 248 KB Output is correct
34 Correct 101 ms 428 KB Output is correct
35 Correct 94 ms 376 KB Output is correct
36 Correct 107 ms 476 KB Output is correct
37 Correct 90 ms 376 KB Output is correct
38 Correct 119 ms 376 KB Output is correct
39 Correct 94 ms 360 KB Output is correct
40 Correct 93 ms 376 KB Output is correct
41 Correct 86 ms 376 KB Output is correct
42 Correct 124 ms 376 KB Output is correct
43 Correct 91 ms 376 KB Output is correct
44 Correct 119 ms 376 KB Output is correct
45 Correct 91 ms 512 KB Output is correct
46 Correct 92 ms 376 KB Output is correct
47 Correct 119 ms 376 KB Output is correct
48 Correct 126 ms 348 KB Output is correct
49 Correct 78 ms 376 KB Output is correct
50 Correct 141 ms 504 KB Output is correct
51 Correct 101 ms 376 KB Output is correct
52 Correct 133 ms 376 KB Output is correct
53 Correct 85 ms 376 KB Output is correct
54 Correct 142 ms 376 KB Output is correct
55 Correct 87 ms 376 KB Output is correct
56 Correct 80 ms 376 KB Output is correct
57 Correct 60 ms 408 KB Output is correct
58 Correct 90 ms 476 KB Output is correct
59 Correct 82 ms 504 KB Output is correct
60 Correct 106 ms 376 KB Output is correct