176592025-08-27 22:14:11PajerLeviLCS of Permutationscpp17Time limit exceeded 0/1004.105s262144 KiB
#include<bits/stdc++.h>

using namespace std;

int main(){
	int t;
	cin >> t;
	while(t--){
		int n, a, b, c, output;
		cin >> n >> a >> b >> c >> output;
		/*if(b==n-c+1){
			cout << "YES\n";
			if(output){
				for(int i=0;i<n;i++) cout << n-i << ' ';
				cout << '\n';
				for(int i=0;i<n;i++) cout << i+1 << ' ';
				cout << '\n';
				for(int i=0;i<=n-c;i++) cout << n-c-i+1 << ' ';
				for(int i=n-c+1;i<n;i++) cout << i+1 << ' ';
				cout << '\n';
			}
		}
		else{
			cout << "NO\n";
		}*/
		vector<int> p(n), q(n), r(n);
		iota(p.begin(), p.end(), 1);
		iota(q.begin(), q.end(), 1);
		iota(r.begin(), r.end(), 1);
		bool found=false;
		vector<vector<int>> dp1(n+1, vector<int>(n+1)), dp2(n+1, vector<int>(n+1)), dp3(n+1, vector<int>(n+1));
		do{
			do{
				for(int i=1;i<=n;i++){
					for(int j=1;j<=n;j++){
						dp1[i][j]=max(dp1[i-1][j], dp1[i][j-1]);
						if(p[i-1]==q[j-1]) dp1[i][j]=max(dp1[i][j], dp1[i-1][j-1]+1);
						if(a<dp1[i][j]) continue;
					}
				}
				if(dp1[n][n]!=a) continue;
				do{
					for(int i=1;i<=n;i++){
						for(int j=1;j<=n;j++){
							dp2[i][j]=max(dp2[i-1][j], dp2[i][j-1]);
							if(p[i-1]==r[j-1]) dp2[i][j]=max(dp2[i][j], dp2[i-1][j-1]+1);
							if(b<dp2[i][j]) continue;
						}
					}
					if(dp2[n][n]!=b) continue;
					for(int i=1;i<=n;i++){
						for(int j=1;j<=n;j++){
							dp3[i][j]=max(dp3[i-1][j], dp3[i][j-1]);
							if(q[i-1]==r[j-1]) dp3[i][j]=max(dp3[i][j], dp3[i-1][j-1]+1);
							if(c<dp3[i][j]) continue;
						}
					}
					if(dp3[n][n]!=c) continue;
					cout << "YES\n";
					for(int x : p) cout << x << ' ';
					cout << '\n';
					for(int x : q) cout << x << ' ';
					cout << '\n';
					for(int x : r) cout << x << ' ';
					cout << '\n';
					found=true;
					break;
				} while(next_permutation(r.begin(), r.end()));
				if(found) break;
			} while(next_permutation(q.begin(), q.end()));
			if(found) break;
		} while(next_permutation(p.begin(), p.end()));
		if(!found) cout << "NO\n";
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
00/0
1Time limit exceeded0/04.078s500 KiB
10/3
2Time limit exceeded4.087s3380 KiB
3Runtime error203ms262144 KiB
4Runtime error244ms262144 KiB
5Runtime error206ms262144 KiB
6Runtime error250ms262144 KiB
7Time limit exceeded4.08s19508 KiB
8Time limit exceeded4.099s316 KiB
9Time limit exceeded4.076s408 KiB
20/8
10Time limit exceeded0/84.085s316 KiB
30/10
11Time limit exceeded4.084s316 KiB
12Runtime error207ms262144 KiB
13Runtime error246ms262144 KiB
14Runtime error244ms262144 KiB
15Runtime error202ms262144 KiB
16Runtime error244ms262144 KiB
17Runtime error241ms262144 KiB
18Runtime error202ms262144 KiB
19Runtime error239ms262144 KiB
20Runtime error243ms262144 KiB
21Runtime error202ms262144 KiB
22Runtime error250ms262144 KiB
23Runtime error238ms262144 KiB
24Runtime error206ms262144 KiB
25Runtime error209ms262144 KiB
26Runtime error248ms262144 KiB
27Time limit exceeded4.092s104756 KiB
28Time limit exceeded4.087s20280 KiB
29Runtime error208ms262144 KiB
30Time limit exceeded4.084s19508 KiB
31Time limit exceeded4.084s1332 KiB
32Time limit exceeded4.086s316 KiB
33Time limit exceeded4.077s316 KiB
34Time limit exceeded4.087s316 KiB
40/17
35Time limit exceeded4.086s508 KiB
36Runtime error241ms262144 KiB
37Runtime error202ms262144 KiB
38Runtime error202ms262144 KiB
39Runtime error202ms262144 KiB
40Runtime error239ms262144 KiB
41Runtime error225ms262144 KiB
42Runtime error202ms262144 KiB
43Runtime error245ms262144 KiB
44Runtime error202ms262144 KiB
45Runtime error216ms262144 KiB
46Runtime error209ms262144 KiB
47Runtime error239ms262144 KiB
48Runtime error208ms262144 KiB
49Runtime error207ms262144 KiB
50Runtime error244ms262144 KiB
51Time limit exceeded4.099s104748 KiB
52Time limit exceeded4.084s20276 KiB
53Runtime error202ms262144 KiB
54Time limit exceeded4.085s19692 KiB
55Time limit exceeded4.09s1332 KiB
56Time limit exceeded4.079s316 KiB
57Time limit exceeded4.099s316 KiB
58Time limit exceeded4.078s404 KiB
50/22
59Time limit exceeded4.089s500 KiB
60Runtime error209ms262144 KiB
61Time limit exceeded4.091s2100 KiB
62Runtime error256ms262144 KiB
63Time limit exceeded4.09s2284 KiB
64Time limit exceeded4.078s3636 KiB
65Runtime error246ms262144 KiB
66Runtime error203ms262144 KiB
67Runtime error241ms262144 KiB
68Time limit exceeded4.08s9784 KiB
69Runtime error201ms262144 KiB
70Runtime error239ms262144 KiB
71Runtime error244ms262144 KiB
72Time limit exceeded4.099s316 KiB
73Time limit exceeded4.105s74804 KiB
74Time limit exceeded4.08s820 KiB
75Runtime error202ms262144 KiB
76Runtime error202ms262144 KiB
77Runtime error207ms262144 KiB
78Time limit exceeded4.099s6452 KiB
79Time limit exceeded4.079s508 KiB
80Time limit exceeded4.09s316 KiB
81Time limit exceeded4.098s564 KiB
82Time limit exceeded4.084s316 KiB
83Time limit exceeded4.074s1332 KiB
84Time limit exceeded4.078s316 KiB
85Time limit exceeded4.098s316 KiB
86Time limit exceeded4.078s404 KiB
60/40
87Time limit exceeded0/404.08s500 KiB
88Time limit exceeded0/04.083s3636 KiB
89Runtime error0/0247ms262144 KiB
90Runtime error0/0203ms262144 KiB
91Runtime error0/0206ms262144 KiB
92Time limit exceeded0/04.087s9780 KiB
93Runtime error0/0202ms262144 KiB
94Runtime error0/0203ms262144 KiB
95Runtime error0/0204ms262144 KiB
96Time limit exceeded0/04.087s508 KiB
97Time limit exceeded0/04.085s75068 KiB
98Time limit exceeded0/04.078s820 KiB
99Runtime error0/0202ms262144 KiB
100Runtime error0/0202ms262144 KiB
101Runtime error0/0204ms262144 KiB
102Time limit exceeded0/04.09s6452 KiB
103Time limit exceeded0/04.079s316 KiB
104Time limit exceeded0/04.085s316 KiB
105Time limit exceeded0/04.098s564 KiB
106Time limit exceeded0/04.078s316 KiB
107Time limit exceeded0/04.087s1332 KiB
108Time limit exceeded0/04.085s316 KiB
109Time limit exceeded0/04.099s316 KiB
110Time limit exceeded0/04.083s316 KiB