QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#135998#5460. Sum of NumberslinninsWA 18ms3316kbC++143.2kb2023-08-06 17:29:152023-08-06 17:29:19

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-06 17:29:19]
  • 评测
  • 测评结果:WA
  • 用时:18ms
  • 内存:3316kb
  • [2023-08-06 17:29:15]
  • 提交

answer

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#pragma GCC optimize(2) 

using namespace std;

char Mid[200500];
int Map[200500];

int Ans[200500];
int Sum[200500];

int MM =0;

int Anspoint = 2147483647;
int Sumpoint = 0;

void ADD(int p,int n)
{
	for(int i=1;i<=n;i++)
	{
		Sum[i] += Map[p+i];
	}
	Sumpoint = max(Sumpoint,n);
}

void clearSum()
{
	int flag = Sumpoint;
	for(int i=1;i<Sumpoint;i++)
	{
		Sum[i+1] += Sum[i]/10;
		Sum[i] %= 10; 
	}
	while(Sum[flag]>10)
	{
		Sum[flag+1] = Sum[flag]/10;
		Sum[flag]%=10;
		flag+=1;
		Sumpoint = flag;
	}

}

void change()
{
	Anspoint = Sumpoint;
	for(int i=1;i<=Sumpoint;i++)
	{
		Ans[i] = Sum[i];
	}
}

void updateAns()
{
	if(Anspoint>Sumpoint)
	{
		change();
	}
	else if(Anspoint==Sumpoint)
	{
		for(int i=Anspoint;i>=1;i--)
		{
			if(Ans[i]>Sum[i])
			{
				change();
				break;
			}
			else if(Ans[i] < Sum[i])
				break;
		}
	}
}

int checki(int range,int n,int k,int avg)
{	
	int Cek[10];
	for(int i=1;i<k;i++)
	{
		if(range%3 == 2)
			Cek[i] = -1;
		else if(range%3 == 1)
			Cek[i] = 1;
		else
		 	Cek[i] = 0;
		range/=3;
	}
	
	Cek[0] = 0;
	
	for(int i=1;i<k;i++)
	{
		Cek[i] = Cek[i-1] + Cek[i];
	}
	
	int Sum = 0; 
	
	for(int i=1;i<k;i++)
	{
		Sum+=Cek[i];
	}
	
	for(int i=avg-5;i<=avg+5;i++)
	{
		if(i*k+Sum == n)
		{
			return i;
		}
	}
	return 0;
}

int main()
{
	int T;
	scanf("%d",&T);
	int MM = 0;
	for(int L=1;L<=T;L++)
	{
		int n,k;
		Anspoint = 2147483647;
		scanf("%d%d",&n,&k);
		k+=1;	
		scanf("%s",Mid);
		int len = strlen(Mid);
		for(int i=len;i>=1;i--)
		{
			Map[i] = Mid[len-i] - '0';
		}
		int avg = n/k;
		int type = pow(3,k-1);
		type -= 1;

		int LAST = avg-2;
		
		for(int i = type;i>=0;i--)
		{
			int Last = checki(i,n,k,avg);
			if(!Last)
			{
				continue;
			}
		
			int MID = i;
			int Sumn = 0;
			Sumpoint = 0;
			for(int i=1;i<=avg+10;i++)
			{
				Sum[i] = 0;
			}
			int c=1;
			if(Last < 1)
			{
				continue;
			}
			ADD(Sumn,Last);
			Sumn+=Last;
			int last = Last;
			for(int j=2;j<=k;j++)
			{
				if(MID%3 == 2)
				{
					if(last-1 <= 0)
					{
						break;
					}
					
					ADD(Sumn,last-1);
					Sumn+=last-1;
					last -=1;
				}
				else if(MID%3 == 1)
				{
					ADD(Sumn,last+1);
					Sumn+=last+1;
					last +=1;
				}
				else
				{
					ADD(Sumn,last);
					Sumn+=last;
				}
				MID/=3;
			}
			if(Sumn == n)
			{
				clearSum();
				updateAns();
			}
		}

		while(Ans[Anspoint]>=10)
		{
			Ans[Anspoint+1]+=Ans[Anspoint]/10;
			Anspoint = max(Anspoint,Anspoint+1);
		}

		for(int i=Anspoint;i>=1;i--)
		{
			putchar('0'+Ans[i]);
			//printf("%d",Ans[i]);
		}
		printf("\n");
		
	}
}

