QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#203258#6353. Kth Lex Min Min Min SubpalindromesqzzyqAC ✓48ms19676kbC++142.7kb2023-10-06 16:27:152023-10-06 16:27:16

Judging History

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

  • [2023-10-06 16:27:16]
  • 评测
  • 测评结果:AC
  • 用时:48ms
  • 内存:19676kb
  • [2023-10-06 16:27:15]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define maxn 1000005
#define put() putchar('\n')
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
using namespace std;
void read(int &x){
    int f=1;x=0;char c=getchar();
    while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
    while (c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
    x*=f;
}
namespace Debug{
	Tp void _debug(char* f,Ty t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,Ty x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	Tp ostream& operator<<(ostream& os,vector<Ty>& V){os<<"[";for(auto& vv:V) os<<vv<<",";os<<"]";return os;}
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
}using namespace Debug;
#define fi first
#define se second
#define mk make_pair
const int mod=1e9+7;
int power(int x,int y=mod-2) {
	int sum=1;
	while (y) {
		if (y&1) sum=sum*x%mod;
		x=x*x%mod;y>>=1;
	}
	return sum;
}
int n,m,k;
vector<int> gen(int S,int n) {
	vector<int>a;int i;
	for (i=n-1;i>=0;i--) a.push_back((S>>i)&1);
	return a; 
}
int calc(vector<int>a,int n) {
	int ans=0,i;
	for (i=0;i<n;i++) {
		int j=1;
		while (i-j>=0&&i+j<=n-1&&a[i-j]==a[i+j]) j++;
		ans+=j;
	}
	for (i=1;i<n;i++) if (a[i]==a[i-1]) {
		int j=1;
		while (i-j-1>=0&&i+j<=n-1&&a[i-j-1]==a[i+j]) j++;
		ans+=j;
	}
	return ans;
} 
void solve(void) {
	int N=min(n,6ll),i,j,Min=1e9;
	for (i=0;i<(1<<N);i++) Min=min(Min,calc(gen(i,N),N));
	for (i=0;i<(1<<N);i++) {
		int tmp=calc(gen(i,N),N);
		if (tmp==Min) {
			if (!(--k)) {
				vector<int>a=gen(i,N);
				for (j=0;j<n;j++) printf("%d ",a[j%N]+1);
				exit(0);
			}
		}
	}
	puts("-1");
}
int ans[maxn],pw[maxn];
void print(int id,int res) {
	int i;
//	gdb(id,res,ans[id-1]);
	for (i=id;i<=n;i++) {
//		gdb(i,res,pw[i]);
		int nums=(res+pw[i]-1)/pw[i],t=nums;
		if (i>=2&&t>=min(ans[i-1],ans[i-2])) t++;
		if (i>=3&&t>=max(ans[i-1],ans[i-2])) t++;
		ans[i]=t;
		res=res-(nums-1)*pw[i];
	}
	for (i=1;i<=n;i++) printf("%lld ",ans[i]);
	exit(0);
}
signed main(void){
	int i;
	read(n);read(m);read(k);
	if (m==1) {
		if (k>1) puts("-1");
		else {
			for (i=1;i<=n;i++) printf("%d ",1);
		}
		return 0;
	}
	if (m==2) {
		solve();
		return 0;
	}
	int res=1;
	ans[0]=1e9;
	for (i=1;i<=n;i++) ans[i]=(i-1)%3+1;
	for (i=n;i>=1;i--) {
		int tmp=m-2+(i<=2)+(i<=1);
		pw[i]=res;
		if ((long double)tmp*res>=k) {
			int nums=(k+res-1)/res,t=nums;
//			gdb(i,nums);
			if (i>=2&&t>=min(ans[i-1],ans[i-2])) t++;
			if (i>=3&&t>=max(ans[i-1],ans[i-2])) t++;
			ans[i]=t;
			print(i+1,k-(nums-1)*res);
		}
		else res=res*tmp;
	}
	puts("-1");
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1 1 1

output:

1 

result:

ok 1 number(s): "1"

Test #2:

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

input:

2 2 2

output:

2 1 

result:

ok 2 number(s): "2 1"

Test #3:

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

input:

3 3 3

output:

2 1 3 

result:

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

Test #4:

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

input:

9 9 8244353

output:

2 4 1 2 6 8 1 2 7 

result:

ok 9 numbers

Test #5:

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

input:

10 7 998244353

output:

-1

result:

ok 1 number(s): "-1"

Test #6:

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

input:

3 1000 994253860

output:

998 244 353 

result:

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

Test #7:

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

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: 5628kb

input:

58 4 864691128455135233

output:

-1

result:

ok 1 number(s): "-1"

Test #9:

score: 0
Accepted
time: 38ms
memory: 13488kb

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: 12116kb

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: 3520kb

input:

1 1 2

output:

-1

result:

ok 1 number(s): "-1"

Test #12:

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

input:

1 2 2

output:

2 

result:

ok 1 number(s): "2"

Test #13:

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

input:

2 2 1

output:

1 2 

result:

ok 2 number(s): "1 2"

Test #14:

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

input:

3 2 4

output:

2 1 1 

result:

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

Test #15:

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

input:

3 2 7

output:

-1

result:

ok 1 number(s): "-1"

Test #16:

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

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: 3780kb

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: 3796kb

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: 0ms
memory: 3664kb

input:

5 2 13

output:

-1

result:

ok 1 number(s): "-1"

Test #20:

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

input:

6 2 5

output:

1 2 2 1 1 2 

result:

ok 6 numbers

Test #21:

score: 0
Accepted
time: 37ms
memory: 3772kb

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: 40ms
memory: 3824kb

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: 40ms
memory: 4128kb

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: 0ms
memory: 3664kb

input:

1000000 2 1000000000000000000

output:

-1

result:

ok 1 number(s): "-1"

Test #25:

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

input:

1 3 2

output:

2 

result:

ok 1 number(s): "2"

Test #26:

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

input:

2 3 5

output:

3 1 

result:

ok 2 number(s): "3 1"

Test #27:

score: 0
Accepted
time: 48ms
memory: 19676kb

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: 5ms
memory: 19144kb

input:

1000000 3 7

output:

-1

result:

ok 1 number(s): "-1"

Test #29:

score: 0
Accepted
time: 38ms
memory: 12500kb

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: 13268kb

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: 39ms
memory: 13388kb

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: 5812kb

input:

6 1000000 1000000000000000000

output:

1 2 4 9 15 8 

result:

ok 6 numbers

Test #33:

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

input:

4 1000000 1000000000000000000

output:

2 7 15 9 

result:

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

Test #34:

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

input:

3 1000000 999997000002000000

output:

1000000 999999 999998 

result:

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

Test #35:

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

input:

3 1000000 999997000002000001

output:

-1

result:

ok 1 number(s): "-1"