Codeforces Round #385 (Div. 2), problem: (D) Hongcow’s Game Solution in C/C++

#include <limits.h>
#include <stdio.h>

#define N	1000

void query(int *ww, int *aa, int k, int n) {
	int i;

	printf("%d\n", k);
	for (i = 0; i < k; i++)
		printf("%d ", ww[i]);
	printf("\n");
	fflush(stdout);
	for (i = 1; i <= n; i++)
		scanf("%d", &aa[i]);
}

int main() {
	int i, j, n;
	static int mm[N + 1];

	scanf("%d", &n);
	for (i = 1; i <= n; i++)
		mm[i] = INT_MAX;
	for (i = 0; 1 << i <= n; i++) {
		int aa[N], bb[N], acnt, bcnt;
		int amin[N + 1], bmin[N + 1];

		acnt = bcnt = 0;
		for (j = 1; j <= n; j++) {
			if ((j & 1 << i) == 0)
				aa[acnt++] = j;
			else
				bb[bcnt++] = j;
		}
		query(aa, amin, acnt, n);
		query(bb, bmin, bcnt, n);
		for (j = 1; j <= n; j++) {
			int min;

			min = (j & 1 << i) == 0 ? bmin[j] : amin[j];
			if (mm[j] > min)
				mm[j] = min;
		}
	}
	printf("-1\n");
	for (i = 1; i <= n; i++)
		printf("%d ", mm[i]);
	printf("\n");
	fflush(stdout);
	return 0;
}
#include <limits.h>
#include <stdio.h>

#define N	1000

void query(int *ww, int *aa, int k, int n) {
	int i;

	printf("%d\n", k);
	for (i = 0; i < k; i++)
		printf("%d ", ww[i]);
	printf("\n");
	fflush(stdout);
	for (i = 1; i <= n; i++)
		scanf("%d", &aa[i]);
}

int main() {
	int i, j, n;
	static int mm[N + 1];

	scanf("%d", &n);
	for (i = 1; i <= n; i++)
		mm[i] = INT_MAX;
	for (i = 0; 1 << i <= n; i++) {
		int aa[N], bb[N], acnt, bcnt;
		int amin[N + 1], bmin[N + 1];

		acnt = bcnt = 0;
		for (j = 1; j <= n; j++) {
			if ((j & 1 << i) == 0)
				aa[acnt++] = j;
			else
				bb[bcnt++] = j;
		}
		query(aa, amin, acnt, n);
		query(bb, bmin, bcnt, n);
		for (j = 1; j <= n; j++) {
			int min;

			min = (j & 1 << i) == 0 ? bmin[j] : amin[j];
			if (mm[j] > min)
				mm[j] = min;
		}
	}
	printf("-1\n");
	for (i = 1; i <= n; i++)
		printf("%d ", mm[i]);
	printf("\n");
	fflush(stdout);
	return 0;
}

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

How to Use Snail Mucin Essence on Face (Complete Beginner’s Guide)

Overview: How to Use Snail Mucin Essence on Face (Complete Beginner's Guide) Finding reliable, data-backed guidance on how to use snail mucin essence on face...

How to Use Cosrx Snail Mucin at Night (Complete Beginner’s Guide)

Overview: How to Use Cosrx Snail Mucin at Night (Complete Beginner's Guide) Finding reliable, data-backed guidance on how to use cosrx snail mucin at night...

How to Use Cosrx Snail Mucin Moisturizer (Complete Beginner’s Guide)

Overview: How to Use Cosrx Snail Mucin Moisturizer (Complete Beginner's Guide) Finding reliable, data-backed guidance on how to use cosrx snail mucin moisturizer can be...

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!