Submission #112163

# Submission time Handle Problem Language Result Execution time Memory
112163 2019-05-17T16:14:56 Z Bruteforceman Swap (BOI16_swap) C++11
0 / 100
10 ms 10624 KB
#include "bits/stdc++.h"
using namespace std;
int n;
int a[400010];
set <int> s[200010];
int match[200010];

int main(int argc, char const *argv[])
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	for(int i = n+1; i <= 2*n+1; i++) {
		a[i] = INT_MAX;
	}
	memset(match, -1, sizeof match);

	for(int i = 1; i <= n; i++) {
		int l = i << 1;
		int r = l + 1;
		int val = a[i];
		if(a[i] == -1) {
			int cur = i;
			val = INT_MAX;
			while(cur > 1) {
				cur /= 2;
				if(!s[cur].empty()) {
					val = min(val, *s[cur].begin());
				}
			}
		}
		if(val < min(a[l], a[r])) {
			if(a[i] == -1) {
				int cur = i;
				while(cur > 1) {
					int now = cur;
					cur /= 2;
					if(s[cur].find(val) != s[cur].end()) {
						s[cur].erase(val);
						s[cur].erase(match[val]);
						if(match[val] != -1) {
							s[now ^ 1].insert(match[val]);
							match[match[val]] = -1;
						}
						break;
					}
				}
			}
			a[i] = val;
		} else if (a[l] < a[r]) {
			swap(a[i], a[l]);
		} else {
			swap(a[i], a[r]);
			if(a[l] != -1) s[i].insert(a[l]);
			if(a[r] != -1) s[i].insert(a[r]);
			if(a[l] != -1 && a[r] != -1) {
				match[a[l]] = a[r];
				match[a[r]] = a[l];
			}
			a[l] = a[r] = -1;
		}
	}
	for(int i = 1; i <= n; i++) {
		printf("%d ", a[i]);
	}
	printf("\n");
	return 0;
}

Compilation message

swap.cpp: In function 'int main(int, const char**)':
swap.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
swap.cpp:12:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 10624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 10624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 10624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 10624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 10624 KB Output isn't correct
2 Halted 0 ms 0 KB -