QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#509683#1968. Science FictionPetroTarnavskyi#AC ✓1ms3952kbC++201.3kb2024-08-08 17:15:302024-08-08 17:15:31

Judging History

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

  • [2024-08-08 17:15:31]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3952kb
  • [2024-08-08 17:15:30]
  • 提交

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;

bool has_bit(int x, int bt)
{
	return (x >> bt) & 1;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	
	VI p(1 << n);
	FOR (i, 0, SZ(p))
		cin >> p[i];
	
	VI srt = p;
	sort(ALL(srt));
	
	vector<PII> ans;
	
	FOR (en, 0, 1 << n)
	{
		int st = -1;
		FOR (pos, en, 1 << n)
		{
			if (srt[en] == p[pos])
			{
				st = pos;
				break;
			}
		}
		FOR (i, 0, n)
		{
			if (has_bit(en, i) && !has_bit(st, i))
			{
				ans.PB({st, st | (1 << i)});
				swap(p[st], p[st | (1 << i)]);
				st |= 1 << i;
			}
		}
		FOR (i, 0, n)
		{
			if (!has_bit(en, i) && has_bit(st, i))
			{
				ans.PB({st, st ^ (1 << i)});
				swap(p[st], p[st ^ (1 << i)]);
				st ^= 1 << i;
			}
		}
	}
	
	
	assert(is_sorted(ALL(p)));
	assert(SZ(ans) <= n * (1 << n));
	cout << SZ(ans) << '\n';
	for (auto [i, j] : ans)
		cout << i << ' ' << j << '\n';
	
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
3 2 10 4

output:

2
1 0
3 2

result:

ok nice! 2 moves

Test #2:

score: 0
Accepted
time: 0ms
memory: 3784kb

input:

1
10 100

output:

0

result:

ok nice! 0 moves

Test #3:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

1
824838 992401

output:

0

result:

ok nice! 0 moves

Test #4:

score: 0
Accepted
time: 0ms
memory: 3596kb

input:

2
208395 17211 250690 874014

output:

1
1 0

result:

ok nice! 1 moves

Test #5:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

8
991318 655714 983340 496226 752852 888298 572661 729100 426124 437775 8096 28612 303846 295897 970760 179029 702449 407420 945406 352294 960516 484993 724888 495235 156841 451864 95506 869159 61631 296168 279240 260130 901551 726353 298872 221580 982372 394731 720187 656498 595457 381795 759187 36...

output:

938
62 60
60 56
56 48
48 32
32 0
10 11
11 9
9 1
77 79
79 78
78 74
74 66
66 2
44 45
45 47
47 43
43 35
35 3
69 68
68 4
10 11
11 15
15 13
13 5
210 214
214 198
198 134
134 6
54 55
55 39
39 7
137 136
136 8
138 139
139 137
137 9
171 170
170 138
138 10
195 203
203 139
139 11
194 198
198 206
206 204
204 140...

result:

ok nice! 938 moves

Test #6:

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

input:

9
888559 111203 65032 290846 22133 226267 707470 14065 736516 622251 346047 555707 482074 680230 613967 497441 449554 967825 651070 678493 472313 583791 720445 224302 300743 198731 973353 657745 445065 428890 915188 532221 601100 975552 252972 265343 797188 997748 751515 244459 880581 499279 192690 ...

output:

2126
430 428
428 424
424 416
416 384
384 256
256 0
156 157
157 153
153 145
145 129
129 1
228 230
230 226
226 194
194 130
130 2
211 195
195 131
131 3
7 6
6 4
213 197
197 133
133 5
225 227
227 231
231 230
230 198
198 134
134 6
473 475
475 479
479 471
471 455
455 391
391 263
263 7
68 76
76 72
72 8
271 ...

result:

ok nice! 2126 moves

Test #7:

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

input:

10
46982 476817 496931 560433 461240 750978 947847 814814 659646 506842 759616 931346 752705 449448 557667 164565 805585 139966 935551 743130 400827 826593 316939 597171 566302 42318 283510 548860 557699 464391 241748 310653 488228 677001 434005 590123 338841 574036 303991 216552 454974 914883 31282...

output:

4792
303 302
302 300
300 296
296 288
288 256
256 0
717 713
713 705
705 641
641 513
513 1
860 862
862 858
858 850
850 834
834 770
770 514
514 2
664 665
665 667
667 659
659 643
643 515
515 3
263 262
262 260
260 4
235 239
239 237
237 229
229 197
197 133
133 5
690 694
694 678
678 646
646 518
518 6
740 7...

result:

ok nice! 4792 moves

Test #8:

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

input:

10
949240 35612 460205 974087 338042 271803 334025 63491 750807 279433 899420 120333 875712 396956 17331 903377 75543 841309 975578 209064 858085 265088 990752 382189 453875 707785 91883 487626 999153 989617 672899 730478 89929 619621 96174 915274 438090 705909 682206 236298 574666 885407 168720 540...

output:

4720
930 928
928 896
896 768
768 512
512 0
266 267
267 265
265 257
257 1
762 754
754 738
738 706
706 642
642 514
514 2
717 719
719 715
715 707
707 643
643 515
515 3
370 374
374 372
372 356
356 324
324 260
260 4
561 565
565 549
549 517
517 5
101 103
103 102
102 70
70 6
203 207
207 199
199 135
135 7
4...

result:

ok nice! 4720 moves

Test #9:

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

input:

10
746874 671481 787373 91722 286998 843370 287027 699571 566633 92904 121270 84581 172807 118213 566935 494171 96174 128894 912103 167003 563084 240573 445148 595153 430540 871105 407520 875615 374793 147544 58778 979552 146961 97898 511796 530999 496562 478923 730985 885285 94569 490511 331797 927...

output:

4755
625 624
624 608
608 576
576 512
512 0
708 709
709 705
705 641
641 513
513 1
951 950
950 946
946 930
930 898
898 770
770 514
514 2
834 835
835 771
771 515
515 3
717 716
716 708
708 644
644 516
516 4
991 989
989 981
981 965
965 901
901 773
773 517
517 5
870 838
838 774
774 518
518 6
43 47
47 39
3...

result:

ok nice! 4755 moves

Test #10:

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

input:

10
546693 308346 853356 12952 842161 797467 832954 207696 730371 27541 94381 419145 35259 663666 987797 42166 362364 136282 161216 934180 391497 780167 195044 636218 940656 362727 31072 839926 412136 570431 834451 594285 517357 298316 891244 707769 86006 662265 452173 697662 420751 904255 665271 730...

output:

4737
503 502
502 500
500 496
496 480
480 448
448 384
384 256
256 0
774 775
775 773
773 769
769 513
513 1
793 795
795 794
794 786
786 770
770 514
514 2
332 333
333 335
335 331
331 323
323 259
259 3
77 76
76 68
68 4
923 927
927 925
925 917
917 901
901 773
773 517
517 5
336 338
338 342
342 326
326 262
...

result:

ok nice! 4737 moves

Test #11:

score: 0
Accepted
time: 0ms
memory: 3784kb

input:

1
819419 113088

output:

1
1 0

result:

ok nice! 1 moves

Test #12:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

2
725964 552203 371378 344109

output:

4
3 2
2 0
3 1
3 2

result:

ok nice! 4 moves

Test #13:

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

input:

10
998030 997163 996957 993557 991195 989284 988223 985000 982700 982212 981058 981023 980199 979436 979287 977471 977098 977062 975229 974818 973741 973028 971101 970597 970328 969913 967931 967747 966649 966556 965497 963873 963808 962577 961661 960874 960527 958588 957708 956548 954238 954169 953...

output:

5120
1023 1022
1022 1020
1020 1016
1016 1008
1008 992
992 960
960 896
896 768
768 512
512 0
1023 1021
1021 1017
1017 1009
1009 993
993 961
961 897
897 769
769 513
513 1
1023 1022
1022 1018
1018 1010
1010 994
994 962
962 898
898 770
770 514
514 2
1023 1019
1019 1011
1011 995
995 963
963 899
899 771
7...

result:

ok nice! 5120 moves

Test #14:

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

input:

10
998603 998169 997659 997290 997252 997151 996413 996391 996085 994969 990896 989802 987855 987448 986526 985933 984340 984041 983080 982762 982158 981412 980751 979775 979599 979224 976027 972756 972515 971272 971034 970460 969635 968618 968234 965740 964670 963272 958508 958370 956691 955586 955...

output:

5153
1023 1022
1022 1020
1020 1016
1016 1008
1008 992
992 960
960 896
896 768
768 512
512 0
1023 1021
1021 1017
1017 1009
1009 993
993 961
961 897
897 769
769 513
513 1
1023 1022
1022 1018
1018 1010
1010 994
994 962
962 898
898 770
770 514
514 2
1023 1019
1019 1011
1011 995
995 963
963 899
899 771
7...

result:

ok nice! 5153 moves

Test #15:

score: 0
Accepted
time: 0ms
memory: 3736kb

input:

10
997893 997879 997251 996734 995681 995546 992657 991595 989691 989182 988758 988161 987328 985910 982385 982322 981361 980688 977437 977323 977313 977088 974645 973981 973504 972672 972559 969933 968924 968786 967992 967889 967840 966919 966755 966540 966241 965403 963714 962495 961713 960731 960...

output:

5196
1023 1022
1022 1020
1020 1016
1016 1008
1008 992
992 960
960 896
896 768
768 512
512 0
1023 1021
1021 1017
1017 1009
1009 993
993 961
961 897
897 769
769 513
513 1
1023 1022
1022 1018
1018 1010
1010 994
994 962
962 898
898 770
770 514
514 2
1023 1019
1019 1011
1011 995
995 963
963 899
899 771
7...

result:

ok nice! 5196 moves

Test #16:

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

input:

10
999765 999540 999524 442723 783220 997869 997780 712090 996433 996257 996040 992566 991883 990874 990859 988633 582417 981709 937314 977988 84342 975260 591353 974330 974158 528281 973722 973625 973185 972643 971744 971507 969795 969647 969612 129152 966057 220244 964045 963969 963162 597812 4185...

output:

6093
435 434
434 432
432 416
416 384
384 256
256 0
1022 1023
1023 1021
1021 1017
1017 1009
1009 993
993 961
961 897
897 769
769 513
513 1
1023 1022
1022 1018
1018 1010
1010 994
994 962
962 898
898 770
770 514
514 2
523 515
515 3
1019 1023
1023 1022
1022 1020
1020 1012
1012 996
996 964
964 900
900 77...

result:

ok nice! 6093 moves

Test #17:

score: 0
Accepted
time: 0ms
memory: 3748kb

input:

10
343821 998027 997026 996414 996404 773250 994500 859736 367107 993429 990586 714714 989540 989370 988330 987442 985869 478079 984828 984430 983909 424172 980184 438518 46043 797866 973296 972011 970740 969830 969509 968315 439027 967113 967029 966931 583530 47644 445131 961898 957808 957034 95661...

output:

6044
422 420
420 416
416 384
384 256
256 0
45 41
41 33
33 1
1021 1023
1023 1022
1022 1018
1018 1010
1010 994
994 962
962 898
898 770
770 514
514 2
1020 1021
1021 1023
1023 1019
1019 1011
1011 995
995 963
963 899
899 771
771 515
515 3
1023 1022
1022 1020
1020 1012
1012 996
996 964
964 900
900 772
772...

result:

ok nice! 6044 moves

Test #18:

score: 0
Accepted
time: 0ms
memory: 3724kb

input:

10
999796 853861 338685 673431 997360 508676 986083 623206 985281 261993 455281 984165 806278 365801 983086 329846 836224 107339 978674 500414 976971 553047 53972 897597 287497 368894 966051 965944 25111 965071 162596 862808 962587 907148 336588 664453 959641 958947 958555 958124 954763 951778 95161...

output:

5971
250 248
248 240
240 224
224 192
192 128
128 0
477 473
473 465
465 449
449 385
385 257
257 1
508 510
510 506
506 498
498 482
482 450
450 386
386 258
258 2
195 131
131 3
1019 1023
1023 1022
1022 1020
1020 1012
1012 996
996 964
964 900
900 772
772 516
516 4
634 635
635 639
639 637
637 629
629 613
...

result:

ok nice! 5971 moves

Test #19:

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

input:

10
695647 998457 256203 909670 982894 995992 995387 777482 994669 263854 989569 320493 252841 985455 530388 684573 983066 975593 891430 487880 349963 472375 372708 423420 974655 974388 974301 973152 950030 969447 679648 246707 966536 966376 965740 866666 30143 963819 961332 960251 209174 640492 2202...

output:

5832
1023 1022
1022 1020
1020 1016
1016 1008
1008 992
992 960
960 896
896 768
768 512
512 0
604 605
605 601
601 593
593 577
577 513
513 1
1021 1023
1023 1022
1022 1018
1018 1010
1010 994
994 962
962 898
898 770
770 514
514 2
1023 1019
1019 1011
1011 995
995 963
963 899
899 771
771 515
515 3
1023 102...

result:

ok nice! 5832 moves

Test #20:

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

input:

10
258936 410937 283884 393387 982697 510737 680897 212979 153426 621625 795061 757773 244663 213121 74281 949123 983068 965482 433099 992440 514506 239699 440821 724409 311327 313198 852076 262928 788330 678441 506087 34286 809495 599525 970320 301833 969669 307223 871328 525355 797019 515257 10861...

output:

5057
194 192
192 128
128 0
835 833
833 769
769 513
513 1
353 355
355 354
354 322
322 258
258 2
646 647
647 643
643 515
515 3
867 871
871 870
870 868
868 836
836 772
772 516
516 4
553 557
557 549
549 517
517 5
637 639
639 638
638 630
630 614
614 582
582 518
518 6
193 195
195 199
199 135
135 7
1015 10...

result:

ok nice! 5057 moves

Test #21:

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

input:

10
989539 264003 89801 336845 872805 363863 409608 722546 676281 871400 20414 972543 452474 858575 480750 639385 877845 432002 283043 932719 857101 146837 773058 438046 755472 383841 330153 180919 419122 281693 289297 988547 934831 667163 418404 844342 707371 773251 452058 951076 674998 598366 23071...

output:

4894
644 640
640 512
512 0
516 517
517 513
513 1
922 914
914 898
898 770
770 514
514 2
110 111
111 107
107 99
99 67
67 3
357 356
356 324
324 260
260 4
998 999
999 997
997 965
965 901
901 773
773 517
517 5
985 987
987 991
991 990
990 982
982 966
966 902
902 774
774 518
518 6
554 555
555 559
559 551
5...

result:

ok nice! 4894 moves

Test #22:

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

input:

10
268981 729295 424417 366156 357055 175507 417152 240251 411056 912165 423865 278160 907860 413812 133438 626599 165355 660278 473775 6476 512331 250836 713169 750412 856144 665133 815985 636387 389359 22218 327844 551545 921825 35601 877698 671416 589514 192363 822860 403486 197385 617060 909896 ...

output:

4834
105 104
104 96
96 64
64 0
696 697
697 689
689 673
673 641
641 513
513 1
203 202
202 194
194 130
130 2
19 3
968 972
972 964
964 900
900 772
772 516
516 4
830 831
831 829
829 821
821 805
805 773
773 517
517 5
660 662
662 646
646 518
518 6
747 751
751 743
743 711
711 647
647 519
519 7
464 472
472 ...

result:

ok nice! 4834 moves