Submission #52398116


Source Code Expand

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int n;
int a[200010];
int fa[30][400010];
int to[200010],nxt[200010],head[200010],cnt;
int p[200010],b[200010];

void add(int x,int y)
{
	if (x < y) swap(x,y);
	to[++ cnt] = y;
	nxt[cnt] = head[x];
	head[x] = cnt;
}

int fnd(int x,int k) {return fa[k][x] = (fa[k][x] == x ? x : fnd(fa[k][x],k));}

void Merge(int l,int r,int k)
{
	// printf("*Merge %d %d %d\n",l,r,k);
	l = fnd(l,k),r = fnd(r,k);
	if (l == r) return ;
	if (l < r) swap(l,r);
	fa[k][l] = r;
}

void merge(int l,int ll,int len)
{
	// printf("merge %d %d %d\n",l,ll,len);
	if (l == ll) return ;
	int r = l + len - 1,rr = ll + len - 1;
	int L = (len == 1 ? 0 : log2(len));
	Merge(l,ll,L);
	Merge(r - (1 << L) + 1,rr - (1 << L) + 1,L);
}

int main()
{
	scanf("%d",&n);
	for (int i = 1;i <= 2 * n;i ++)
		for (int j = 0;j <= 20;j ++)
			fa[j][i] = i;
	for (int i = n + 1;i <= n * 2;i ++) Merge(2 * n - i + 1,i,0);
	for (int i = 1;i <= n;i ++)
	{
		scanf("%d",a + i);
		if (!a[i]) continue;
		merge(i - a[i],2 * n - (i + a[i]) + 1,a[i]);
		merge(i + 1,2 * n - i + 2,a[i]);
	}
	for (int i = 19;~i;i --)
		for (int j = 1;j <= 2 * n - (1 << (i + 1)) + 1;j ++)
		{
			int tmp = fnd(j,i + 1);
			Merge(j,tmp,i);
			Merge(j + (1 << i),tmp + (1 << i),i);
		}
	// for (int i = 1;i <= n;i ++) printf("%d %d\n",i,fnd(i,0));
	for (int i = 1;i <= n;i ++)
	{
		if (a[i] == i - 1 || a[i] == n - i) continue;
		if (fnd(i - a[i] - 1,0) == fnd(i + a[i] + 1,0))
		{
			printf("No\n");
			return 0;
		}
		add(fnd(i - a[i] - 1,0),fnd(i + a[i] + 1,0));
	}
	printf("Yes\n");
	for (int i = 1;i <= n;i ++)
		if (i == fnd(i,0))
		{
			int nw = 1;
			for (int j = head[i];j;j = nxt[j])
				p[b[to[j]]] = 1;//printf("*%d %d %d\n",i,j,b[j]);
			while (p[nw]) nw ++;
			b[i] = nw;
			printf("%d ",nw);
			for (int j = head[i];j;j = nxt[j]) p[b[to[j]]] = 0;
		}
		else printf("%d ",b[fnd(i,0)]);
	printf("\n");
}

Submission Info

Submission Time
Task G - Palindrome Construction
User RabbieWjy
Language C++ 17 (gcc 12.2)
Score 625
Code Size 2005 Byte
Status AC
Exec Time 96 ms
Memory 40616 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:43:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |         scanf("%d",&n);
      |         ~~~~~^~~~~~~~~
Main.cpp:50:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   50 |                 scanf("%d",a + i);
      |                 ~~~~~^~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 625 / 625
Status
AC × 3
AC × 57
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 1 ms 3852 KiB
00_sample_02.txt AC 1 ms 3976 KiB
00_sample_03.txt AC 1 ms 3784 KiB
01_random_01.txt AC 96 ms 36192 KiB
01_random_02.txt AC 94 ms 34840 KiB
01_random_03.txt AC 68 ms 36592 KiB
01_random_04.txt AC 71 ms 37160 KiB
01_random_05.txt AC 55 ms 38876 KiB
01_random_06.txt AC 43 ms 35776 KiB
01_random_07.txt AC 52 ms 38096 KiB
01_random_08.txt AC 53 ms 38860 KiB
01_random_09.txt AC 51 ms 37164 KiB
01_random_10.txt AC 74 ms 34432 KiB
01_random_11.txt AC 54 ms 35852 KiB
01_random_12.txt AC 56 ms 37024 KiB
01_random_13.txt AC 61 ms 40124 KiB
01_random_14.txt AC 55 ms 37744 KiB
01_random_15.txt AC 53 ms 37112 KiB
01_random_16.txt AC 46 ms 35348 KiB
01_random_17.txt AC 46 ms 34924 KiB
01_random_18.txt AC 55 ms 38256 KiB
01_random_19.txt AC 54 ms 38276 KiB
01_random_20.txt AC 54 ms 35080 KiB
01_random_21.txt AC 51 ms 38120 KiB
01_random_22.txt AC 54 ms 38432 KiB
01_random_23.txt AC 57 ms 37980 KiB
01_random_24.txt AC 57 ms 37512 KiB
01_random_25.txt AC 64 ms 39264 KiB
01_random_26.txt AC 48 ms 36996 KiB
01_random_27.txt AC 62 ms 37024 KiB
01_random_28.txt AC 66 ms 39584 KiB
01_random_29.txt AC 51 ms 36316 KiB
01_random_30.txt AC 55 ms 38676 KiB
01_random_31.txt AC 52 ms 36016 KiB
01_random_32.txt AC 66 ms 39068 KiB
01_random_33.txt AC 46 ms 35040 KiB
01_random_34.txt AC 57 ms 40236 KiB
01_random_35.txt AC 67 ms 40108 KiB
01_random_36.txt AC 58 ms 36984 KiB
01_random_37.txt AC 62 ms 38304 KiB
01_random_38.txt AC 53 ms 37268 KiB
01_random_39.txt AC 47 ms 37068 KiB
01_random_40.txt AC 61 ms 38720 KiB
01_random_41.txt AC 52 ms 34056 KiB
01_random_42.txt AC 54 ms 36168 KiB
01_random_43.txt AC 59 ms 37232 KiB
01_random_44.txt AC 61 ms 38292 KiB
01_random_45.txt AC 53 ms 37120 KiB
01_random_46.txt AC 64 ms 39536 KiB
01_random_47.txt AC 63 ms 39496 KiB
01_random_48.txt AC 63 ms 40116 KiB
01_random_49.txt AC 60 ms 38796 KiB
02_handmade_01.txt AC 81 ms 37492 KiB
02_handmade_02.txt AC 55 ms 40616 KiB
02_handmade_03.txt AC 1 ms 3660 KiB
02_handmade_04.txt AC 1 ms 3820 KiB
02_handmade_05.txt AC 74 ms 37428 KiB