QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#586924#8805. Pizza Partychenxinyang2006#4 38ms14512kbC++201.9kb2024-09-24 16:33:462024-09-24 16:33:47

Judging History

This is the latest submission verdict.

  • [2024-09-24 16:33:47]
  • Judged
  • Verdict: 4
  • Time: 38ms
  • Memory: 14512kb
  • [2024-09-24 16:33:46]
  • Submitted

answer

#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;

template <class T>
void chkmax(T &x,T y){
	if(x < y) x = y;
}

template <class T>
void chkmin(T &x,T y){
	if(x > y) x = y;
}

inline int popcnt(int x){
	return __builtin_popcount(x);
}

inline int ctz(int x){
	return __builtin_ctz(x);
}


/*ll power(ll p,int k = mod - 2){
	ll ans = 1;
	while(k){
		if(k % 2 == 1) ans = ans * p % mod;
		p = p * p % mod;
		k /= 2;	
	}
	return ans;
}*/
int n;
int a[1000005],b[1000005],occ[2][1000005],A[1000005];

void Set(int &x,int y){
	if(x){
		printf("-1\n");
		exit(0);
	}
	x = y;
}

int m;
int dp[1000005];
vector <int> sta[1000005];
void up(int x,int y){
	sta[x].eb(y);
}

void dwn(int x,int y){
	assert(!sta[x].empty() && sta[x].back() == y);
	sta[x].pop_back();
}

