QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#135712 | #5460. Sum of Numbers | linnins | WA | 605ms | 4140kb | C++14 | 1.9kb | 2023-08-05 23:05:53 | 2023-08-05 23:05:56 |
Judging History
answer
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
char Mid[200500];
int Map[200500];
int Ans[200500];
int Sum[200500];
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 n)
{
int flag = n;
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
{
for(int i=Anspoint;i>=1;i--)
{
if(Ans[i]>Sum[i])
{
change();
break;
}
else if(Ans[i] < Sum[i])
break;
}
}
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
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(4,k);
type -= 1;
for(int i = type;i>=0;i--)
{
int MID = i;
int Sumn = 0;
Sumpoint = 0;
for(int i=1;i<=avg+1;i++)
{
Sum[i] = 0;
}
for(int j=1;j<=k;j++)
{
if(MID%4 == 3)
{
ADD(Sumn,avg-1);
Sumn+=avg-1;
}
else if(MID%4 == 1)
{
ADD(Sumn,avg+1);
Sumn+=avg+1;
}
else if(MID%4 == 2)
{
ADD(Sumn,avg+2);
Sumn+=avg+2;
}
else
{
ADD(Sumn,avg);
Sumn+=avg;
}
MID/=4;
}
if(Sumn == n)
{
clearSum(n);
updateAns();
}
}
for(int i=Anspoint;i>=1;i--)
{
printf("%d",Ans[i]);
}
printf("\n");
}
}
/*
20
10 2
2156345972
20
14 3
32154512561264
20
14 6
12345678910354
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4140kb
input:
2 8 1 45455151 2 1 42
output:
9696 6
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 605ms
memory: 2396kb
input:
10 1301 6 56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...
output:
124115335779078922697142599750684548980404596737700273093309677559864316358291281079807176534604084699009517877366708474130829059041479012430901412539277729476820007444544007761009364578263238 11648452520920032248648545368439511166569758872159264527026376245756676432392604743148879569432915086812809...
result:
wrong answer 1st lines differ - expected: '286183755510664079479706773787...6909797866802717925250679901255', found: '124115335779078922697142599750...0007444544007761009364578263238'