답안 #67352

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
67352 2018-08-14T05:36:04 Z Kmcode Xylophone (JOI18_xylophone) C++14
100 / 100
110 ms 1288 KB
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<unordered_set>
#include<unordered_map>

using namespace std;


//void solve(int N);
//int query(int s, int t);
//void answer(int i, int a);

#include "xylophone.h"


map<pair<int, int>, int> mp;
int ask(int a, int b){
	if (mp.count(make_pair(a, b))){
		return mp[make_pair(a, b)];
	}
	mp[make_pair(a, b)] = query(a, b);
	return mp[make_pair(a, b)];
}
int ans[5002];

set<int> usesd;
void solve(int N) {
	int mint = 1;
	int maxt = N;
	while (mint + 1 < maxt){
		int mid = (mint + maxt) >> 1;
		if (ask(1, mid) >= N-1){
			maxt = mid;
		}
		else{
			mint = mid + 1;
		}
	}
	if (ask(1, mint) >= N-1){
		maxt=mint;
	}
	else{
		mint = maxt;
	}
	int pos = mint;
	ans[pos] = N;
	for (int i = pos + 1; i <= N; i++){
		int dif = ask(i - 1, i);
		int n1 = ans[i-1] - dif;
		int n2 = ans[i - 1] + dif;
		if (n1<1||usesd.count(n1)){
			usesd.insert(n2);
			ans[i] = n2;
			continue;
		}
		if (n2 > N || usesd.count(n2)){
			usesd.insert(n1);
			ans[i] = n1;
			continue;
		}
		int F = ask(i-2, i);
		int mint = min(min(ans[i - 1], n1), ans[i - 2]);
		int maxt = max(max(ans[i - 1], n1), ans[i - 2]);
		if (maxt - mint == F){
			usesd.insert(n1);
			ans[i] = n1;
			continue;
		}
		usesd.insert(n2);
		ans[i] = n2;
	}for (int i = pos - 1; i >=1 ; i--){
		int dif = ask(i, i+1);
		int n1 = ans[i + 1] - dif;
		int n2 = ans[i + 1] + dif;
		if (n1<1 || usesd.count(n1)){
			usesd.insert(n2);
			ans[i] = n2;
			continue;
		}
		if (n2 > N || usesd.count(n2)){
			usesd.insert(n1);
			ans[i] = n1;
			continue;
		}
		int F = ask(i, i+2);
		int mint = min(min(ans[i + 1], n1), ans[i + 2]);
		int maxt = max(max(ans[i + 1], n1), ans[i + 2]);
		if (maxt - mint == F){
			usesd.insert(n1);
			ans[i] = n1;
			continue;
		}
		usesd.insert(n2);
		ans[i] = n2;
	}
	for (int i = 1; i <= N; i++) {
		answer(i, ans[i]);
	}

}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 3 ms 380 KB Output is correct
4 Correct 3 ms 440 KB Output is correct
5 Correct 3 ms 568 KB Output is correct
6 Correct 5 ms 568 KB Output is correct
7 Correct 4 ms 568 KB Output is correct
8 Correct 4 ms 568 KB Output is correct
9 Correct 4 ms 568 KB Output is correct
10 Correct 3 ms 568 KB Output is correct
11 Correct 4 ms 568 KB Output is correct
12 Correct 6 ms 568 KB Output is correct
13 Correct 3 ms 568 KB Output is correct
14 Correct 4 ms 568 KB Output is correct
15 Correct 5 ms 568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 3 ms 380 KB Output is correct
4 Correct 3 ms 440 KB Output is correct
5 Correct 3 ms 568 KB Output is correct
6 Correct 5 ms 568 KB Output is correct
7 Correct 4 ms 568 KB Output is correct
8 Correct 4 ms 568 KB Output is correct
9 Correct 4 ms 568 KB Output is correct
10 Correct 3 ms 568 KB Output is correct
11 Correct 4 ms 568 KB Output is correct
12 Correct 6 ms 568 KB Output is correct
13 Correct 3 ms 568 KB Output is correct
14 Correct 4 ms 568 KB Output is correct
15 Correct 5 ms 568 KB Output is correct
16 Correct 6 ms 568 KB Output is correct
17 Correct 10 ms 568 KB Output is correct
18 Correct 14 ms 568 KB Output is correct
19 Correct 19 ms 592 KB Output is correct
20 Correct 15 ms 676 KB Output is correct
21 Correct 18 ms 676 KB Output is correct
22 Correct 15 ms 676 KB Output is correct
23 Correct 17 ms 676 KB Output is correct
24 Correct 16 ms 676 KB Output is correct
25 Correct 17 ms 676 KB Output is correct
26 Correct 17 ms 732 KB Output is correct
27 Correct 22 ms 732 KB Output is correct
28 Correct 21 ms 732 KB Output is correct
29 Correct 10 ms 732 KB Output is correct
30 Correct 12 ms 732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 3 ms 380 KB Output is correct
4 Correct 3 ms 440 KB Output is correct
5 Correct 3 ms 568 KB Output is correct
6 Correct 5 ms 568 KB Output is correct
7 Correct 4 ms 568 KB Output is correct
8 Correct 4 ms 568 KB Output is correct
9 Correct 4 ms 568 KB Output is correct
10 Correct 3 ms 568 KB Output is correct
11 Correct 4 ms 568 KB Output is correct
12 Correct 6 ms 568 KB Output is correct
13 Correct 3 ms 568 KB Output is correct
14 Correct 4 ms 568 KB Output is correct
15 Correct 5 ms 568 KB Output is correct
16 Correct 6 ms 568 KB Output is correct
17 Correct 10 ms 568 KB Output is correct
18 Correct 14 ms 568 KB Output is correct
19 Correct 19 ms 592 KB Output is correct
20 Correct 15 ms 676 KB Output is correct
21 Correct 18 ms 676 KB Output is correct
22 Correct 15 ms 676 KB Output is correct
23 Correct 17 ms 676 KB Output is correct
24 Correct 16 ms 676 KB Output is correct
25 Correct 17 ms 676 KB Output is correct
26 Correct 17 ms 732 KB Output is correct
27 Correct 22 ms 732 KB Output is correct
28 Correct 21 ms 732 KB Output is correct
29 Correct 10 ms 732 KB Output is correct
30 Correct 12 ms 732 KB Output is correct
31 Correct 42 ms 868 KB Output is correct
32 Correct 68 ms 968 KB Output is correct
33 Correct 77 ms 1152 KB Output is correct
34 Correct 99 ms 1152 KB Output is correct
35 Correct 105 ms 1256 KB Output is correct
36 Correct 78 ms 1256 KB Output is correct
37 Correct 78 ms 1256 KB Output is correct
38 Correct 68 ms 1256 KB Output is correct
39 Correct 54 ms 1256 KB Output is correct
40 Correct 90 ms 1256 KB Output is correct
41 Correct 56 ms 1256 KB Output is correct
42 Correct 69 ms 1256 KB Output is correct
43 Correct 68 ms 1256 KB Output is correct
44 Correct 41 ms 1256 KB Output is correct
45 Correct 81 ms 1288 KB Output is correct
46 Correct 97 ms 1288 KB Output is correct
47 Correct 105 ms 1288 KB Output is correct
48 Correct 110 ms 1288 KB Output is correct
49 Correct 83 ms 1288 KB Output is correct
50 Correct 61 ms 1288 KB Output is correct
51 Correct 55 ms 1288 KB Output is correct
52 Correct 101 ms 1288 KB Output is correct
53 Correct 95 ms 1288 KB Output is correct
54 Correct 73 ms 1288 KB Output is correct
55 Correct 53 ms 1288 KB Output is correct
56 Correct 65 ms 1288 KB Output is correct
57 Correct 80 ms 1288 KB Output is correct
58 Correct 95 ms 1288 KB Output is correct
59 Correct 80 ms 1288 KB Output is correct
60 Correct 75 ms 1288 KB Output is correct