int main(){	
//	freopen("test.in","r",stdin);
	scanf("%d",&n);
	rep(i,1,n){
		scanf("%d",&a[i]);
		Set(occ[0][a[i]],i);
	}
	rep(i,1,n){
		scanf("%d",&b[i]);
		Set(occ[1][b[i]],i);
	}
	rep(i,1,n){
		A[i] = occ[1][a[i]];
	}
	rep(i,1,n){
		dp[i] = 1;
		rep(j,1,i - 1) if(A[j] < A[i]) chkmax(dp[i],dp[j] + 1);
		chkmax(m,dp[i]);
	}
	rep(i,1,n) up(dp[i],a[i]);
	rep(i,1,n) dwn(dp[occ[0][b[i]]],b[i]);

	printf("%d\n",m);
	rep(i,1,n){
		printf("%d",dp[i]);
		if(i < n) printf(" ");
		else printf("\n");
	}
	rep(i,1,n){
		printf("%d",dp[occ[0][b[i]]]);
		if(i < n) printf(" ");
		else printf("\n");
	}
	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 5940kb

input:

1000000
1 1 1 2 1 1 1 1 1 2 1 1 1 2 1 2 1 1 1 2 2 1 2 1 2 2 2 2 2 1 2 2 1 1 1 2 1 1 2 1 2 2 2 2 2 2 2 1 2 1 2 2 1 1 2 1 2 2 2 1 1 2 2 1 1 1 1 2 1 2 2 1 2 2 2 1 2 1 1 2 1 1 1 2 1 2 2 1 1 1 2 2 2 2 1 2 1 1 1 2 2 2 1 1 1 1 1 2 2 2 1 1 1 2 2 2 2 1 2 2 2 1 2 1 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 1 2 1 1 2 1 ...

output:

-1

result:

wrong answer jury uses fewer stacks: jans = 2, pans = 1061109567

Subtask #2:

score: 4
Accepted

Test #24:

score: 4
Accepted
time: 35ms
memory: 12228kb

input:

5000
3140 3541 3540 3884 2792 3966 1359 549 2273 2669 2100 4448 4722 3937 23 3964 4910 3490 61 2723 2554 4177 3025 4909 2127 939 2536 835 2801 459 3374 972 4687 2102 2919 4367 4905 3414 869 2272 507 4210 2906 2584 1639 2020 3287 3447 2500 4866 3284 2010 1826 331 1873 3895 4946 889 3059 894 4233 2541...

output:

134
1 1 2 2 1 3 3 3 4 5 1 6 5 2 6 7 7 4 3 3 3 7 8 9 6 10 2 7 10 3 9 4 4 3 10 5 8 6 4 7 3 4 8 9 6 5 7 11 8 10 9 9 10 11 12 5 12 9 10 7 3 6 9 7 10 6 11 13 12 7 12 13 13 8 14 12 15 16 10 15 17 11 1 5 8 9 10 17 16 11 15 10 10 3 3 16 4 17 18 11 16 15 12 11 8 7 13 12 11 12 13 9 12 13 4 17 14 6 14 6 17 15 ...

result:

ok good job!

Test #25:

score: 4
Accepted
time: 0ms
memory: 7956kb

input:

5000
4578 3847 1800 2885 967 324 4074 3778 2704 4767 1568 1699 1141 4576 3887 1284 69 4730 153 3305 3397 1295 1928 958 573 3436 1244 105 4529 4647 1428 4237 2776 2491 3747 3068 1150 719 4205 3174 4040 2867 2083 821 4822 717 3291 3595 3063 2883 1510 3874 3859 2500 4679 4522 1336 716 319 53 3576 593 4...

output:

-1

result:

ok good job!

Test #26:

score: 4
Accepted
time: 34ms
memory: 12148kb

input:

5000
1838 1490 3227 3011 2539 3994 2825 2349 506 2396 1818 2845 3279 3554 2441 4510 2168 3269 1691 4180 1107 4493 3390 3964 4323 2487 2182 3246 4710 2408 2989 3925 1600 3070 2522 3786 585 4756 4000 1023 2033 2963 2665 2728 1489 4749 3674 708 1975 1298 1293 466 1750 1272 1859 4748 3429 4937 1158 4917...

output:

132
1 2 1 1 2 3 2 4 4 2 3 3 4 5 6 7 1 6 2 7 7 8 8 4 8 9 6 1 5 6 7 9 8 9 3 5 3 10 8 3 2 2 9 10 10 7 3 4 5 7 11 8 6 7 11 9 10 11 12 12 11 7 12 11 8 4 13 3 14 14 9 10 15 10 13 16 17 8 9 8 14 11 17 14 2 18 4 19 10 8 12 5 11 19 18 10 11 12 16 2 18 14 13 13 13 14 17 15 15 15 9 13 10 18 16 12 10 15 19 14 1...

result:

ok good job!

Test #27:

score: 4
Accepted
time: 2ms
memory: 7944kb

input:

5000
1377 4891 4834 4667 4174 3490 441 3314 437 4271 89 913 199 2634 4005 2379 1562 963 80 3691 3493 2385 1079 1625 921 3863 4354 2874 2575 2167 1011 4203 2767 4998 102 1685 1283 4204 4091 4804 4869 16 4359 195 1693 1012 315 2708 4794 1684 818 1262 161 2391 3832 575 2732 352 1767 1918 4773 3432 2127...

output:

-1

result:

ok good job!

Test #28:

score: 4
Accepted
time: 38ms
memory: 12152kb

input:

5000
4864 2930 3469 4883 755 4142 1509 1713 1778 1406 2427 3263 2482 3440 2401 1516 306 1419 1363 2783 4245 2249 3954 409 1076 2922 3908 1949 1222 4164 3050 582 1722 3788 4906 4381 1235 4117 4846 1218 942 3721 1990 3053 4928 2267 692 3104 142 1658 2806 3897 4428 684 1764 1685 3203 3092 440 3168 4165...

output:

130
1 2 3 4 1 2 3 4 3 4 5 5 5 6 6 3 6 7 1 6 1 2 3 2 7 4 1 7 1 2 1 6 3 8 2 5 8 2 9 9 4 8 10 4 5 6 9 7 8 11 9 2 8 10 11 8 12 13 3 3 12 1 9 13 9 10 12 4 8 3 11 10 1 12 11 12 12 11 6 13 2 9 14 7 4 9 12 5 12 6 3 14 15 4 5 6 7 1 9 15 13 9 14 16 8 11 10 10 14 3 16 8 9 9 14 4 8 9 11 12 8 10 10 15 14 17 11 1...

result:

ok good job!

Test #29:

score: 4
Accepted
time: 2ms
memory: 7964kb

input:

5000
3320 1681 1730 1944 2400 2712 3710 1634 3295 1653 2615 837 2704 1506 3356 1571 4735 1738 4297 2317 4240 1095 3935 666 2676 2302 4213 4152 2748 1103 2188 1386 1300 3917 4142 1829 1793 2836 2814 3595 3060 212 460 4633 1053 3322 483 3806 4625 3046 1294 4194 2956 1281 2837 3551 4779 1876 4629 1422 ...

output:

-1

result:

ok good job!

Test #30:

score: 4
Accepted
time: 2ms
memory: 8032kb

input:

5000
2013 837 2709 828 182 1161 3695 3964 2602 429 3516 1374 686 4942 2941 1365 2976 808 2638 3599 1133 4537 3069 4981 285 2858 1486 4661 4345 4517 3683 3413 1310 3794 566 4374 4042 262 307 424 648 4219 1293 2104 4782 2378 4937 1687 3888 1660 1288 3935 2071 1527 4949 3902 2118 1144 3336 1609 3474 33...

output:

-1

result:

ok good job!

Test #31:

score: 4
Accepted
time: 35ms
memory: 14132kb

input:

5000
2178 3304 278 3675 3343 3283 3660 4470 2202 2263 3855 2325 551 1900 1263 3501 1559 1373 3408 3885 4177 4391 4758 1717 3012 4848 831 4357 4899 4992 3091 747 2225 703 1250 1285 2496 733 1062 2211 857 3255 1230 3084 889 470 3672 414 3925 413 3544 397 775 3065 2478 2060 2617 1241 2463 4161 1580 364...

output:

139
1 2 2 2 3 4 2 2 4 5 3 5 3 5 5 6 4 5 4 7 4 4 6 7 8 6 6 7 9 5 3 6 4 10 7 5 8 8 9 10 6 11 4 4 3 11 9 6 4 12 11 11 13 7 7 12 14 13 15 6 14 5 8 13 12 15 9 7 10 7 11 12 13 9 5 9 6 6 14 16 13 7 10 7 1 15 12 11 13 14 15 16 12 7 11 10 15 17 8 4 14 6 16 15 16 16 12 12 10 2 16 8 17 17 9 7 18 8 19 20 19 10 ...

result:

ok good job!

Test #32:

score: 4
Accepted
time: 34ms
memory: 12140kb

input:

5000
70 4640 3524 4107 3413 3819 1432 3069 4309 3527 3626 1208 2716 1849 2307 649 3217 4148 2989 26 955 605 1378 4994 1072 4487 3929 1666 1972 3795 4167 4829 1128 2671 4277 4627 589 4349 664 2960 2609 1321 3113 1996 2836 4836 4831 2736 3228 2617 2235 1946 1106 4738 4047 99 71 2625 4514 2239 4966 385...

output:

138
1 2 3 3 3 4 5 4 6 5 6 6 1 7 5 2 2 6 3 7 2 8 7 9 9 10 2 9 5 10 7 6 10 8 7 11 3 7 4 3 8 4 9 12 1 2 5 6 3 9 10 1 6 11 3 7 11 12 6 7 9 10 8 10 12 13 7 14 8 8 3 15 4 7 6 9 9 8 3 12 5 6 11 13 14 10 10 9 5 16 11 12 10 11 14 12 6 13 14 11 3 12 15 14 9 11 15 15 6 8 12 14 16 9 15 2 7 10 16 16 17 13 17 9 7...

result:

ok good job!

Test #33:

score: 4
Accepted
time: 38ms
memory: 12072kb

input:

5000
2445 3775 921 4693 1784 1523 2190 2637 3512 297 129 4821 3415 3867 1509 4401 4580 599 4328 2790 1290 4592 571 2187 545 3632 3813 4405 2439 4610 3456 4617 3595 4467 3350 3457 2968 3388 4901 3397 304 4565 4450 3447 540 3993 3382 2147 978 1959 2126 4743 1827 2314 527 964 521 4985 2849 4116 2940 40...

output:

126
1 1 1 2 3 4 2 3 1 3 3 1 2 2 3 4 4 5 1 5 3 6 2 6 4 2 4 4 7 8 5 8 5 5 4 5 7 6 7 3 6 7 8 3 8 7 8 5 6 7 5 2 8 9 4 5 5 6 7 10 4 2 9 9 10 3 6 11 1 11 4 5 6 3 9 8 3 11 10 6 9 7 7 7 8 10 11 9 11 1 12 7 10 13 6 10 14 12 2 13 15 15 16 17 4 10 7 6 11 17 5 12 12 16 8 4 6 18 17 14 9 5 14 19 10 18 7 11 8 6 15...

result:

ok good job!

Test #34:

score: 4
Accepted
time: 12ms
memory: 12380kb

input:

5000
1568 2325 1902 74 3720 2756 2692 771 73 4932 4816 2402 540 908 701 2417 3566 2933 4765 1082 6 1249 830 1231 1755 1983 4151 1427 4237 2258 2110 4263 1786 1790 1843 2590 4098 2873 2194 3259 3378 679 1117 564 3322 3314 4477 1982 4613 1055 4917 4706 4 1057 50 225 1675 1564 1921 4025 2611 139 3999 2...

output:

5000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101...

result:

ok good job!

Test #35:

score: 4
Accepted
time: 8ms
memory: 12116kb

input:

5000
1445 4864 1501 3046 635 4037 2219 2636 4030 1902 1864 3916 2239 2621 4113 2528 3876 153 1868 1188 2062 2241 161 2376 3123 999 3338 1482 291 1361 4944 1652 3828 1649 553 3898 3641 2242 3658 3912 2359 2422 3322 4922 4583 1928 4558 183 1315 4847 4936 1897 2337 2525 672 1708 2618 3554 4975 735 2894...

output:

1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

result:

ok good job!

Test #36:

score: 4
Accepted
time: 9ms
memory: 14512kb

input:

5000
1898 4597 2541 1021 1144 4174 2629 481 3581 1233 36 4525 1256 2063 3498 2283 2385 3477 1926 4802 184 4553 1660 1607 3763 1024 3758 1839 1814 2862 613 4017 2081 4358 2400 1658 1408 3228 2542 4411 3691 3215 1610 2332 4481 4397 257 1056 2508 3293 4800 4199 45 1078 2510 4291 3306 2129 870 150 2771 ...

output:

4990
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101...

result:

ok good job!

Test #37:

score: 4
Accepted
time: 11ms
memory: 12064kb

input:

5000
1400 3821 4858 3981 3206 3764 3211 1973 2509 1514 1782 1324 3642 956 2345 2284 4254 1411 2786 2103 734 2613 1504 3676 3595 4305 3570 4201 4224 2644 2005 1237 2864 2434 653 3635 1201 4164 4922 149 3422 4284 2998 2633 957 717 3045 737 2832 1881 4255 4867 4083 1168 1896 1159 647 698 4293 3167 2440...

output:

3
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

result:

ok good job!

Test #38:

score: 4
Accepted
time: 3ms
memory: 7984kb

input:

5000
4039 1530 2881 4442 3802 2332 3753 807 3959 3832 2359 2580 1187 456 3606 3722 1086 2095 2254 4379 2490 1634 3276 135 329 2161 1681 1664 425 3893 3894 1575 3772 3775 3381 4578 891 2217 3257 3447 2247 1920 2654 3228 4383 1074 2447 1007 751 1249 3829 3461 2499 3682 57 588 1593 1906 2662 1172 193 6...

output:

-1

result:

ok good job!

Subtask #3:

score: 0
Time Limit Exceeded

Test #39:

score: 0
Time Limit Exceeded

input:

1000000
134990 280863 995875 82485 490673 517020 49269 636214 69331 626226 96180 743288 524606 324456 937362 164072 680663 931183 195920 618400 741187 164410 478750 590824 160168 192530 154228 661164 17160 343556 653139 229351 350929 719054 634472 433811 352199 163260 833268 56711 963125 346135 9350...

output:


result: