답안 #61911

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

int n, K, w[N_], s = 0, U[31*N_], cnt;
bool v[31 * 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 216 ms 11220 KB Output is correct
2 Correct 217 ms 11272 KB Output is correct
3 Correct 236 ms 11368 KB Output is correct
4 Correct 243 ms 11368 KB Output is correct
5 Correct 325 ms 11464 KB Output is correct
6 Correct 323 ms 11464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 225 ms 11464 KB Expected EOF
2 Correct 241 ms 11464 KB Output is correct
3 Incorrect 292 ms 11464 KB Expected EOF
4 Incorrect 254 ms 11464 KB Expected EOF
5 Incorrect 214 ms 11472 KB Expected EOF
6 Incorrect 332 ms 11472 KB Expected EOF
7 Incorrect 216 ms 11512 KB Expected EOF
8 Incorrect 318 ms 11556 KB Expected EOF
9 Incorrect 258 ms 11556 KB Expected EOF
10 Incorrect 120 ms 11556 KB Expected EOF
11 Incorrect 256 ms 11556 KB Expected EOF
12 Incorrect 263 ms 11916 KB Expected EOF
13 Incorrect 260 ms 11916 KB Expected EOF
14 Incorrect 253 ms 11916 KB Expected EOF