QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#347228#6353. Kth Lex Min Min Min Subpalindromeschenxinyang2006AC ✓47ms15652kbC++142.6kb2024-03-09 12:28:192024-03-09 12:28:19

Judging History

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

  • [2024-03-09 12:28:19]
  • 评测
  • 测评结果:AC
  • 用时:47ms
  • 内存:15652kb
  • [2024-03-09 12:28:19]
  • 提交

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,m;
ll k;

int a[2333];
vector <int> SS;
void constr(int N){
	int l,r,bst = inf,cur;
	rep(S,0,(1 << N) - 1){
		rep(i,0,N - 1) a[i + 1] = (S >> i) & 1;
		cur = 0;
		rep(i,1,N){
			l = r = i;
			cur++;
			while(l > 1 && r < N && a[l - 1] == a[r + 1]){
				l--;r++;
				cur++;
			}
		} 
		rep(i,1,N - 1){
			l = i + 1;r = i;
			while(l > 1 && r < N && a[l - 1] == a[r + 1]){
				l--;r++;
				cur++;
			}
		}
		if(cur < bst){
			bst = cur;
			SS.clear();
		}
		if(cur == bst) SS.eb(S);
	}
}

int ans[1000005];
void solve2(){
	constr(min(n,10));
	if(k > SZ(SS)){
		printf("-1\n");
		return;
	}	
	int sz = min(n,10);
	per(i,sz - 1,0) ans[i + 1] = ((SS[k - 1] >> i) & 1) + 1;
	reverse(ans + 1,ans + sz + 1);
	rep(i,1,n){
		if(i > sz) ans[i] = ans[i - 6];
		printf("%d ",ans[i]);
	}
	printf("\n");
}

#define lll __int128
ll mul(ll x,ll y){
	lll ret = (lll)x * y;
	if(ret > linf) return linf;
	return ret;
}

ll base[1000005];
int main(){
//	freopen("test.in","r",stdin);
	scanf("%d%d%lld",&n,&m,&k);
	if(m == 1){
		if(k == 1){
			rep(i,1,n) printf("1 ");
			printf("\n");
		}else{
			printf("-1\n");
		}
		return 0;
	}
	if(m == 2){
		solve2();
		return 0;
	}
	base[n + 1] = 1; 
	per(i,n,1) base[i] = mul(base[i + 1],m + 1 - min(3,i));
	k--;
	if(k >= base[1]){
		printf("-1\n");
		return 0;
	}
	rep(i,1,n){
		ans[i] = 1 + k / base[i + 1];
		k %= base[i + 1];
		if(i >= 2 && ans[i] >= ans[i - 1]){
			ans[i]++;
			if(i >= 3 && ans[i] >= ans[i - 2]) ans[i]++;
		}else{
			if(i >= 3 && ans[i] >= ans[i - 2]){
				ans[i]++;
				if(i >= 2 && ans[i] >= ans[i - 1]) ans[i]++;
			}
		}
		printf("%d ",ans[i]);
	}
	printf("\n");
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3860kb

input:

1 1 1

output:

1 

result:

ok 1 number(s): "1"

Test #2:

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

input:

2 2 2

output:

2 1 

result:

ok 2 number(s): "2 1"

Test #3:

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

input:

3 3 3

output:

2 1 3 

result:

ok 3 number(s): "2 1 3"

Test #4:

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

input:

9 9 8244353

output:

2 4 1 2 6 8 1 2 7 

result:

ok 9 numbers

Test #5:

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

input:

10 7 998244353

output:

-1

result:

ok 1 number(s): "-1"

Test #6:

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

input:

3 1000 994253860

output:

998 244 353 

result:

ok 3 number(s): "998 244 353"

Test #7:

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

input:

58 4 864691128455135232

output:

4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 

result:

ok 58 numbers

Test #8:

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

input:

58 4 864691128455135233

output:

-1

result:

ok 1 number(s): "-1"

Test #9:

score: 0
Accepted
time: 43ms
memory: 15464kb

input:

1000000 1000000 1000000000000000000

output:

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 ...

result:

ok 1000000 numbers

Test #10:

score: 0
Accepted
time: 43ms
memory: 15652kb

input:

1000000 4 1000000000000000000

output:

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 ...

result:

ok 1000000 numbers

Test #11:

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

input:

1 1 2

output:

-1

result:

ok 1 number(s): "-1"

Test #12:

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

input:

1 2 2

output:

2 

result:

ok 1 number(s): "2"

Test #13:

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

input:

2 2 1

output:

1 2 

result:

ok 2 number(s): "1 2"

Test #14:

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

input:

3 2 4

output:

2 1 1 

result:

ok 3 number(s): "2 1 1"

Test #15:

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

input:

3 2 7

output:

-1

result:

ok 1 number(s): "-1"

Test #16:

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

input:

4 2 10

output:

2 2 1 2 

result:

ok 4 number(s): "2 2 1 2"

Test #17:

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

input:

4 2 3

output:

1 2 1 1 

result:

ok 4 number(s): "1 2 1 1"

Test #18:

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

input:

5 2 7

output:

2 1 1 2 1 

result:

ok 5 number(s): "2 1 1 2 1"

Test #19:

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

input:

5 2 13

output:

-1

result:

ok 1 number(s): "-1"

Test #20:

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

input:

6 2 5

output:

1 2 2 1 1 2 

result:

ok 6 numbers

Test #21:

score: 0
Accepted
time: 34ms
memory: 7816kb

input:

1000000 2 3

output:

1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 ...

result:

ok 1000000 numbers

Test #22:

score: 0
Accepted
time: 39ms
memory: 7768kb

input:

1000000 2 5

output:

1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 ...

result:

ok 1000000 numbers

Test #23:

score: 0
Accepted
time: 34ms
memory: 7832kb

input:

1000000 2 7

output:

2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 ...

result:

ok 1000000 numbers

Test #24:

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

input:

1000000 2 1000000000000000000

output:

-1

result:

ok 1 number(s): "-1"

Test #25:

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

input:

1 3 2

output:

2 

result:

ok 1 number(s): "2"

Test #26:

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

input:

2 3 5

output:

3 1 

result:

ok 2 number(s): "3 1"

Test #27:

score: 0
Accepted
time: 39ms
memory: 15580kb

input:

1000000 3 5

output:

3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 ...

result:

ok 1000000 numbers

Test #28:

score: 0
Accepted
time: 3ms
memory: 11612kb

input:

1000000 3 7

output:

-1

result:

ok 1 number(s): "-1"

Test #29:

score: 0
Accepted
time: 40ms
memory: 15616kb

input:

1000000 4 211106232532991

output:

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 ...

result:

ok 1000000 numbers

Test #30:

score: 0
Accepted
time: 39ms
memory: 15616kb

input:

1000000 5 1000000000000000000

output:

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 ...

result:

ok 1000000 numbers

Test #31:

score: 0
Accepted
time: 47ms
memory: 15604kb

input:

1000000 123123 1000000000000000000

output:

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 ...

result:

ok 1000000 numbers

Test #32:

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

input:

6 1000000 1000000000000000000

output:

1 2 4 9 15 8 

result:

ok 6 numbers

Test #33:

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

input:

4 1000000 1000000000000000000

output:

2 7 15 9 

result:

ok 4 number(s): "2 7 15 9"

Test #34:

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

input:

3 1000000 999997000002000000

output:

1000000 999999 999998 

result:

ok 3 number(s): "1000000 999999 999998"

Test #35:

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

input:

3 1000000 999997000002000001

output:

-1

result:

ok 1 number(s): "-1"