Submission #99764

# Submission time Handle Problem Language Result Execution time Memory
99764 2019-03-07T01:06:22 Z jasony123123 Xylophone (JOI18_xylophone) C++11
100 / 100
91 ms 504 KB
#define _CRT_SECURE_NO_WARNINGS
#include "xylophone.h"
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;

#define FOR(i,start,end) for(int i=start;i<(int)(end);i++)
#define FORE(i,start,end) for(int i=start;i<=(int)end;i++)
#define RFOR(i,start,end) for(int i = start; i>end; i--)
#define RFORE(i,start,end) for(int i = start; i>=end; i--)
#define all(a) a.begin(), a.end()
#define mt make_tuple
#define mp make_pair
#define v vector
#define sf scanf
#define pf printf
#define dvar(x) cout << #x << " := " << x << "\n"
#define darr(x,n) FOR(i,0,n) cout << #x << "[" << i << "]" << " := " << x[i] << "\n"

typedef long long ll;
typedef long double ld;
typedef pair<int, int > pii;
typedef pair<ll, ll> pll;
//template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> void minn(T &a, T b) { a = min(a, b); }
template<class T> void maxx(T &a, T b) { a = max(a, b); }

void io() {
#ifdef LOCAL_PROJECT 
	freopen("input.in", "r", stdin); freopen("output.out", "w", stdout);
#else 
//	freopen("rockers.in", "r", stdin); freopen("rockers.out", "w", stdout);
#endif 
	ios_base::sync_with_stdio(false); cin.tie(NULL);
}

const ll MOD = 1000000007LL;
const ll PRIME = 105943LL;
const ll INF = 1e18;
/***********************JOI Open 18 - xylophone*****************************/

pii get(v<int> &a) {
	pii mn = { INT_MAX, -1 }, mx = { INT_MIN, -1 };
	FOR(i, 0, a.size()) {
		minn(mn, { a[i], i });
		maxx(mx, { a[i], i });
	}
	return{ mn.second, mx.second };
}
void fix(v<int> &a, pii mxn) {
	int dif = 1 - a[mxn.first];
	FOR(i, 0, a.size()) a[i] += dif;
}
void solve(int N) {
	v<int> par(N);
	v<int> dif(N);
	par[0] = 1;
	dif[0] = query(0+1, 1+1);
	FOR(i, 0, N - 2) {
		dif[i + 1] = query(i + 1+1, i + 2+1);
		if (dif[i] + dif[i + 1] == query(i+1, i + 2+1))
			par[i + 1] = par[i];
		else
			par[i + 1] = par[i] * -1;
	}

	v<int> a(N), b(N);
	a[0] = 0, b[0] = 0;
	FOR(i, 1, N) {
		a[i] = a[i - 1] + dif[i - 1] * par[i - 1];
		b[i] = b[i - 1] + dif[i - 1] * par[i - 1] * -1;
	}
	pii posA = get(a), posB = get(b);
	if (posA.first < posA.second) {
		assert(posB.first > posB.second);
		fix(a, posA);
		FOR(i, 0, N)
			answer(i+1, a[i]);
	}
	else {
		assert(posB.first < posB.second);
		fix(b, posB);
		FOR(i, 0, N)
			answer(i+1, b[i]);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 3 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 3 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 304 KB Output is correct
16 Correct 5 ms 324 KB Output is correct
17 Correct 11 ms 384 KB Output is correct
18 Correct 9 ms 440 KB Output is correct
19 Correct 17 ms 256 KB Output is correct
20 Correct 17 ms 384 KB Output is correct
21 Correct 16 ms 256 KB Output is correct
22 Correct 19 ms 408 KB Output is correct
23 Correct 19 ms 256 KB Output is correct
24 Correct 21 ms 256 KB Output is correct
25 Correct 11 ms 324 KB Output is correct
26 Correct 17 ms 384 KB Output is correct
27 Correct 15 ms 304 KB Output is correct
28 Correct 17 ms 384 KB Output is correct
29 Correct 18 ms 376 KB Output is correct
30 Correct 17 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 3 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 304 KB Output is correct
16 Correct 5 ms 324 KB Output is correct
17 Correct 11 ms 384 KB Output is correct
18 Correct 9 ms 440 KB Output is correct
19 Correct 17 ms 256 KB Output is correct
20 Correct 17 ms 384 KB Output is correct
21 Correct 16 ms 256 KB Output is correct
22 Correct 19 ms 408 KB Output is correct
23 Correct 19 ms 256 KB Output is correct
24 Correct 21 ms 256 KB Output is correct
25 Correct 11 ms 324 KB Output is correct
26 Correct 17 ms 384 KB Output is correct
27 Correct 15 ms 304 KB Output is correct
28 Correct 17 ms 384 KB Output is correct
29 Correct 18 ms 376 KB Output is correct
30 Correct 17 ms 384 KB Output is correct
31 Correct 19 ms 416 KB Output is correct
32 Correct 52 ms 420 KB Output is correct
33 Correct 59 ms 376 KB Output is correct
34 Correct 86 ms 384 KB Output is correct
35 Correct 72 ms 376 KB Output is correct
36 Correct 78 ms 384 KB Output is correct
37 Correct 72 ms 384 KB Output is correct
38 Correct 55 ms 376 KB Output is correct
39 Correct 58 ms 356 KB Output is correct
40 Correct 91 ms 376 KB Output is correct
41 Correct 63 ms 360 KB Output is correct
42 Correct 79 ms 356 KB Output is correct
43 Correct 81 ms 384 KB Output is correct
44 Correct 80 ms 376 KB Output is correct
45 Correct 85 ms 352 KB Output is correct
46 Correct 39 ms 444 KB Output is correct
47 Correct 84 ms 376 KB Output is correct
48 Correct 62 ms 420 KB Output is correct
49 Correct 90 ms 384 KB Output is correct
50 Correct 64 ms 376 KB Output is correct
51 Correct 62 ms 384 KB Output is correct
52 Correct 48 ms 376 KB Output is correct
53 Correct 85 ms 376 KB Output is correct
54 Correct 80 ms 380 KB Output is correct
55 Correct 79 ms 376 KB Output is correct
56 Correct 37 ms 436 KB Output is correct
57 Correct 77 ms 384 KB Output is correct
58 Correct 79 ms 376 KB Output is correct
59 Correct 78 ms 424 KB Output is correct
60 Correct 73 ms 504 KB Output is correct