QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#374684#8307. Club AssignmentPetroTarnavskyi#AC ✓87ms5008kbC++201.7kb2024-04-02 16:59:152024-04-02 16:59:16

Judging History

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

  • [2024-04-02 16:59:16]
  • 评测
  • 测评结果:AC
  • 用时:87ms
  • 内存:5008kb
  • [2024-04-02 16:59:15]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second 

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const int N = 100'447;
const int INF = 1e9 + 47;
int n;
PII a[N];
int recov[N];

int find(int l, int r, int bit)
{
	FOR (i, l, r)
		if (a[i].F & (1 << bit))
			return i;
	return r;
}

int brute(int l, int r)
{
	VI nums;
	FOR (i, l, r)
		nums.PB(a[i].F);
	int ans = 0;
	FOR (i, 0, 1 << SZ(nums))
	{
		VI f[2];
		FOR (j, 0, SZ(nums))
		{
			f[(i >> j) & 1].PB(nums[j]);
		}
		VI res(2, INF);
		FOR (t, 0, 2)
		{
			FOR (j, 0, SZ(f[t]))
			{
				FOR (k, j + 1, SZ(f[t]))
					res[t] = min(res[t], f[t][j] ^ f[t][k]);
			}
		}
		int nres = min(res[0], res[1]);
		if (ans < nres)
		{
			ans = nres;
			FOR (j, 0, SZ(nums))
				recov[a[j + l].S] = (i >> j) & 1;
		}
	}
	return ans;
}

int solve(int l, int r, int bit)
{
	if (l == r)	
		return INF;
	if (bit == -1)
	{	
		if (r - l > 2)
			return 0;
		return brute(l, r);
	}
	int m = find(l, r, bit);
	if (m - l > 2 || r - m > 2)
		return min(solve(l, m, bit - 1), solve(m, r, bit - 1));
	else
		return brute(l, r);
}

