답안 #67186

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
67186 2018-08-13T13:58:32 Z radoslav11 Xylophone (JOI18_xylophone) C++14
100 / 100
132 ms 720 KB
#include <bits/stdc++.h>
#include "xylophone.h"
//#include "Lgrader.cpp"
 
using namespace std;
template<class T, class T2> inline int chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline int chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const int MAXN = (5042);
 
int n;
 
bool check(vector<int> p)
{
	vector<bool> used(p.size(), 0);
 
	int pmax, pmin, mx = -1, mn = (int)1e9;
	for(int i = 0; i < n; i++)
	{
		if(chkmax(mx, p[i])) pmax = i;
		if(chkmin(mn, p[i])) pmin = i;
	
		if(p[i] >= n) return false;
		if(used[p[i]]) return false;
		used[p[i]] = true;
	}
 
	if((mx != (int)p.size() - 1) || mn != 0 || pmax < pmin)
		return false;
 
	return true;
}
 
int ask(int l, int r) { return query(l + 1, r + 1); }
 
void fix(vector<int> &p)
{
	int mn = 1e9;
	for(int &x: p)
		chkmin(mn, x);
 
	for(int &x: p)
		x += -mn;
 
	//for(int x: p)
	//	cerr << x << " ";
	//cerr << endl << flush;
}
 
int ask2[MAXN], ask3[MAXN];
 
int my_ask(int a, int b, int c)
{
	int ret = 0;
	
	chkmax(ret, a - b);
	chkmax(ret, b - a);
 
	chkmax(ret, a - c);
	chkmax(ret, c - a);
 
	chkmax(ret, c - b);
	chkmax(ret, b - c);
 
	return ret;
}
 
void solve(int N) 
{
	n = N;
 
	for(int i = 0; i + 1 < n; i++) ask2[i] = ask(i, i + 1);
	for(int i = 0; i + 2 < n; i++) ask3[i] = ask(i, i + 2);
 
	vector<int> A(n, 0);
	A[0] = 0;
	A[1] = ask2[0];
 
	for(int i = 2; i < n; i++)
	{
		if(my_ask(A[i - 2], A[i - 1], A[i - 1] + ask2[i - 1]) == ask3[i - 2]) A[i] = A[i - 1] + ask2[i - 1];
		else A[i] = A[i - 1] - ask2[i - 1];
	}
 
	fix(A);
	if(check(A))
	{
		for(int i = 0; i < n; i++)
			answer(i + 1, A[i] + 1);
		return;
	}
 
	A.assign(n, 0);
	A[0] = 0;
	A[1] = -ask2[0];
 
	for(int i = 2; i < n; i++)
	{
		if(my_ask(A[i - 2], A[i - 1], A[i - 1] + ask2[i - 1]) == ask3[i - 2]) A[i] = A[i - 1] + ask2[i - 1];
		else A[i] = A[i - 1] - ask2[i - 1];
	}
 
	fix(A);
	if(check(A))
	{
		for(int i = 0; i < n; i++)
			answer(i + 1, A[i] + 1);
		return;
	}
}

Compilation message

