QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#101860#6353. Kth Lex Min Min Min Subpalindromeszhouhuanyi#AC ✓757ms52428kbC++112.0kb2023-05-01 14:42:572023-05-01 14:42:58

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-01 14:42:58]
  • 评测
  • 测评结果:AC
  • 用时:757ms
  • 内存:52428kb
  • [2023-05-01 14:42:57]
  • 提交

answer

#include<iostream>
#include<cstdio>
#define N 1000000
#define inf 1e9
using namespace std;
long long read()
{
    char c=0;
    long long sum=0;
    while (c<'0'||c>'9') c=getchar();
    while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
    return sum;
}
int n,m,a[N+1],b[N+1];
long long k,pw[N+1];
bool check(int l,int r)
{
    bool op=1;
    for (int i=l;i<=r;++i) op&=(a[i]==a[l+r-i]);
    return op;
}
void dfs(int x,int cnt)
{
    if (x==n+1)
    {
	if ((n==1||cnt==((n-1)<<1))&&k)
	{
	    k--;
	    if (!k)
	    {
		for (int i=1;i<=n;++i) b[i]=a[i];
	    }
	}
	return;
    }
    int rst=0;
    a[x]=1;
    for (int i=max(x-6,1);i<=x;++i)
	if (check(i,x))
	    rst++;
    if (x<=2||cnt+rst<=((x-1)<<1)) dfs(x+1,cnt+rst);
    a[x]=2,rst=0;
    for (int i=max(x-6,1);i<=x;++i)
	if (check(i,x))
	    rst++;
    if (x<=2||cnt+rst<=((x-1)<<1)) dfs(x+1,cnt+rst);
    return;
}
int main()
{
    int x,y;
    long long d,cnt;
    n=read(),m=read(),k=read();
    if (m==1)
    {
	if (k>1) puts("-1");
	else
	{
	    for (int i=1;i<=n;++i) printf("1 ");
	    puts("");
	}
    }
    else if (m==2)
    {
	dfs(1,0);
	if (k) puts("-1");
	else
	{
	    for (int i=1;i<=n;++i) printf("%d ",b[i]);
	    puts("");
	}
    }
    else if (n==1)
    {
	if (k>m) puts("-1");
	else
	{
	    for (int i=1;i<=n;++i) printf("%lld ",k);
	    puts("");
	}
    }
    else
    {
	pw[0]=1;
	for (int i=1;i<=n;++i) pw[i]=min((__int128)(pw[i-1])*(m-2),(__int128)(k+1));
	if (k>min((__int128)(pw[n-2])*(m-1)*m,(__int128)(k+1))) puts("-1");
	else
	{
	    k--;
	    for (int i=1;i<=n;++i)
	    {
		if (i==1) d=min((__int128)(pw[n-2])*(m-1),(__int128)(k+1));
		else d=pw[n-i];
		cnt=k/d+1,k%=d,x=y=inf;
		if (i-2>=1) x=a[i-2];
		if (i-1>=1) y=a[i-1];
		if (x>y) swap(x,y);
		if (cnt>=x) cnt++;
		if (cnt>=y) cnt++;
		a[i]=cnt;
	    }
	    for (int i=1;i<=n;++i) printf("%d ",a[i]);
	    puts("");
	}
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1 1 1

output:

1 

result:

ok 1 number(s): "1"

Test #2:

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

input:

2 2 2

output:

2 1 

result:

ok 2 number(s): "2 1"

Test #3:

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

input:

3 3 3

output:

2 1 3 

result:

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

Test #4:

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

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

input:

10 7 998244353

output:

-1

result:

ok 1 number(s): "-1"

Test #6:

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

input:

3 1000 994253860

output:

998 244 353 

result:

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

Test #7:

score: 0
Accepted
time: 2ms
memory: 7640kb

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: 2ms
memory: 5292kb

input:

58 4 864691128455135233

output:

-1

result:

ok 1 number(s): "-1"

Test #9:

score: 0
Accepted
time: 79ms
memory: 16932kb

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: 72ms
memory: 17324kb

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: 2ms
memory: 5280kb

input:

1 1 2

output:

-1

result:

ok 1 number(s): "-1"

Test #12:

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

input:

1 2 2

output:

2 

result:

ok 1 number(s): "2"

Test #13:

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

input:

2 2 1

output:

1 2 

result:

ok 2 number(s): "1 2"

Test #14:

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

input:

3 2 4

output:

2 1 1 

result:

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

Test #15:

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

input:

3 2 7

output:

-1

result:

ok 1 number(s): "-1"

Test #16:

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

input:

4 2 10

output:

2 2 1 2 

result:

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

Test #17:

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

input:

4 2 3

output:

1 2 1 1 

result:

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

Test #18:

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

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: 3ms
memory: 7360kb

input:

5 2 13

output:

-1

result:

ok 1 number(s): "-1"

Test #20:

score: 0
Accepted
time: 2ms
memory: 7580kb

input:

6 2 5

output:

1 2 2 1 1 2 

result:

ok 6 numbers

Test #21:

score: 0
Accepted
time: 746ms
memory: 51628kb

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: 738ms
memory: 52428kb

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: 757ms
memory: 52024kb

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: 673ms
memory: 49192kb

input:

1000000 2 1000000000000000000

output:

-1

result:

ok 1 number(s): "-1"

Test #25:

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

input:

1 3 2

output:

2 

result:

ok 1 number(s): "2"

Test #26:

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

input:

2 3 5

output:

3 1 

result:

ok 2 number(s): "3 1"

Test #27:

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

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: 2ms
memory: 11964kb

input:

1000000 3 7

output:

-1

result:

ok 1 number(s): "-1"

Test #29:

score: 0
Accepted
time: 84ms
memory: 17244kb

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: 67ms
memory: 17256kb

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: 65ms
memory: 17036kb

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: 3ms
memory: 7576kb

input:

6 1000000 1000000000000000000

output:

1 2 4 9 15 8 

result:

ok 6 numbers

Test #33:

score: 0
Accepted
time: 2ms
memory: 7608kb

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

input:

3 1000000 999997000002000000

output:

1000000 999999 999998 

result:

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

Test #35:

score: 0
Accepted
time: 2ms
memory: 5220kb

input:

3 1000000 999997000002000001

output:

-1

result:

ok 1 number(s): "-1"