void solve()
{
	cin >> n;
	FOR (i, 0, n) 
	{
		cin >> a[i].F;
		a[i].S = i;
	}
	sort(a, a + n);
	cout << solve(0, n, 30) << '\n';
	FOR (i, 0, n)
	{
		cout << recov[i] + 1;
	}
	cout << '\n';
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
	
	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3612kb

input:

2
3
1 2 3
3
5 5 5

output:

3
221
0
221

result:

ok accepted

Test #2:

score: 0
Accepted
time: 62ms
memory: 3808kb

input:

2000
100
7 90 64 59 9 12 72 41 72 45 35 90 65 43 81 37 49 62 42 61 12 3 30 97 3 21 43 44 18 71 3 8 70 25 55 41 43 26 80 36 11 6 36 5 57 7 35 23 72 27 73 45 2 64 86 90 47 93 54 26 7 48 63 40 1 61 35 45 11 80 90 68 20 6 22 92 57 47 37 8 84 43 51 95 20 44 89 25 65 18 79 77 5 2 85 62 63 27 62 72
100
34 ...

output:

0
1121121211112112211211111112211222111222221221111211211122211121111111112121111121111111111211111111
0
2121122221211112121212111211122212121122122121211121112112212122111121122122112111111111121111111211
0
21121222122121121112221221222122222212211111212111111121121111111111121111122111111111211111...

result:

ok accepted

Test #3:

score: 0
Accepted
time: 65ms
memory: 3620kb

input:

200
1000
97 76 593 917 428 944 219 473 261 128 920 740 977 978 694 944 856 329 655 861 641 631 249 859 612 547 726 765 705 192 777 483 948 701 754 764 346 237 68 849 437 94 692 717 630 562 350 156 1000 511 27 594 394 866 475 914 90 578 830 561 977 454 676 291 920 240 107 298 451 175 490 545 718 835 ...

output:

0
1221221111121211211221112122222221111112122122222112112112121221111121211211211112121211121122111121122221121122222111221212111212121111111211111122122221221111211112211122111112211121222211112212221111111122211221112121111111221222122112122111112221112212221211121212112111212211212122212121112111...

result:

ok accepted

Test #4:

score: 0
Accepted
time: 67ms
memory: 3652kb

input:

20
10000
7358 1871 8343 6135 4994 4079 3743 4186 527 4232 7581 7898 9666 8358 5102 125 2834 5982 8666 1280 5573 5739 3503 7360 4838 6780 8600 1007 1288 3064 3041 2499 773 4230 6504 7856 5525 3334 6103 3311 1226 6944 2435 2583 8520 7352 2368 3628 7223 9814 3860 7489 8326 5247 676 5151 2620 7377 7776 ...

output:

0
1111121122121212122211222212111121111212122121211211222222121221112222112122211222211212112222112222111112221111222222122111112122211222222121121111112212221111211211111122212121111221121212211111212212122222111221111112111212112122221211222212222221121221212221121222221221211222222211112111112112...

result:

ok accepted

Test #5:

score: 0
Accepted
time: 69ms
memory: 4716kb

input:

2
100000
218410698 619540136 204059004 828710620 433760707 858949452 56646112 343599233 518371279 912235738 799450998 326791937 997127468 922411567 674148810 889617381 91785714 334607795 359332260 175429017 274919417 819231450 913356616 280261257 637218211 804856990 65884496 965434998 482413448 3087...

output:

174
22212221111111212111112212211211222222211122121211211111221121212221212112221212112111212121122121111111122111111122112111211112211221212221121122111212212122121212212211122212111112121121221221212221112121121111122221121212112111211112112112112112112211211212122211222212112211121212111112112112...

result:

ok accepted

Test #6:

score: 0
Accepted
time: 72ms
memory: 4732kb

input:

2
100000
45952020 43003530 739180636 232767573 928337854 143603361 924998273 796606214 887978620 676123110 595413672 655383019 412391053 668472352 900665348 221270516 314314511 996768891 510349335 976288889 458956574 244172022 224900343 843998667 443023193 258664781 428071249 674088601 906425324 818...

output:

51
121122111212112121211212111122222122121111111221212121212211121211121212212211221222112221212112111112112221212111122122111121121211222211221221111112211211121111122121221222112211211121221212221122211112122221112122222112111211211111111121212121111212111212212111111211221211112112122212211121121...

result:

ok accepted

Test #7:

score: 0
Accepted
time: 65ms
memory: 4772kb

input:

2
100000
324060983 423975639 78065962 741281065 952530874 832828146 707841582 336594075 743524679 52184684 668286910 947430308 566647354 609915099 243838528 856841453 735467021 395320501 812917090 384828337 733188613 600906008 279756620 852934734 501320489 951804546 551979949 548694006 239218612 657...

output:

123
11112211121112111211111211211221212222122122111111112111121211222221111112211212211122222122222111212121121121122111111121111112121121121111221111212111221111212212212112211221212121111221121122121121212221122111121211122111222121111211111211212112121122112111111121211221111112121121122211111212...

result:

ok accepted

Test #8:

score: 0
Accepted
time: 65ms
memory: 4716kb

input:

2
100000
645808205 596421158 828608492 741755672 575429555 422819108 27948943 49756965 597845168 967876020 389765414 910234806 12837665 509211680 693343477 674806907 854395084 451492301 670063415 927393016 820001775 467358808 665476077 837216106 84383051 700506954 24534089 153318845 711873152 289359...

output:

26
121222111222122211121211121221122211211122111211211222121211121212112121112111111212111121212112221121211112211111121212111121111221112112111111111121111111121122211122221222111222222122221212212111122111112121112111111121111121111112222122111211122112222121112121222111111112221211222111212111111...

result:

ok accepted

Test #9:

score: 0
Accepted
time: 72ms
memory: 3892kb

input:

60
3000
395876099 358329090 202043778 195559313 254936094 16398849 45756931 132764931 76461320 135497869 418058647 147099536 407816577 216372353 481862294 42000129 419413250 450811521 63495425 388701064 384263070 19473421 357315733 395876125 279500675 57699481 55989916 368907800 62815361 423516163 2...

output:

332185
12212111111122212211121212112212112111211211121111121221122221222222122221211111222221111221121122112111111121221111222122121221222222222121122122211211211221222222122211222212112211211212221111121122122111111211121122212211111221112112111111112222122212121212122112121112212212222112221111212...

result:

ok accepted

Test #10:

score: 0
Accepted
time: 76ms
memory: 4776kb

input:

2
100000
507178766 163687811 411956866 85087132 508806531 209890449 458005890 485265665 196036993 284356481 316468128 172403458 5839746 256974219 317615754 173968513 365579906 30026144 169925506 494563853 163053569 88085778 233741187 160727939 496540557 236586627 51396128 412694029 376036225 3889998...

output:

8200
1222112112121111112111112111122221122211112122112212222122212122111112111222121212211122222111211122211222221222122122121111212212222121212222211122222212111112211211122112222112212221222122221122221121211212122121122121212111211111221222122121211122222111111121212111112112112111112121221112222...

result:

ok accepted

Test #11:

score: 0
Accepted
time: 62ms
memory: 3604kb

input:

60
3000
337511938 249817344 179524364 259713164 330009344 61787392 94543500 290085644 336838528 276430336 92847490 238901516 257662978 322847884 184983308 201702914 152555788 204092044 150509568 235827458 105815820 13328258 58721792 222172812 94203778 221836418 136520834 168261632 96603020 114679426...

output:

14
121122112211111111211121111211111211111111112221212111221111111122112122211122211112211221211121211111121111221111111111111222122112122221111112211111121121112111121121222211111121112111112112111112111111211211111122111112111212112112221111111212211111122111111111112112112121111211122111112211121...

result:

ok accepted

Test #12:

score: 0
Accepted
time: 73ms
memory: 4768kb

input:

2
99999
26872320 11378188 92725632 299758348 38637184 28110466 259842176 336508418 183081986 62270976 281121408 290264194 151789698 218227458 224093068 336191232 260661132 87849996 222147712 118694156 82002828 113554306 264162572 275202432 314031104 308686466 188940034 211109120 196322444 159838722 ...

output:

14
212121211221111211211112211211122112211111111212111111222111111212211121122112111111121112112111211111111121112121221111222212112111221212112112211111111122122111211111111221211121111111111221111222112211211112111122212111112112111121111121112212112211111111121222222222121122121211212112112122121...

result:

ok accepted

Test #13:

score: 0
Accepted
time: 87ms
memory: 5008kb

input:

2
100000
664174 3699447 2989290 3133937 733293 432010 960975 1009770 2894902 3133287 2585854 867938 781291 3304247 2208015 2647539 3099219 164967 2247690 1499689 1350168 2591211 2176174 686579 2097381 1264892 3121613 2579857 1332416 2355218 601058 679055 735128 1301455 2149378 2717051 2208574 651296...

output:

64
222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222212222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222212222222222222222222222222222...

result:

ok accepted

Extra Test:

score: 0
Extra Test Passed