/*


1
3 1
643

2
2 1
42



20
10 2
2156345972

20
14 3
32154512561264

20
14 6
12345678910354

10
10 3
1111111111

73745151612994128663659691951

100
119 4
74557467972773121782538891362827481768912897991754711869314352623359371753878285451828757473745151612994128663659691951



119 4
745574679727731217825388913628
274817689128979917547118693143
526233593717538782854518287574
73745151612994128663659691951

2411812927269438997564718


*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
8 1
45455151
2 1
42

output:

9696
6

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 18ms
memory: 2460kb

input:

10
1301 6
56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...

output:

2861837555106640794797067737879913860686764066159587941287350938727749577629356630565034353414526438507603808735990935008225192080065174423508575377930722196909797866802717925250679901255
1330897896655974774035586406544907434842835048336411271110427836483063457950873824562288934364096546537492367401...

result:

ok 10 lines

Test #3:

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

input:

3
68312 1
97721793232462295468345161395388245623318759168492992575579675893432997968276399269361852215552871434587866112799189725614696256526239439933158479577223186954475137216722241699568491426254779997896288355965839555276546655174417599498493234323661877664997543475525992228661739933395881544363...

output:

165361439370989969611281150911906045608758081895436745302721903170895741831200164992289491213814537683869854746077326282091529052307364873668669947061960472772133388934416763345394409983809105665214082485429685401199520114459892594221344388768178495952936142426649338494017013932243993161711816767032...

result:

ok 3 lines

Test #4:

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

input:

3
104062 2
6586987777965872861989232258194733262765989634859654379877935579528781688159322513128986886481716832258115626748535521126479244461411522889744479186513298679746684345233214226141199846787117661159318966767135455745184384324833645134232699525177668629239933843658643667417337451334591594819...

output:

536246497591460214899497073157707308719964754106858053886979792537707870310253164299747153718261114131636990130350872742851787818427135113617679220183754863021102973854172956224432906133335696002890140207617299467927865340000078212572980076032917286214327823207585568582552662612028254042515906063023...

result:

ok 3 lines

Test #5:

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

input:

3
139639 3
6796297676823528648589397343663999328612414278384367347213637689464348185237425534836886677731351726963453579377613988437426483671299519186839344132333793569544718489728294346989818592279444871423953477919473799463194216678119582972131632322347549538925164854516141164554772823372476647126...

output:

126364763403906564661708542497996384758493064461499142133308596067494936258655259133526434841726196274703766844552726915088706942994746309192813887599486034682622494344506129054929148805249803660505979746418821689885230718372401950523582639142168746487771785553740446005221635828358569536474437471762...

result:

ok 3 lines

Test #6:

score: 0
Accepted
time: 5ms
memory: 2616kb

input:

3
74882 4
34214651312364628656844245717387533432968776973534628295922991352118459564756246556257779312918116552177726519173345828839532314119892538422953191411989526818837499574837984599131437923829691932871927272598159916936847255554115731624229194141184295327556843698221845942155322267254877729895...

output:

652879872016718790343280470756061301445687203441680798826476501917145925778781111109343489062160438478188515389826291555084101569285971285993846457561557667210690487169933469816410296697081463378678731150633158904900018680809858404118923436246875692603950100371337341615443319224405626522868813204392...

result:

ok 3 lines

Test #7:

score: -100
Wrong Answer
time: 4ms
memory: 3316kb

input:

3
191014 5
4625226525489118654543959629348153444699986242632464847423452621546972849227817733763237372239335981427166568676892839618898764121637356149689834276433852165285729163339388526992792556894792278543347578452353389831593643818698478199319882191378795871195868331188637941453446682259469316457...

output:

183433830723962716661960230479245454318025962759914611110498608412928382555357890844482989235397326332530009244441167586569039863115637789245293728629736732433450983262080427109116060046615860768206472546822403232142108561871987242547562597599614404577271199268661821460539766659678709433633532926618...

result:

wrong answer 3rd lines differ - expected: '104614928207243672593067479304...4697334678614140061970364654282', found: '2:4614928207243672593067479304...4697334678614140061970364654282'