답안 #76609

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

const int mxN=2e5;
int n, a[mxN+1];
vector<int> dp[mxN+1][36], 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]);
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i=1; i<=n; ++i)
		cin >> a[i];
	for(int i=n; i; --i) {
		for(int j=0; i>>j; ++j) {
			for(int k=0; k<1+((i>>j&1)&&i>>j>1); ++k) {
				int b=i>>j^k, c=j*2+k;
				if(2*i+1<=n) {
					if(a[2*i+1]<a[b]&&a[2*i+1]<a[2*i]) {
						v1={a[2*i+1]};
						v2={a[2*i+1]};
						mrg(v1, dp[2*i][0], dp[2*i+1][c+2]);
						mrg(v2, dp[2*i][c+2], dp[2*i+1][1]);
						dp[i][c]=min(v1, v2);
					} else {
						dp[i][c]={min(a[b], a[2*i])};
						mrg(dp[i][c], dp[2*i][a[b]>a[2*i]?c+2:0], dp[2*i+1][0]);
					}
				} else if(2*i<=n)
					dp[i][c]={min(a[b], a[2*i]), max(a[b], a[2*i])};
				else
					dp[i][c]={a[b]};
			}
		}
		if(2*i+1<=n)
			for(int l=0; l<2; ++l)
				for(int j=0; (2*i+l)>>j; ++j)
					for(int k=0; k<1+(((2*i+l)>>j&1)&&(2*i+l)>>j>1); ++k)
						vector<int>().swap(dp[2*i+l][j*2+k]);
	}
	for(int b : dp[1][0])
		cout << b << " ";
}

Compilation message

swap.cpp: In function 'void mrg(std::vector<int>&, std::vector<int>&, std::vector<int>&)':
swap.cpp:9: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:9: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:10:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int k=0; k<l&&i+k<a.size(); ++k)
                     ~~~^~~~~~~~~
swap.cpp:12: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 151 ms 169464 KB Output is correct
2 Correct 166 ms 169556 KB Output is correct
3 Correct 147 ms 169632 KB Output is correct
4 Correct 147 ms 169632 KB Output is correct
5 Correct 150 ms 169632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 151 ms 169464 KB Output is correct
2 Correct 166 ms 169556 KB Output is correct
3 Correct 147 ms 169632 KB Output is correct
4 Correct 147 ms 169632 KB Output is correct
5 Correct 150 ms 169632 KB Output is correct
6 Correct 146 ms 169632 KB Output is correct
7 Correct 148 ms 169632 KB Output is correct
8 Correct 147 ms 169632 KB Output is correct
9 Correct 146 ms 169632 KB Output is correct
10 Correct 146 ms 169676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 151 ms 169464 KB Output is correct
2 Correct 166 ms 169556 KB Output is correct
3 Correct 147 ms 169632 KB Output is correct
4 Correct 147 ms 169632 KB Output is correct
5 Correct 150 ms 169632 KB Output is correct
6 Correct 146 ms 169632 KB Output is correct
7 Correct 148 ms 169632 KB Output is correct
8 Correct 147 ms 169632 KB Output is correct
9 Correct 146 ms 169632 KB Output is correct
10 Correct 146 ms 169676 KB Output is correct
11 Correct 153 ms 169932 KB Output is correct
12 Correct 148 ms 169932 KB Output is correct
13 Correct 150 ms 169932 KB Output is correct
14 Correct 149 ms 169932 KB Output is correct
15 Correct 152 ms 169932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 151 ms 169464 KB Output is correct
2 Correct 166 ms 169556 KB Output is correct
3 Correct 147 ms 169632 KB Output is correct
4 Correct 147 ms 169632 KB Output is correct
5 Correct 150 ms 169632 KB Output is correct
6 Correct 146 ms 169632 KB Output is correct
7 Correct 148 ms 169632 KB Output is correct
8 Correct 147 ms 169632 KB Output is correct
9 Correct 146 ms 169632 KB Output is correct
10 Correct 146 ms 169676 KB Output is correct
11 Correct 153 ms 169932 KB Output is correct
12 Correct 148 ms 169932 KB Output is correct
13 Correct 150 ms 169932 KB Output is correct
14 Correct 149 ms 169932 KB Output is correct
15 Correct 152 ms 169932 KB Output is correct
16 Correct 369 ms 187796 KB Output is correct
17 Correct 403 ms 187796 KB Output is correct
18 Correct 387 ms 187888 KB Output is correct
19 Correct 356 ms 187888 KB Output is correct
20 Correct 355 ms 188032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 151 ms 169464 KB Output is correct
2 Correct 166 ms 169556 KB Output is correct
3 Correct 147 ms 169632 KB Output is correct
4 Correct 147 ms 169632 KB Output is correct
5 Correct 150 ms 169632 KB Output is correct
6 Correct 146 ms 169632 KB Output is correct
7 Correct 148 ms 169632 KB Output is correct
8 Correct 147 ms 169632 KB Output is correct
9 Correct 146 ms 169632 KB Output is correct
10 Correct 146 ms 169676 KB Output is correct
11 Correct 153 ms 169932 KB Output is correct
12 Correct 148 ms 169932 KB Output is correct
13 Correct 150 ms 169932 KB Output is correct
14 Correct 149 ms 169932 KB Output is correct
15 Correct 152 ms 169932 KB Output is correct
16 Correct 369 ms 187796 KB Output is correct
17 Correct 403 ms 187796 KB Output is correct
18 Correct 387 ms 187888 KB Output is correct
19 Correct 356 ms 187888 KB Output is correct
20 Correct 355 ms 188032 KB Output is correct
21 Execution timed out 1094 ms 251560 KB Time limit exceeded
22 Halted 0 ms 0 KB -