답안 #258527

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
258527 2020-08-06T05:38:59 Z 임성재(#5051) Swap (BOI16_swap) C++17
0 / 100
4 ms 4992 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];
set<int> g[100010];

int main() {
	fast;

	cin >> n;

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

		if(i > 1) g[i/2].insert(i), g[i].insert(i/2);
	}

	for(int i=1; i<=n; i++) {
		int mn = a[i];
		int x = i;

		for(auto it : g[i]) {
			g[it].erase(i);
			if(a[it] < mn) {
				x = it;
				mn = a[it];
			}
			mn = min(mn, a[it]);
		}

		swap(a[x], a[i]);

		if(x == i) continue;

		for(auto it : g[i]) {
			if(it == x) break;

			g[x].insert(it);
			g[it].insert(x);
		}
	}

	for(int i=1; i<=n; i++) {
		cout << a[i] << " ";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Incorrect 3 ms 4992 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Incorrect 3 ms 4992 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Incorrect 3 ms 4992 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Incorrect 3 ms 4992 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Incorrect 3 ms 4992 KB Output isn't correct
4 Halted 0 ms 0 KB -