Submission #27040

# Submission time Handle Problem Language Result Execution time Memory
27040 2017-07-09T06:06:54 Z 김동현(#1117) Swap (BOI16_swap) C++
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

int n, sz, a[262144];
map<int, vector<int>> mp[262144];

vector<int> mrg(int r, vector<int> a, vector<int> b){
	vector<int> ret;
	if(r) ret.push_back(r);
	for(int i = 0, j = 1; i < a.size(); i += j, j *= 2){
		for(int k = 0; k < j; k++) ret.push_back(a[i + k]);
		for(int k = 0; k < j; k++) ret.push_back(b[i + k]);
	}
	return ret;
}

vector<int> f(int x, int r){
	if(x > sz / 2){
		vector<int> ret; ret.push_back(r); return ret;
	}
	if(mp[x].find(r) != mp[x].end()) return mp[x][r];
	vector<int> ret;
	int t[3] = {r, a[2 * x], a[2 * x + 1]};
	sort(t, t + 3);
	if(t[0] != a[2 * x + 1]){
		ret = mrg(t[0], f(2 * x, r + a[2 * x] - t[0]), f(2 * x + 1, a[2 * x + 1]));
	}
	else{
		ret = min(mrg(t[0], f(2 * x, r), f(2 * x + 1, a[2 * x])),
				  mrg(t[0], f(2 * x, a[2 * x]), f(2 * x + 1, r)));
	}
	mp[x][r] = ret;
	return ret;
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", a + i);
	for(sz = 1; sz < n; sz = 2 * sz + 1);
	for(int i = n + 1; i <= sz; i++) a[i] = i;
	vector<int> ans = f(1, a[1]);
	for(int i = 0; i < n; i++) printf("%d ", ans[i]);
	puts("");
}

Compilation message

swap.cpp:5:20: error: '>>' should be '> >' within a nested template argument list
 map<int, vector<int>> mp[262144];
                    ^
swap.cpp: In function 'std::vector<int> mrg(int, std::vector<int>, std::vector<int>)':
swap.cpp:10:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0, j = 1; i < a.size(); i += j, j *= 2){
                          ^
swap.cpp: In function 'int main()':
swap.cpp:37:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
swap.cpp:38:48: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= n; i++) scanf("%d", a + i);
                                                ^