10489 - Boxes of Chocolates
Moderator: Board moderators
-
- 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]
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]
-
- New poster
- Posts: 21
- Joined: Sun Jan 19, 2003 4:01 pm
- Location: Hong Kong
-
- New poster
- Posts: 21
- Joined: Sun Jan 19, 2003 4:01 pm
- Location: Hong Kong
10489 -- Box of Chocolates Why WA???
Hi,
Could anyone tell me whats wrong with my code? I think output is ok.
THANKS!!!
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;
}
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!
http://acm.uva.es/problemset/usersnew.php?user=54806 ... and going up!
Hi,
Just add
after
and you should get AC.
Just add
Code: Select all
total %= numFriends;
Code: Select all
total += result;
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!
http://acm.uva.es/problemset/usersnew.php?user=54806 ... and going up!
Could you help me with 10489?
This is my code, and i'm getting wa...
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;
}
}
Re: 10489 - Boxes of Chocolates
Here's some input / output that I found useful while testing / debugging.
Input:
Output:
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
Code: Select all
4
11
6