Submission #534019

# Submission time Handle Problem Language Result Execution time Memory
534019 2022-03-07T19:40:45 Z rainboy Popcount (COCI19_popcount) C
110 / 110
5 ms 340 KB
#include <stdio.h>
#include <string.h>

#define L	256

void mult2(int *aa) {
	int h;

	for (h = 0; h < L; h++)
		aa[h] *= 2;
	for (h = 0; h < L; h++)
		if (aa[h] >= 10)
			aa[h] -= 10, aa[h + 1]++;
}

void add1(int *aa) {
	int h;

	aa[0] += 1;
	for (h = 0; h < L; h++)
		if (aa[h] >= 10)
			aa[h] -= 10, aa[h + 1]++;
}

int main() {
	static int aa[L];
	static char cc[L + 1];
	int n, m, l, i, cnt;

	scanf("%d%*d", &n);
	cnt = 0;
	for (m = 1; m < n; m <<= 1)
		cnt++;
	printf("%d\n", cnt);
	for (m = 1; m < n; m <<= 1) {
		memset(aa, 0, L * sizeof *aa);
		for (i = n - 1; i >= 0; i--) {
			mult2(aa);
			if (i % (m * 2) < m)
				add1(aa);
		}
		l = L;
		while (l > 1 && aa[l - 1] == 0)
			l--;
		for (i = l - 1; i >= 0; i--)
			cc[l - 1 - i] = aa[i] + '0';
		cc[l] = 0;
		printf("A=((A&%s)+((A>>%d)&%s))\n", cc, m, cc);
	}
	return 0;
}

Compilation message

popcount.c: In function 'main':
popcount.c:30:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |  scanf("%d%*d", &n);
      |  ^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Accepted.
2 Correct 0 ms 204 KB Accepted.
3 Correct 0 ms 204 KB Accepted.
4 Correct 1 ms 280 KB Accepted.
5 Correct 1 ms 276 KB Accepted.
6 Correct 0 ms 204 KB Accepted.
7 Correct 1 ms 204 KB Accepted.
8 Correct 1 ms 204 KB Accepted.
9 Correct 1 ms 204 KB Accepted.
10 Correct 1 ms 204 KB Accepted.
11 Correct 1 ms 204 KB Accepted.
12 Correct 1 ms 204 KB Accepted.
13 Correct 1 ms 204 KB Accepted.
14 Correct 1 ms 204 KB Accepted.
# Verdict Execution time Memory Grader output
1 Correct 5 ms 204 KB Accepted.
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Accepted.
2 Correct 1 ms 204 KB Accepted.
3 Correct 0 ms 204 KB Accepted.
4 Correct 1 ms 204 KB Accepted.
5 Correct 1 ms 204 KB Accepted.
6 Correct 0 ms 276 KB Accepted.
7 Correct 1 ms 204 KB Accepted.
8 Correct 0 ms 256 KB Accepted.
9 Correct 0 ms 204 KB Accepted.
10 Correct 1 ms 204 KB Accepted.
11 Correct 0 ms 204 KB Accepted.
12 Correct 1 ms 204 KB Accepted.
13 Correct 1 ms 276 KB Accepted.
14 Correct 1 ms 332 KB Accepted.
15 Correct 1 ms 204 KB Accepted.
16 Correct 1 ms 204 KB Accepted.
17 Correct 0 ms 204 KB Accepted.
18 Correct 0 ms 204 KB Accepted.
19 Correct 1 ms 204 KB Accepted.
20 Correct 1 ms 204 KB Accepted.
21 Correct 1 ms 204 KB Accepted.
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Accepted.
2 Correct 3 ms 204 KB Accepted.
3 Correct 3 ms 204 KB Accepted.
4 Correct 3 ms 204 KB Accepted.
5 Correct 1 ms 204 KB Accepted.
6 Correct 1 ms 204 KB Accepted.
7 Correct 1 ms 204 KB Accepted.
8 Correct 1 ms 204 KB Accepted.
9 Correct 2 ms 204 KB Accepted.
10 Correct 3 ms 204 KB Accepted.
11 Correct 2 ms 204 KB Accepted.
12 Correct 4 ms 204 KB Accepted.