QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#573275#7939. High TowersHuTaoWA 0ms12016kbC++144.2kb2024-09-18 17:59:332024-09-18 17:59:35

Judging History

你现在查看的是最新测评结果

  • [2024-09-18 17:59:35]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:12016kb
  • [2024-09-18 17:59:33]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5, M = 115, T = 3e7 + 5, m = 10;

struct BigNumber{
	int n, pos;
	char s[M];
	inline void Write()
	{
		reverse(s, s + n);
		for(int i = 0; i < n; i ++ ) s[i] ^= 48;
		printf("%s ", s);
		reverse(s, s + n);
		for(int i = 0; i < n; i ++ ) s[i] ^= 48;
	}
	inline void Make(BigNumber &t, int i, int x)
	{
		for(int j = 0; j < i; j ++ ) s[j] = t.s[j];
		s[i] = x;
		for(int j = i; j < t.n; j ++ ) s[j + 1] = t.s[j];
		n = t.n + 1, pos = min(n - 1, i + 1);
	}
	inline bool operator <= (const BigNumber &w) const
	{
		for(int i = n - 1; i >= 0; i -- )
			if(s[i] != w.s[i])
				return s[i] < w.s[i];
		return 1;
	}
	inline bool operator != (const BigNumber &w) const
	{
		for(int i = 0; i < n; i ++ )
			if(s[i] != w.s[i])
				return 1;
		return 0;
	}
};

bool ST;
int n, k;
bitset<M> vis[m];
int f[N], st[N];
BigNumber s[N * 2], s0[N], s1[N], r0[N], r1[N], cur;
int p0, p00, p01, p10, p11, c10, c11;
struct Node{
	unsigned t : 18;
	unsigned i : 8;
	unsigned x : 4;
}x[T], y[T];
int cnt[N];
bool ED;

inline int GetBit(Node &x, int i)
{
	return i < x.i ? s[x.t].s[i] : (i == x.i ? x.x : s[x.t].s[i - 1]);
}
inline int GetBlock(Node &x, int i)
{
	return ((((GetBit(x, i + 4) * 10 + GetBit(x, i + 3)) * 10) + GetBit(x, i + 2)) * 10 + GetBit(x, i + 1)) * 10 + GetBit(x, i);
}
inline void Sort(int n, int m)
{
	if(!m) return ;
	int c = 0;
	if(k > m)
	{
		for(int i = 0; i < m; i ++ )
			for(int j = s[i].pos; j < n; j ++ )
				for(int k = 0; k < 10; k ++ )
					if(j == s[i].pos || s[i].s[j - 1] != k)
						x[c].t = i, x[c].i = j, x[c].x = k, c ++ ;
	}
	else
	{
		for(int i = 0; i < m; i ++ )
			for(int j = s[i].pos; j < n; j ++ )
				for(int k = 0; k < 10; k ++ )
					if(j == s[i].pos || s[i].s[j - 1] != k || (j == n - 1 && k == 1) || (j != n - 1 && s[i].s[n - 2] == 1))
						x[c].t = i, x[c].i = j, x[c].x = k, c ++ ;
	}
	// puts("\n#");
	// for(int i = 0; i < c; i ++ )
	// {
	// 	cur.Make(s[x[i].t], x[i].i, x[i].x);
	// 	cur.Write();
	// }
	// if(n == 4) exit(0);
	Node *p = x, *q = y;
	for(int i = 0; i < n; i += 5)
	{
		for(int j = 0; j < c; j ++ ) cnt[GetBlock(p[j], i)] ++ ;
		for(int j = 1; j < N; j ++ ) cnt[j] += cnt[j - 1];
		for(int j = c - 1; j >= 0; j -- ) q[ -- cnt[GetBlock(p[j], i)]] = p[j];
		for(int j = 0; j < N; j ++ ) cnt[j] = 0;
		swap(p, q);
	}
	
	c10 = c11 = 0;
	for(int i = 0; i < c; i ++ )
	{
		cur.Make(s[p[i].t], p[i].i, p[i].x);
		if(cur.s[n - 1])
		{
			if((c10 <= k && !c10) || r0[c10 - 1] != cur)
				r0[c10 ++ ] = cur;
		}
		else
		{
			if((c11 <= k && !c11) || r1[c11 - 1] != cur)
				r1[c11 ++ ] = cur;
		}
	}

	// puts("\n*");
	// for(int i = 0; i < c10; i ++ ) r0[i].Write();
	// puts("");
	// if(n == 4) exit(0);
}
inline void DFS(int i, int S)
{
	if(!st[S] || p00 == k) return ;
	if(i < 0)
	{
		if(cur.s[cur.n - 1])
		{
			while(p10 < c10 && p00 < k && r0[p10] <= cur) s0[p00 ++ ] = r0[p10 ++ ];
			if(!p00 || (p00 < k && s0[p00 - 1] != cur)) s0[p00 ++ ] = cur;
		}
		else
		{
			while(p11 < c11 && p01 < k && r1[p11] <= cur) s1[p01 ++ ] = r1[p11 ++ ];
			if(!p01 || (p01 < k && s1[p01 - 1] != cur)) s1[p01 ++ ] = cur;
		}
		return ;
	}
	for(int j = 0; j < m; j ++ )
	{
		cur.s[i] = j;
		DFS(i - 1, S | (1 << j));
	}
}

int main()
{
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n; i ++ )
		for(int j = 0; j < 6; j ++ )
		{
			int x;
			scanf("%d", &x);
			vis[x].set(i);
		}
	for(int i = 0; i < 1 << m; i ++ )
	{
		bitset<M> mask;
		mask.reset();
		for(int j = 0; j < m; j ++ )
			if(i >> j & 1)
				mask |= vis[j];
		f[i] = mask.count() + 1;
	}
	
	for(int i = 1; k; i ++ )
	{
		Sort(i, p0);
		for(int j = (1 << m) - 1; j >= 0; j -- )
		{
			st[j] |= f[j] <= i;
			for(int k = 0; k < m; k ++ )
				st[j] |= st[j | 1 << k];
		}
		p00 = p01 = p10 = p11 = 0;
		cur.n = i, cur.pos = 0;
		DFS(i - 1, 0);
		while(p10 < c10 && p00 < k) s0[p00 ++ ] = r0[p10 ++ ];
		while(p11 < c11 && p01 < k) s1[p01 ++ ] = r1[p11 ++ ];
		for(int i = 0; i < p00; i ++ ) s0[i].Write();
		k -= p00;
		for(int i = 0; i < p00; i ++ ) s[i] = s0[i];
		for(int i = 0; i < p01; i ++ ) s[i + p00] = s1[i];
		p0 = p00 + p01;
	}
	puts("");
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 12016kb

input:

6
3 3 4 2 5 1

output:

6 7 8 

result:

wrong output format Unexpected end of file - int32 expected