10050 - Hartals
Moderator: Board moderators
-
- New poster
- Posts: 18
- Joined: Fri Jan 07, 2005 9:35 pm
- Location: Bangladesh
10050 still WA?
i have changed a bit the initialization part but still WA
Last edited by Fuad Hassan_IIUC(DC) on Tue Feb 01, 2005 2:57 pm, edited 1 time in total.
fuad
Please do not open a new topic for posts concerning the same problem.
And you have completely mistaken my previous reply... By initialization I mean setting the elements of your array count_a to 0. Check that statement, and hope you can get that fixed.
P.S. Remember to remove your code after you get AC.![8)](./images/smilies/icon_cool.gif)
And you have completely mistaken my previous reply... By initialization I mean setting the elements of your array count_a to 0. Check that statement, and hope you can get that fixed.
P.S. Remember to remove your code after you get AC.
![8)](./images/smilies/icon_cool.gif)
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
-
- New poster
- Posts: 18
- Joined: Fri Jan 07, 2005 9:35 pm
- Location: Bangladesh
-
- New poster
- Posts: 18
- Joined: Fri Jan 07, 2005 9:35 pm
- Location: Bangladesh
10050
HI,
Getting WA for this code
[code]
/*
Name: Hartals
Number: 10050
Type : ad hoc
Process : ON
Author :Salman Zaman
Email : zamansalman@gmail.com
Date : 02/06/05 01:27
*/
#include<stdio.h>
//#include<string.h>
//#include<conio.h>
int main(){
int n,p,t;
int days[4000];
int party[500];
int i,j,k,x,count;
//freopen("10050.txt","r",stdin);
scanf("%d",&t);
for(i=0;i<t;i++){
scanf("%d%d",&n,&p);
for(k=0;k<=n;k++)days[k]=0;
for(j=0;j<p;j++){
scanf("%d",&x);
for(k=x;k<=n;k=k+x){
days[k]=1;
}
}
for(k=7;k<=n;k+=7){
days[k]=0;
days[k-1]=0;
}
for(k=1,count=0;k<=n;k++){
if(days[k])count++;
}
printf("%d\n",count);
}
// getch();
return 0;
}
[/code]
Test case is ok but i think the problem is with weekends checking!!!
Getting WA for this code
[code]
/*
Name: Hartals
Number: 10050
Type : ad hoc
Process : ON
Author :Salman Zaman
Email : zamansalman@gmail.com
Date : 02/06/05 01:27
*/
#include<stdio.h>
//#include<string.h>
//#include<conio.h>
int main(){
int n,p,t;
int days[4000];
int party[500];
int i,j,k,x,count;
//freopen("10050.txt","r",stdin);
scanf("%d",&t);
for(i=0;i<t;i++){
scanf("%d%d",&n,&p);
for(k=0;k<=n;k++)days[k]=0;
for(j=0;j<p;j++){
scanf("%d",&x);
for(k=x;k<=n;k=k+x){
days[k]=1;
}
}
for(k=7;k<=n;k+=7){
days[k]=0;
days[k-1]=0;
}
for(k=1,count=0;k<=n;k++){
if(days[k])count++;
}
printf("%d\n",count);
}
// getch();
return 0;
}
[/code]
Test case is ok but i think the problem is with weekends checking!!!
-
- New poster
- Posts: 50
- Joined: Thu Jul 31, 2003 10:43 am
- Location: Daffodil University,Dhaka,Bangladesh
- Contact:
U used a array party that is never used.... & try for these inputs:
Input:
4
8
100
4
12
15
25
40
1000
4
45
100
6
12
3000
10
15
500
6
89
87
184
456
15
444
2
My Acc program Output:
5
15
132
1166
Your:
5
15
133
1166
So may be u have done some mistake ....Try urself ...best..to find out it...
Input:
4
8
100
4
12
15
25
40
1000
4
45
100
6
12
3000
10
15
500
6
89
87
184
456
15
444
2
My Acc program Output:
5
15
132
1166
Your:
5
15
133
1166
So may be u have done some mistake ....Try urself ...best..to find out it...
I hate Wrong Answer!
test cases
J & Jewel,
I'm affraid your input is slightly wrong
( does dot match the input description from
the problem statement ).
Here are your test cases corrected plus
one more test case.
INPUT
OUTPUT
I hope the test cases will be helpful to
Salman and/or to someone else.
I'm affraid your input is slightly wrong
( does dot match the input description from
the problem statement ).
Here are your test cases corrected plus
one more test case.
INPUT
Code: Select all
5
14
3
3
4
8
100
4
12
15
25
40
1000
4
45
100
6
12
3000
10
15
500
6
89
87
184
456
15
444
2
3600
10
9
12
17
100
121
130
200
3600
3601
181
OUTPUT
Code: Select all
5
15
132
1166
610
Salman and/or to someone else.
10050 - Hartals - I got RE.
I don't know what make my program runtime error.
Actually, when I tested my program, it was no problem.
Who can advise me?
Actually, when I tested my program, it was no problem.
Who can advise me?
Code: Select all
#include <iostream>
#include <cstring>
using namespace std;
const int MAXPARTY = 110;
const int MAXDAY = 3700;
const int SAT = 7;
int main()
{
int tscase;
cin >> tscase;
int days, partis;
bool day[MAXDAY] = {false,};
int party[MAXPARTY] = {0,};
for(int i=0; i < tscase; i++)
{
// Input
cin >> days >> partis;
for(int j=0; j < partis; j++)
{
cin >> party[j];
}
// Processing
for(int k=1; k <= days; k++)
{
for(int m=0; m < partis; m++)
{
if( (k % party[m]) == 0 ) {
day[k] = true;
}
}
}
int count = 0;
for(int k=1; k <= days; k++)
{
if( (day[k] == true) ) {
if( (k % SAT) != 0 && (k % SAT) != 6) {
count++;
}
}
}
// Output
if( i == tscase-1 )
cout << count;
else
cout << count << endl;
// Clear
memset(day, 0x00, sizeof(int)*days);
memset(party, 0x00, sizeof(int)*partis);
}
return 0;
}
Re: 10050 - Hartals - I got RE.
I got A.C.
But, I have just changed my Clear part.
I used for-loop to clear array instead of memset function.
I can't understand why the memset function occur Runtime error.
Who can explain me about it?
But, I have just changed my Clear part.
I used for-loop to clear array instead of memset function.
I can't understand why the memset function occur Runtime error.
Who can explain me about it?
Re: 10050 - Hartals - I got RE.
You define 'day' as an array of bools yet you use sizeof(int) instead of sizeof(bool) when you specify the size of the array in memset. 'bool' is defined as a char so you are clearing data after the end of your array.mosaick2 wrote:I got A.C.
But, I have just changed my Clear part.
I used for-loop to clear array instead of memset function.
I can't understand why the memset function occur Runtime error.
Who can explain me about it?
Re: 10050 - Hartals - I got RE.
kryptolus wrote:You define 'day' as an array of bools yet you use sizeof(int) instead of sizeof(bool) when you specify the size of the array in memset. 'bool' is defined as a char so you are clearing data after the end of your array.mosaick2 wrote:I got A.C.
But, I have just changed my Clear part.
I used for-loop to clear array instead of memset function.
I can't understand why the memset function occur Runtime error.
Who can explain me about it?
Oh, my GOD...
Thanks, kruptolus.
I'm really appreciate you.
-
- Experienced poster
- Posts: 162
- Joined: Thu Jul 13, 2006 7:07 am
- Location: Campus Area. Dhaka.Bangladesh
- Contact:
why runtime error hartals:10050?
deleted after acceptation
thank you to help me.
Last edited by newton on Wed Dec 20, 2006 8:26 am, edited 1 time in total.
Re: why runtime error hartals:10050?
array[1000] -> array[3651]newton wrote:may you check it please?
both of c and c++ compiler told me runtime error.
but why?
day[3651] -> day[100]
After getting correct answer, please delete above your code.
Best regards.
What am I doing wrong?
I have tried my program with all the sample input from the four threads on Hartals and it works perfectly for all of them. What am I missing? Thanks in advance.
Code: Select all
Figured out my problem.