답안 #76599

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
76599 2018-09-15T06:31:14 Z tmwilliamlin168 Swap (BOI16_swap) C++14
68 / 100
1000 ms 263168 KB
#include <bits/stdc++.h>
using namespace std;

const int mxN=2e5, MGC1=1.5e6;
int n, a[mxN+1], cdi;
unordered_map<int, int> di[mxN+1];
vector<int> dp[MGC1], v1, v2;

void mrg(vector<int> &v, vector<int> &a, vector<int> &b) {
	for(int l=1, i=0, j=0; i<a.size()||j<b.size(); i+=l, j+=l, l*=2) {
		for(int k=0; k<l&&i+k<a.size(); ++k)
			v.push_back(a[i+k]);
		for(int k=0; k<l&&j+k<b.size(); ++k)
			v.push_back(b[j+k]);
	}
}

void as(int i, int b) {
	if(di[i].find(b)==di[i].end())
		di[i][b]=-1;
}

vector<int>& gd(int i, int b) {
	return dp[di[i][b]];
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i=1; i<=n; ++i)
		cin >> a[i];
	as(1, a[1]);
	for(int i=1; 2*i+1<=n; ++i) {
		for(auto it=di[i].begin(); it!=di[i].end(); ++it) {
			int b=it->first;
			if(a[2*i+1]<b&&a[2*i+1]<a[2*i]) {
				as(2*i, a[2*i]);
				as(2*i+1, b);
				as(2*i, b);
				as(2*i+1, a[2*i]);
			} else {
				as(2*i, max(b, a[2*i]));
				as(2*i+1, a[2*i+1]);
			}
		}
	}
	for(int i=n; i; --i) {
		for(auto it=di[i].begin(); it!=di[i].end(); ++it) {
			int b=it->first, c=it->second=cdi;
			cdi=(cdi+1)%MGC1;
			dp[c].clear();
			if(2*i+1<=n) {
				if(a[2*i+1]<b&&a[2*i+1]<a[2*i]) {
					v1={a[2*i+1]};
					v2={a[2*i+1]};
					mrg(v1, gd(2*i, a[2*i]), gd(2*i+1, b));
					mrg(v2, gd(2*i, b), gd(2*i+1, a[2*i]));
					dp[c]=min(v1, v2);
				} else {
					dp[c]={min(b, a[2*i])};
					mrg(dp[c], gd(2*i, max(b, a[2*i])), gd(2*i+1, a[2*i+1]));
				}
			} else if(2*i<=n)
				dp[c]={min(b, a[2*i]), max(b, a[2*i])};
			else
				dp[c]={b};
		}
	}
	for(int b : gd(1, a[1]))
		cout << b << " ";
}

Compilation message

swap.cpp: In function 'void mrg(std::vector<int>&, std::vector<int>&, std::vector<int>&)':
swap.cpp:10:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int l=1, i=0, j=0; i<a.size()||j<b.size(); i+=l, j+=l, l*=2) {
                         ~^~~~~~~~~
swap.cpp:10:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int l=1, i=0, j=0; i<a.size()||j<b.size(); i+=l, j+=l, l*=2) {
                                     ~^~~~~~~~~
swap.cpp:11:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int k=0; k<l&&i+k<a.size(); ++k)
                     ~~~^~~~~~~~~
swap.cpp:13:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int k=0; k<l&&j+k<b.size(); ++k)
                     ~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 46584 KB Output is correct
2 Correct 44 ms 46684 KB Output is correct
3 Correct 44 ms 46696 KB Output is correct
4 Correct 42 ms 46704 KB Output is correct
5 Correct 43 ms 46728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 46584 KB Output is correct
2 Correct 44 ms 46684 KB Output is correct
3 Correct 44 ms 46696 KB Output is correct
4 Correct 42 ms 46704 KB Output is correct
5 Correct 43 ms 46728 KB Output is correct
6 Correct 44 ms 46744 KB Output is correct
7 Correct 57 ms 46744 KB Output is correct
8 Correct 48 ms 46916 KB Output is correct
9 Correct 45 ms 46960 KB Output is correct
10 Correct 46 ms 46960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 46584 KB Output is correct
2 Correct 44 ms 46684 KB Output is correct
3 Correct 44 ms 46696 KB Output is correct
4 Correct 42 ms 46704 KB Output is correct
5 Correct 43 ms 46728 KB Output is correct
6 Correct 44 ms 46744 KB Output is correct
7 Correct 57 ms 46744 KB Output is correct
8 Correct 48 ms 46916 KB Output is correct
9 Correct 45 ms 46960 KB Output is correct
10 Correct 46 ms 46960 KB Output is correct
11 Correct 45 ms 47116 KB Output is correct
12 Correct 43 ms 47132 KB Output is correct
13 Correct 55 ms 47132 KB Output is correct
14 Correct 54 ms 47632 KB Output is correct
15 Correct 46 ms 47656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 46584 KB Output is correct
2 Correct 44 ms 46684 KB Output is correct
3 Correct 44 ms 46696 KB Output is correct
4 Correct 42 ms 46704 KB Output is correct
5 Correct 43 ms 46728 KB Output is correct
6 Correct 44 ms 46744 KB Output is correct
7 Correct 57 ms 46744 KB Output is correct
8 Correct 48 ms 46916 KB Output is correct
9 Correct 45 ms 46960 KB Output is correct
10 Correct 46 ms 46960 KB Output is correct
11 Correct 45 ms 47116 KB Output is correct
12 Correct 43 ms 47132 KB Output is correct
13 Correct 55 ms 47132 KB Output is correct
14 Correct 54 ms 47632 KB Output is correct
15 Correct 46 ms 47656 KB Output is correct
16 Correct 124 ms 62192 KB Output is correct
17 Correct 151 ms 62192 KB Output is correct
18 Correct 113 ms 62868 KB Output is correct
19 Correct 426 ms 117632 KB Output is correct
20 Correct 426 ms 117632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 46584 KB Output is correct
2 Correct 44 ms 46684 KB Output is correct
3 Correct 44 ms 46696 KB Output is correct
4 Correct 42 ms 46704 KB Output is correct
5 Correct 43 ms 46728 KB Output is correct
6 Correct 44 ms 46744 KB Output is correct
7 Correct 57 ms 46744 KB Output is correct
8 Correct 48 ms 46916 KB Output is correct
9 Correct 45 ms 46960 KB Output is correct
10 Correct 46 ms 46960 KB Output is correct
11 Correct 45 ms 47116 KB Output is correct
12 Correct 43 ms 47132 KB Output is correct
13 Correct 55 ms 47132 KB Output is correct
14 Correct 54 ms 47632 KB Output is correct
15 Correct 46 ms 47656 KB Output is correct
16 Correct 124 ms 62192 KB Output is correct
17 Correct 151 ms 62192 KB Output is correct
18 Correct 113 ms 62868 KB Output is correct
19 Correct 426 ms 117632 KB Output is correct
20 Correct 426 ms 117632 KB Output is correct
21 Correct 340 ms 117632 KB Output is correct
22 Correct 337 ms 117632 KB Output is correct
23 Correct 337 ms 117632 KB Output is correct
24 Execution timed out 1090 ms 263168 KB Time limit exceeded
25 Halted 0 ms 0 KB -