답안 #384199

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
384199 2021-03-31T19:04:47 Z pure_mem Swap (BOI16_swap) C++14
68 / 100
38 ms 4844 KB
#include <bits/stdc++.h>

#define X first
#define Y second
#define MP make_pair
#define ll long long

using namespace std;

const int N = 2e5 + 12;
const int mod = 1e9 + 7;

int n, p[N];
map< pair<int, int>, int > dp;

int get(int v, int val){
	if(dp.count(MP(v, val)))
		return dp[MP(v, val)];
	if(val < min(p[v * 2], p[v * 2 + 1]))
		return v;
	if(p[v * 2] < p[v * 2 + 1])
		return dp[MP(v, val)] = get(v * 2, val);
	int mn = min(p[v * 2], val), mx = max(p[v * 2], mx);
	if(get(v * 2, mn) < get(v * 2 + 1, mn)){
		if(mn == val)
			return dp[MP(v, val)] = get(v * 2, val);
		else
			return dp[MP(v, val)] = get(v * 2 + 1, val); 	
	}
	else{
	    if(mn != val)
			return dp[MP(v, val)] = get(v * 2, val);
		else
			return dp[MP(v, val)] = get(v * 2 + 1, val);
	}
}

int main () {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	memset(p, 0x3f, sizeof(p));
	cin >> n;
	for(int i = 1;i <= n;i++)
		cin >> p[i];
    for(int i = 1;i <= n;i++){
    	if(p[i * 2 + 1] < min(p[i], p[i * 2])){
    		int mn = min(p[i], p[i * 2]), mx = max(p[i], p[i * 2]);
    		p[i] = p[i * 2 + 1], p[i * 2] = mx, p[i * 2 + 1] = mn;
    		if(get(i * 2, mn) < get(i * 2 + 1, mn))
    			p[i * 2] = mn, p[i * 2 + 1] = mx;
    	}
    	else if(p[i * 2] < p[i]){
    		swap(p[i], p[i * 2]);
    	}
    	cout << p[i] << " ";
    }
}                               
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1132 KB Output is correct
2 Correct 2 ms 1132 KB Output is correct
3 Correct 1 ms 1132 KB Output is correct
4 Correct 2 ms 1132 KB Output is correct
5 Correct 2 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1132 KB Output is correct
2 Correct 2 ms 1132 KB Output is correct
3 Correct 1 ms 1132 KB Output is correct
4 Correct 2 ms 1132 KB Output is correct
5 Correct 2 ms 1132 KB Output is correct
6 Correct 2 ms 1132 KB Output is correct
7 Correct 2 ms 1132 KB Output is correct
8 Correct 1 ms 1132 KB Output is correct
9 Correct 2 ms 1132 KB Output is correct
10 Correct 2 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1132 KB Output is correct
2 Correct 2 ms 1132 KB Output is correct
3 Correct 1 ms 1132 KB Output is correct
4 Correct 2 ms 1132 KB Output is correct
5 Correct 2 ms 1132 KB Output is correct
6 Correct 2 ms 1132 KB Output is correct
7 Correct 2 ms 1132 KB Output is correct
8 Correct 1 ms 1132 KB Output is correct
9 Correct 2 ms 1132 KB Output is correct
10 Correct 2 ms 1132 KB Output is correct
11 Correct 2 ms 1132 KB Output is correct
12 Correct 2 ms 1132 KB Output is correct
13 Correct 2 ms 1132 KB Output is correct
14 Correct 2 ms 1132 KB Output is correct
15 Correct 2 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1132 KB Output is correct
2 Correct 2 ms 1132 KB Output is correct
3 Correct 1 ms 1132 KB Output is correct
4 Correct 2 ms 1132 KB Output is correct
5 Correct 2 ms 1132 KB Output is correct
6 Correct 2 ms 1132 KB Output is correct
7 Correct 2 ms 1132 KB Output is correct
8 Correct 1 ms 1132 KB Output is correct
9 Correct 2 ms 1132 KB Output is correct
10 Correct 2 ms 1132 KB Output is correct
11 Correct 2 ms 1132 KB Output is correct
12 Correct 2 ms 1132 KB Output is correct
13 Correct 2 ms 1132 KB Output is correct
14 Correct 2 ms 1132 KB Output is correct
15 Correct 2 ms 1132 KB Output is correct
16 Correct 18 ms 2668 KB Output is correct
17 Correct 18 ms 2668 KB Output is correct
18 Correct 18 ms 2668 KB Output is correct
19 Correct 38 ms 4844 KB Output is correct
20 Correct 37 ms 4844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1132 KB Output is correct
2 Correct 2 ms 1132 KB Output is correct
3 Correct 1 ms 1132 KB Output is correct
4 Correct 2 ms 1132 KB Output is correct
5 Correct 2 ms 1132 KB Output is correct
6 Correct 2 ms 1132 KB Output is correct
7 Correct 2 ms 1132 KB Output is correct
8 Correct 1 ms 1132 KB Output is correct
9 Correct 2 ms 1132 KB Output is correct
10 Correct 2 ms 1132 KB Output is correct
11 Correct 2 ms 1132 KB Output is correct
12 Correct 2 ms 1132 KB Output is correct
13 Correct 2 ms 1132 KB Output is correct
14 Correct 2 ms 1132 KB Output is correct
15 Correct 2 ms 1132 KB Output is correct
16 Correct 18 ms 2668 KB Output is correct
17 Correct 18 ms 2668 KB Output is correct
18 Correct 18 ms 2668 KB Output is correct
19 Correct 38 ms 4844 KB Output is correct
20 Correct 37 ms 4844 KB Output is correct
21 Runtime error 22 ms 3308 KB Execution killed with signal 11
22 Halted 0 ms 0 KB -