QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#233510#3030. Fantastic Compressionjerzyk#AC ✓525ms22088kbC++201.4kb2023-10-31 18:37:192023-10-31 18:37:20

Judging History

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

  • [2023-10-31 18:37:20]
  • 评测
  • 测评结果:AC
  • 用时:525ms
  • 内存:22088kb
  • [2023-10-31 18:37:19]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=25e3+7;
int P[LIM], T[LIM], ile[LIM];
pair<int,int>mi[10];
void solve() {
	int n, k;
	cin >> n >> k;
	rep(i, n) P[i]=T[i]=0;
	rep(i, n-k+1) cin >> P[i];
	rep(i, n-k) T[k+i]=T[i]+P[i+1]-P[i];
	rep(i, k) mi[i]={0, i};
	rep(i, n) mi[i%k]=min(mi[i%k], {T[i], i});
	rep(i, n) T[i]-=mi[i%k].st;
	vector<int>V;
	vector<vector<int>>ans;
	rep(i, k) V.pb(i);
	do {
		vector<int>perm(n);
		rep(i, n) ile[i+1]=0;
		int l=1;
		bool ok=true;
		for(auto i : V) {
			while(ile[l]) ++l;
			for(int j=i; j<n; j+=k) {
				if(1<=l+T[j] && l+T[j]<=n) {
					++ile[l+T[j]];
					perm[j]=l+T[j];
				} else {
					ok=false;
					break;
				}
			}
			if(!ok) break;
		}
		if(!ok) continue;
		int ma=0;
		rep(i, n) ma=max(ma, ile[i+1]);
		if(ma!=1) continue;
		int sum=0;
		rep(i, k) sum+=perm[i];
		rep(i, n-k+1) {
			if(sum!=P[i]) ok=false;
			if(i+k<n) sum+=perm[i+k];
			sum-=perm[i];
		}
		if(ok) ans.pb(perm);
	} while(next_permutation(all(V)));
	sort(all(ans));
	cout << ans.size() << '\n';
	for(auto i : ans) {
		for(auto j : i) {
			cout << j << " ";
		}
		cout << '\n';
	}
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int _=1;
	cin >> _;
	while(_--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 8ms
memory: 3632kb

input:

964
5 4
10 11
5 3
9 8 10
5 2
9 6 5 4
4 4
9
4 4
9
5 4
13 11
5 3
11 10 10
4 2
4 6 3
5 4
12 13
5 3
9 12 9
5 2
9 8 6 3
5 3
10 8 7
5 3
7 10 9
5 4
13 14
5 3
7 8 11
4 2
6 7 4
4 4
11
4 3
8 6
5 3
7 6 6
5 3
10 9 11
5 4
10 11
5 3
12 9 8
5 5
15
5 3
9 10 7
5 5
15
4 2
4 7 6
5 2
4 5 9 7
5 2
6 3 6 7
5 3
7 6 9
4 2
3...

output:

6
4 1 2 3 5 
4 1 3 2 5 
4 2 1 3 5 
4 2 3 1 5 
4 3 1 2 5 
4 3 2 1 5 
1
2 3 4 1 5 
1
5 4 2 3 1 
0
0
6
4 1 3 5 2 
4 1 5 3 2 
4 3 1 5 2 
4 3 5 1 2 
4 5 1 3 2 
4 5 3 1 2 
0
0
6
2 1 4 5 3 
2 1 5 4 3 
2 4 1 5 3 
2 4 5 1 3 
2 5 1 4 3 
2 5 4 1 3 
2
1 5 3 4 2 
2 4 3 5 1 
0
1
3 5 2 1 4 
1
2 4 1 5 3 
6
1 3 4 5 ...

result:

ok 21593 lines

Test #2:

score: 0
Accepted
time: 75ms
memory: 4316kb

input:

11
23853 5
56129 66231 66759 74651 77738 77157 85513 66445 73648 57593 74488 61493 64993 60263 75748 73267 81681 86675 92728 73438 57233 47483 52402 42838 42284 58984 70785 56245 55687 58425 43712 34748 37286 34598 31262 36760 48165 57037 66885 67122 67572 62188 51356 32408 33791 44793 45602 58279 6...

output:

1
1955 20238 7208 20162 6566 12057 20766 15100 23249 5985 20413 1698 22303 7194 22880 7418 5198 17573 22679 20399 15832 10192 23626 3389 4194 6082 15111 14062 2835 20894 17883 571 13504 5573 6181 8919 3109 10816 2237 11679 20324 11981 20664 2474 12129 14940 1149 1716 3857 23131 15749 13826 5377 8992...

result:

ok 16 lines

Test #3:

score: 0
Accepted
time: 525ms
memory: 22088kb

input:

7
6666 6
16671 16672 16673 16674 16675 16676 16677 16678 16679 16680 16681 16682 16683 16684 16685 16686 16687 16688 16689 16690 16691 16692 16693 16694 16695 16696 16697 16698 16699 16700 16701 16702 16703 16704 16705 16706 16707 16708 16709 16710 16711 16712 16713 16714 16715 16716 16717 16718 167...

output:

720
1 1112 2223 3334 4445 5556 2 1113 2224 3335 4446 5557 3 1114 2225 3336 4447 5558 4 1115 2226 3337 4448 5559 5 1116 2227 3338 4449 5560 6 1117 2228 3339 4450 5561 7 1118 2229 3340 4451 5562 8 1119 2230 3341 4452 5563 9 1120 2231 3342 4453 5564 10 1121 2232 3343 4454 5565 11 1122 2233 3344 4455 55...

result:

ok 971 lines