## 10489 - Boxes of Chocolates

Moderator: Board moderators

Chow Wai Chung
New poster
Posts: 21
Joined: Sun Jan 19, 2003 4:01 pm
Location: Hong Kong

### 10489 Boxes of Chocolates : WA??

This problem seems quite easy, but i got a WA

I had consider about the overflow problem, and use long long to store some variable.

world anyone can point out that where is my mistaker, please??

[c]
#include <stdio.h>

int main()
{
long long total,tmp;
int num,n,b,k,box;
scanf("%d",&num);
while(num-->0)
{
scanf("%d %d",&n,&b);
total=0;
while(b-->0)
{
tmp=1;
scanf("%d",&k);
while(k-->0)
{
scanf("%d",&box);
tmp*=box;
}
total+=tmp;
}
printf("%lld\n",total%n);
}
return 0;
}
[/c]

Chow Wai Chung
New poster
Posts: 21
Joined: Sun Jan 19, 2003 4:01 pm
Location: Hong Kong
isn't it just simple sum all a1*a2*a3.... and mod the number of friend??

but why i got a WA??

erfan
New poster
Posts: 44
Joined: Tue Apr 15, 2003 4:31 pm
Contact:
It should not need long long.It also AC at long.
You can change your code by this way.
tmp*=box;
tm=tmp%n;
}
total+=tmp;
total=total%n;
}
I think now AC.

Chow Wai Chung
New poster
Posts: 21
Joined: Sun Jan 19, 2003 4:01 pm
Location: Hong Kong
thank you very much to erfan!!!!

I got AC now

It looks like i have to improve my maths.

babor
New poster
Posts: 16
Joined: Sat Jun 07, 2003 4:23 pm
Contact:
Hai find modulas at each and every step tot avoid time limit & overflow
babor

p!ter
New poster
Posts: 11
Joined: Thu Nov 18, 2004 8:55 pm

### 10489 -- Box of Chocolates Why WA???

Hi,

Could anyone tell me whats wrong with my code? I think output is ok.

Code: Select all

``````#include <stdio.h>

int main() {

int l,N,T,B,r,K,box;
long long w,d;

scanf("%d",&T);
while(T--) {
scanf("%d%d",&N,&B);
w=0;
while(B--) {
scanf("%d",&K);
d=1;
while(K--){
scanf("%d",&box);
d=d*box;
}
w=w+d;
}
r=w%N;
printf("%d\n",r);
}
return 0;
}
``````
THANKS!!!

Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:
It might still overflow. Look up on the Chinese remainder theorem.

p!ter
New poster
Posts: 11
Joined: Thu Nov 18, 2004 8:55 pm
What does it mean overflow?
Could you explain me that and how can I check it?

Jemerson
Learning poster
Posts: 59
Joined: Mon Feb 02, 2004 11:19 pm
Contact:

### 10489 - Boxes of Chocolates - Im getting PISSEDDDD

Hi guys, im not a nice C++ programmer so i think the problem is that I couldnt code the problem correctly, any help?

Code: Select all

``````CUT AFTER ACC
``````
Last edited by Jemerson on Tue Aug 09, 2005 3:51 am, edited 1 time in total.
UFCG Brazil - Computer Science graduate student
http://acm.uva.es/problemset/usersnew.php?user=54806 ... and going up!

daveon
Experienced poster
Posts: 229
Joined: Tue Aug 31, 2004 2:41 am
Hi,

Code: Select all

``````total %= numFriends;
``````
after

Code: Select all

`````` total += result;
``````
and you should get AC.

Jemerson
Learning poster
Posts: 59
Joined: Mon Feb 02, 2004 11:19 pm
Contact:
Thanx a lot, I understood my mistake
UFCG Brazil - Computer Science graduate student
http://acm.uva.es/problemset/usersnew.php?user=54806 ... and going up!

stalf
New poster
Posts: 7
Joined: Fri Apr 06, 2007 7:57 pm
Could you help me with 10489?
This is my code, and i'm getting wa...

Code: Select all

``````#include <iostream>

using namespace std;

int main(){
int t,n,b,k,aux;
long result;
cin>>t;
for(int i=0;i<t;i++){
cin>>n;
cin>>b;
long total = 0;
for(int j=0;j<b;j++){
long partial = 1;
cin>>k;
for(int m=0;m<k;m++){
cin>>aux;
partial = partial*aux;
partial = partial%n;
}
total += partial;
}
cout<<total%n<<endl;
}
}

``````

stalf
New poster
Posts: 7
Joined: Fri Apr 06, 2007 7:57 pm
thanks
got ac [=

uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

### Re: 10489 - Boxes of Chocolates

Here's some input / output that I found useful while testing / debugging.

Input:

Code: Select all

``````3
7 3
6 8 9 3 4 100 98
7 87 64 23 12 88 44 99
3 65 48 76
17 3
10 65 32 88 8 9 3 4 100 98 99
10 100 78 66 87 64 23 12 88 44 99
20 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
23 3
10 65 32 88 8 9 3 4 100 98 99
10 100 78 66 87 64 23 12 88 44 99
24 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
``````
Output:

Code: Select all

``````4
11
6
``````
Check input and AC output for over 7,500 problems on uDebug!