xylophone.cpp: In function 'bool check(std::vector<int>)':
xylophone.cpp:27:42: warning: 'pmin' may be used uninitialized in this function [-Wmaybe-uninitialized]
  if((mx != (int)p.size() - 1) || mn != 0 || pmax < pmin)
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
xylophone.cpp:27:42: warning: 'pmax' may be used uninitialized in this function [-Wmaybe-uninitialized]
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 308 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 3 ms 420 KB Output is correct
5 Correct 4 ms 420 KB Output is correct
6 Correct 4 ms 496 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 4 ms 512 KB Output is correct
9 Correct 5 ms 568 KB Output is correct
10 Correct 7 ms 568 KB Output is correct
11 Correct 5 ms 568 KB Output is correct
12 Correct 5 ms 568 KB Output is correct
13 Correct 4 ms 568 KB Output is correct
14 Correct 5 ms 568 KB Output is correct
15 Correct 4 ms 568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 308 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 3 ms 420 KB Output is correct
5 Correct 4 ms 420 KB Output is correct
6 Correct 4 ms 496 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 4 ms 512 KB Output is correct
9 Correct 5 ms 568 KB Output is correct
10 Correct 7 ms 568 KB Output is correct
11 Correct 5 ms 568 KB Output is correct
12 Correct 5 ms 568 KB Output is correct
13 Correct 4 ms 568 KB Output is correct
14 Correct 5 ms 568 KB Output is correct
15 Correct 4 ms 568 KB Output is correct
16 Correct 8 ms 568 KB Output is correct
17 Correct 11 ms 568 KB Output is correct
18 Correct 18 ms 568 KB Output is correct
19 Correct 21 ms 572 KB Output is correct
20 Correct 19 ms 572 KB Output is correct
21 Correct 18 ms 572 KB Output is correct
22 Correct 13 ms 572 KB Output is correct
23 Correct 26 ms 580 KB Output is correct
24 Correct 19 ms 580 KB Output is correct
25 Correct 15 ms 580 KB Output is correct
26 Correct 14 ms 580 KB Output is correct
27 Correct 15 ms 580 KB Output is correct
28 Correct 10 ms 580 KB Output is correct
29 Correct 11 ms 580 KB Output is correct
30 Correct 16 ms 580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 308 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 3 ms 420 KB Output is correct
5 Correct 4 ms 420 KB Output is correct
6 Correct 4 ms 496 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 4 ms 512 KB Output is correct
9 Correct 5 ms 568 KB Output is correct
10 Correct 7 ms 568 KB Output is correct
11 Correct 5 ms 568 KB Output is correct
12 Correct 5 ms 568 KB Output is correct
13 Correct 4 ms 568 KB Output is correct
14 Correct 5 ms 568 KB Output is correct
15 Correct 4 ms 568 KB Output is correct
16 Correct 8 ms 568 KB Output is correct
17 Correct 11 ms 568 KB Output is correct
18 Correct 18 ms 568 KB Output is correct
19 Correct 21 ms 572 KB Output is correct
20 Correct 19 ms 572 KB Output is correct
21 Correct 18 ms 572 KB Output is correct
22 Correct 13 ms 572 KB Output is correct
23 Correct 26 ms 580 KB Output is correct
24 Correct 19 ms 580 KB Output is correct
25 Correct 15 ms 580 KB Output is correct
26 Correct 14 ms 580 KB Output is correct
27 Correct 15 ms 580 KB Output is correct
28 Correct 10 ms 580 KB Output is correct
29 Correct 11 ms 580 KB Output is correct
30 Correct 16 ms 580 KB Output is correct
31 Correct 34 ms 580 KB Output is correct
32 Correct 54 ms 688 KB Output is correct
33 Correct 114 ms 688 KB Output is correct
34 Correct 45 ms 692 KB Output is correct
35 Correct 54 ms 692 KB Output is correct
36 Correct 39 ms 692 KB Output is correct
37 Correct 54 ms 692 KB Output is correct
38 Correct 84 ms 692 KB Output is correct
39 Correct 66 ms 692 KB Output is correct
40 Correct 58 ms 700 KB Output is correct
41 Correct 93 ms 700 KB Output is correct
42 Correct 86 ms 700 KB Output is correct
43 Correct 97 ms 700 KB Output is correct
44 Correct 89 ms 700 KB Output is correct
45 Correct 95 ms 704 KB Output is correct
46 Correct 78 ms 720 KB Output is correct
47 Correct 75 ms 720 KB Output is correct
48 Correct 95 ms 720 KB Output is correct
49 Correct 121 ms 720 KB Output is correct
50 Correct 61 ms 720 KB Output is correct
51 Correct 106 ms 720 KB Output is correct
52 Correct 94 ms 720 KB Output is correct
53 Correct 88 ms 720 KB Output is correct
54 Correct 100 ms 720 KB Output is correct
55 Correct 49 ms 720 KB Output is correct
56 Correct 99 ms 720 KB Output is correct
57 Correct 100 ms 720 KB Output is correct
58 Correct 132 ms 720 KB Output is correct
59 Correct 96 ms 720 KB Output is correct
60 Correct 53 ms 720 KB Output is correct