QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#572792#7940. Impossible NumbersHuTaoWA 1ms6512kbC++143.3kb2024-09-18 16:23:542024-09-18 16:23:54

Judging History

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

  • [2024-09-18 16:23:54]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6512kb
  • [2024-09-18 16:23:54]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5, M = 105, T = 2e7 + 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 = i + 1;
	}
	inline bool operator <= (const BigNumber &w) const
	{
		if(n != w.n) return n < w.n;
		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
	{
		if(n != w.n) return 1;
		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], r[N], cur;
int p0, p1, c1;
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;
	for(int i = 0; i < m; i ++ )
		for(int j = s[i].pos; j < n; j ++ )
			for(int k = (j == n - 1); k < 10; k ++ )
				if(!j || s[i].s[j - 1] != k)
					c ++ , x[c].t = i, x[c].i = j, x[c].x = k;
	// puts("\n#");
	// for(int i = 0; i < c; i ++ )
	// {
	// 	cur.Make(s[x[i].t], x[i].i, x[i].x);
	// 	cur.Write();
	// }
	// 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);
	}
	r[0].Make(s[p[0].t], p[0].i, p[0].x), c1 = 1;
	for(int i = 1; i < c; i ++ )
	{
		cur.Make(s[p[i].t], p[i].i, p[i].x);
		if(cur != r[c1 - 1]) r[c1 ++ ] = cur;
		if(c1 >= k) break;
	}
	// puts("\n*");
	// for(int i = 0; i < c1; i ++ ) r[i].Write();
	// exit(0);
}
inline void DFS(int i, int ty, int S)
{
	if(!st[S] || p0 == k) return ;
	if(i < 0)
	{
		while(p1 < c1 && p0 < k && r[p1] <= cur) s[p0 ++ ] = r[p1 ++ ];
		if(p0 < k && s[p0 - 1] != cur) s[p0 ++ ] = cur;
		return ;
	}
	for(int j = ty; j < m; j ++ )
	{
		cur.s[i] = j;
		DFS(i - 1, 0, 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;
		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];
		}
		p0 = p1 = 0;
		cur.n = i, cur.pos = 0;
		DFS(i - 1, 1, 0);
		while(p1 < c1 && p0 < k) s[p0 ++ ] = r[p1 ++ ];
		for(int i = 0; i < p0; i ++ ) s[i].Write();
		k -= p0;
	}
	puts("");
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5748kb

input:

2 3
1 8 7 0 6 2
1 2 5 4 9 3

output:

33 34 35 

result:

ok single line: '33 34 35 '

Test #2:

score: 0
Accepted
time: 1ms
memory: 4472kb

input:

1 10
1 5 2 2 6 4

output:

3 7 8 9 10 11 12 13 14 15 

result:

ok single line: '3 7 8 9 10 11 12 13 14 15 '

Test #3:

score: 0
Accepted
time: 1ms
memory: 6512kb

input:

4 10
1 5 7 1 2 4
0 1 5 8 9 4
3 5 2 2 7 8
6 1 7 0 2 2

output:

33 66 99 133 166 199 233 266 299 303 

result:

ok single line: '33 66 99 133 166 199 233 266 299 303 '

Test #4:

score: 0
Accepted
time: 1ms
memory: 4476kb

input:

5 10
5 9 4 8 3 3
1 1 9 2 8 9
6 3 3 0 2 1
2 6 0 3 6 4
3 6 4 2 9 4

output:

7 17 27 37 47 55 57 67 70 71 

result:

ok single line: '7 17 27 37 47 55 57 67 70 71 '

Test #5:

score: 0
Accepted
time: 1ms
memory: 4240kb

input:

5 10
8 7 1 4 8 9
2 5 0 1 0 1
9 5 5 3 9 7
6 0 0 2 3 1
1 0 0 4 9 3

output:

66 88 166 188 222 226 262 266 288 366 

result:

ok single line: '66 88 166 188 222 226 262 266 288 366 '

Test #6:

score: 0
Accepted
time: 1ms
memory: 4180kb

input:

5 10
6 8 7 7 0 0
0 5 1 9 4 1
5 9 6 9 5 4
0 4 6 9 1 6
2 8 7 4 4 0

output:

3 13 22 23 30 31 32 33 34 35 

result:

ok single line: '3 13 22 23 30 31 32 33 34 35 '

Test #7:

score: -100
Wrong Answer
time: 1ms
memory: 4524kb

input:

5 1000
0 4 1 3 9 6
9 6 2 1 8 6
5 3 0 7 7 3
0 2 8 0 8 4
2 4 1 2 9 7

output:

55 155 255 333 335 353 355 455 505 515 525 533 535 545 550 551 552 553 554 555 556 557 558 559 565 575 577 585 595 655 666 755 757 775 777 855 888 1111 1116 1119 1161 1166 1169 1191 1196 1199 1255 1333 1335 1353 1355 1455 1505 1515 1525 1533 1535 1545 1550 1551 1552 1553 1554 1555 1556 1557 1558 155...

result:

wrong answer 1st lines differ - expected: '55 155 255 333 335 353 355 455...0 10053 10055 10111 10116 10119', found: '55 155 255 333 335 353 355 455... 11099 11101 11106 11109 11110 '