답안 #258533

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

int main() {
	fast;

	cin >> n;

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

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

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

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

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

		if(x == i) continue;

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

			g[x].insert(it);
			g[it.se].insert(mp(it.fi, x));
		}
	}

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