Submission #62288460


Source Code Expand

#include <bits/stdc++.h>
#define _F(x,y,z) for(int x=y;x<=z;x++)
#define F_(x,z,y) for(int x=z;x>=y;x--)
#define TF(x,y,z) for(int x=head[y],z;x;x=nex[x])

using namespace std;

typedef long long ll;
typedef double dou;
typedef const int ci;
typedef pair<int,int> pii;

ci maxn=2e6+10;

char a[maxn];
int n,m,ans[15][maxn],f[15][maxn],t[maxn],res=1;
int cnt[2],fl;
int main()
{
	scanf("%d",&n);
	scanf("%s",a+1);
	m=strlen(a+1);
	memset(ans,0x3f,sizeof ans);
	_F(i,1,m)
	{
		ans[0][i]=1;
		f[0][i]=a[i]-'0';
//		printf("%d ",f[0][i]);
	}
	_F(i,1,n)
	{
		res*=3;
		for(int j=1;j*res<=m;j++)
		{
			fl=cnt[1]=cnt[0]=0;
			_F(k,0,2)
				cnt[f[i-1][(j-1)*3+k+1]]++;
			fl=cnt[0]<cnt[1];
			if(cnt[fl]==3)
			{
				_F(k,0,2)
					ans[i][j]=min(ans[i-1][(j-1)*3+k+1]+ans[i-1][(j-1)*3+(k+1)%3+1],ans[i][j]);
			}
			else
			{
				_F(k,0,2)
					if(f[i-1][(j-1)*3+k+1]==fl)
						ans[i][j]=min(ans[i][j],ans[i-1][(j-1)*3+k+1]);
			}
			f[i][j]=fl;
//			printf("%d ",f[i][j]);
		}
//		puts("");
	}
	printf("%d",ans[n][1]);
	return 0;
}

Submission Info

Submission Time
Task E - Hierarchical Majority Vote
User adolphshi
Language C++ 20 (gcc 12.2)
Score 450
Code Size 1082 Byte
Status AC
Exec Time 69 ms
Memory 132036 KiB

Compile Error

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

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 2
AC × 32
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.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, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt, 02_handmade_07.txt, 02_handmade_08.txt, 02_handmade_09.txt, 02_handmade_10.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 47 ms 120860 KiB
00_sample_02.txt AC 47 ms 121024 KiB
01_random_01.txt AC 47 ms 121072 KiB
01_random_02.txt AC 68 ms 131720 KiB
01_random_03.txt AC 48 ms 120844 KiB
01_random_04.txt AC 69 ms 131904 KiB
01_random_05.txt AC 48 ms 121520 KiB
01_random_06.txt AC 66 ms 132028 KiB
01_random_07.txt AC 49 ms 122128 KiB
01_random_08.txt AC 69 ms 131964 KiB
01_random_09.txt AC 47 ms 120960 KiB
01_random_10.txt AC 68 ms 131936 KiB
01_random_11.txt AC 47 ms 121036 KiB
01_random_12.txt AC 60 ms 132036 KiB
01_random_13.txt AC 47 ms 120776 KiB
01_random_14.txt AC 68 ms 131804 KiB
01_random_15.txt AC 47 ms 120924 KiB
01_random_16.txt AC 68 ms 131864 KiB
01_random_17.txt AC 47 ms 121000 KiB
01_random_18.txt AC 68 ms 131828 KiB
01_random_19.txt AC 47 ms 121036 KiB
01_random_20.txt AC 68 ms 131936 KiB
02_handmade_01.txt AC 58 ms 131904 KiB
02_handmade_02.txt AC 58 ms 131720 KiB
02_handmade_03.txt AC 60 ms 131900 KiB
02_handmade_04.txt AC 59 ms 131864 KiB
02_handmade_05.txt AC 58 ms 131808 KiB
02_handmade_06.txt AC 59 ms 132032 KiB
02_handmade_07.txt AC 58 ms 131900 KiB
02_handmade_08.txt AC 59 ms 131860 KiB
02_handmade_09.txt AC 59 ms 131804 KiB
02_handmade_10.txt AC 60 ms 131804 KiB