답안 #61908

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
61908 2018-07-27T05:06:24 Z ainta(#1792) Zalmoxis (BOI18_zalmoxis) C++11
35 / 100
361 ms 11932 KB
#include<cstdio>
#include<algorithm>
#define N_ 1010000
using namespace std;

int n, K, w[N_], s = 0, U[10*N_], cnt;
bool v[10 * N_];
void Put(int &s, int b) {
	if (s&((1 << b) - 1)) {
		int t = (((s >> b) + 1) << b) - s;
		for (int j = 0; j <= 30; j++) {
			if ((t >> j) & 1)U[cnt++] = j;
		}
		s += t;
	}
}
void Print(int x, int C) {
	if (C == (1 << x)) {
		for (int i = 0; i < C; i++)printf("0 ");
		return;
	}
	if (C == 1) {
		printf("%d ", x);
		return;
	}
	if (C > (1 << (x - 1))) {
		Print(x - 1, 1 << (x - 1));
		Print(x - 1, C - (1 << (x - 1)));
	}
	else {
		Print(x - 1, C - 1);
		Print(x - 1, 1);
	}
}
int main() {
	int i, j;
	scanf("%d%d", &n, &K);
	for (i = 1; i <= n; i++)scanf("%d", &w[i]);
	for (i = 1; i <= n; i++) {

		Put(s, w[i]);
		v[cnt] = 1;
		U[cnt++] = w[i];
		s += (1 << w[i]);
	}
	Put(s, 30);
	int C = K+n - cnt;
	for (i = 0; i < cnt; i++) {
		if (v[i] || !C) {
			printf("%d ", U[i]);
			continue;
		}
		if (C >= (1<<U[i]) - 1) {
			for (int j = 0; j < (1<<U[i]); j++)printf("0 ");
			C -= ((1 << U[i]) - 1);
			continue;
		}
		Print(U[i], C+1);
	}
	return 0;
}

Compilation message

zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:36:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
zalmoxis.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &K);
  ~~~~~^~~~~~~~~~~~~~~~
zalmoxis.cpp:38:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (i = 1; i <= n; i++)scanf("%d", &w[i]);
                          ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 230 ms 11144 KB Output is correct
2 Correct 256 ms 11256 KB Output is correct
3 Correct 250 ms 11436 KB Output is correct
4 Correct 245 ms 11436 KB Output is correct
5 Correct 219 ms 11436 KB Output is correct
6 Correct 253 ms 11436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 255 ms 11436 KB Expected EOF
2 Correct 270 ms 11528 KB Output is correct
3 Incorrect 191 ms 11528 KB Expected EOF
4 Incorrect 206 ms 11532 KB Expected EOF
5 Incorrect 245 ms 11532 KB Expected EOF
6 Incorrect 214 ms 11532 KB Expected EOF
7 Incorrect 206 ms 11532 KB Expected EOF
8 Incorrect 208 ms 11532 KB Expected EOF
9 Incorrect 278 ms 11532 KB Expected EOF
10 Incorrect 129 ms 11532 KB Expected EOF
11 Incorrect 179 ms 11532 KB Expected EOF
12 Incorrect 234 ms 11916 KB Expected EOF
13 Incorrect 283 ms 11916 KB Expected EOF
14 Incorrect 361 ms 11932 KB Expected EOF