답안 #258508

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
258508 2020-08-06T05:12:41 Z 임성재(#5051) Swap (BOI16_swap) C++17
0 / 100
9 ms 10112 KB
#include<bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(false); cin.tie(NULL)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define all(v) (v).begin(), (v).end()
#define pre(a) cout<<fixed; cout.precision(a)
#define mp make_pair

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;

int n;
int a[100010];
bool chk[100010];
int ans[100010];
set<int> v[100010];

int main() {
	fast;

	cin >> n;

	for(int i=1; i<=n; i++) {
		cin >> a[i];
		v[i].insert(a[i]);
	}

	for(int i=1; i<=n; i++) {
		int x = inf;
		for(auto j : v[i]) {
			if(chk[j]) continue;

			x = min(x, j);
		}

		if(2 * i <= n) x = min(x, a[2*i]);
		
		if(2*i+1 <= n) {
			if(a[i*2+1] < x) {
				x = a[i*2+1];

				for(auto j : v[i]) {
					v[i*2].insert(j);
					v[i*2+1].insert(j);
				}

				v[i*2+1].insert(a[i*2]);
			}
		}
		
		ans[i] = x;

		chk[x] = true;
		cout << x << " ";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 10112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 10112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 10112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 10112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 10112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -