## 10050 - Hartals

Moderator: Board moderators

Arashk_kh68
New poster
Posts: 6
Joined: Sun Sep 09, 2007 3:56 pm
May somebody help me plz?!
I think I am encountering some serious problems here, I have coded the solution in about 5 minutes! But Im getting crazy with this judge, Cant get AC although I have tried all testcases provided here, U can check this code yourself and see what I am saying, whats wrong with my code?!

Code: Select all

``````// Hartals.cpp : Defines the entry point for the console application.
// UVA 10050

#include <iostream>
#include <string>
using namespace std;

int main()
{
int cases;
cin >> cases; // number of cases

int offs = 0; // number of working days lost
int nDays; // total number if simultion days
int parties; // number of parties

bool* days; // array used for days counted

for (int i = 0; i < cases; i++) {
cin >> nDays;
days = new bool[nDays + 1]; // + 1 to pass off by one
cin >> parties;

for (int j = 0; j < parties; j++) {
int hParam; // hartal parameter
cin >> hParam;

for (int k = 1; k <= nDays; k++) {
if (days[k] && k % hParam == 0 && k % 7 != 0 && k % 7 != 6) { // checks : 1- day is counted before 2- day must be a hartal 3- day is saturday 4- day is sunday
offs++;
days[k] = false; // flags the day as counted
}
}
}
delete days;
cout << offs;
if (i != cases - 1)
cout << endl; // used to skip last newline
offs = 0;
}

return 0;
}

``````

Ion2Atom
New poster
Posts: 3
Joined: Mon Sep 25, 2006 9:41 pm
I completed this problem not too long ago myself (I had a stupid typo), but I did it on PC. I'm still pretty new at this but if I had to guess.....

1. "days = new bool[nDays + 1];"
Is this statement automatically initialized? I am not very familiar with this style... I use vectors.

2. "if (days[k] && k % hParam == 0 && k % 7 != 0 && k % 7 != 6)"
Why do you do it this way? Although there is nothing wrong with this as far as I can see, you can do it much simpler by doing:

for (int k = 1; k <= nDays; k+=hParam) {
if (k % 7 != 0 && k % 7 != 6) { //not Fri. or Sat.

3. You might want to try going back to zero based for your bool array? Maybe it was just my code, but I got some bad output when I was one based. When I moved over to zero based it worked perfectly (Other than the typo above)

balkrishna
New poster
Posts: 3
Joined: Tue Jun 05, 2007 5:57 pm
Contact:

### hartals wa

accepted

New poster
Posts: 3
Joined: Thu Mar 15, 2007 1:03 am
Ok, I'm officially out of ideas. I haven't seen the program fail yet (doing tests by hand, plus getting I/O from you guys),,, what the hell's wrong with it?

Code: Select all

``````#include <iostream>
using namespace std;

int week[3650];
int hartals[101];

int main() {
int T, P, N, h, l, d, c, x;
cin >> T;
for (int t = 0; t < T; t++) {
for (int i = 0; i < 3650; i++) {
week[i] = 0;
}
for (int i = 0; i <= 100; i++) {
hartals[i] = 0;
}

cin >> N;
cin >> P;
for (int p = 0; p < P; p++) {
cin >> h;
if (hartals[h]) continue;
hartals[h] = 1;

l = 5;
d = -1;
while (d < N) {
d += h;
x = d % 7;
if ((x != 5) && (x != 6)) {
week[d] = 1;
}
}
}

c = 0;
for (d = 0; d < N; d++) {
if (week[d]) {
//	cout << d << " ";
c++;
}
}

cout << c << endl;
}
}``````
Here's the I/O I've been doing:
Input:

Code: Select all

``````10
14
3
3
4
8
100
4
12
15
25
40
21
3
21
6
5
10
1
1
100
1
30
3650
1
1
1
1
1
20
1
20
21
1
21
21
1
22``````
Output:

Code: Select all

``````5
15
5
8
2
2608
1
0
0
0``````
Any help would be appreciated.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Contact:
Check the case..

Input:

Code: Select all

``````1
2672
2
795
1945``````
Output:

Code: Select all

``3``
Hope it helps.

goldenbird299
New poster
Posts: 5
Joined: Sun Aug 05, 2012 6:56 am

### Re: 10050 - Hartals, WA ??

hi all
i got WA for this problem
here's my code:

Code: Select all

``````#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <limits.h>
using namespace std;

int main()
{
int t, n, p, h[130], cnt;
bool b[3660];
cin >> t;
for(int z = 0; z < t; z++)
{
memset(b, 0, sizeof(b));
cnt = 0;
cin >> n >> p;
for(int i = 0; i < p; i++)
cin >> h[i];
for(int i = 0; i < p; i++)
{
for(int k = h[i]-1; k < n; k+=h[i])
{
if(k%5 != 0 && k%6 != 0 && !b[k])//if it's not Friday nor Saturday and it's not been marked before(it's all zero-based)
{
b[k] = 1;
cnt++;
}
}
}
printf("%d\n", cnt);
}
return 0;
}``````
can anybody tell me where i'm wrong?

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10050 - Hartals

Input:

Code: Select all

``````1
14
1
14``````
Output should be 0.
Check input and AC output for thousands of problems on uDebug!

shuvrothpol1
New poster
Posts: 17
Joined: Wed Aug 15, 2012 12:37 pm

### Re: 10050 - Hartals

why wa?
i check the given input & output and it's ok..but getting wa..
#include <stdio.h>

int main ()

{
int i,j,n,N,P,d,t,k,count;

scanf ("%d",&t);
for (j=0;j<t;j++)
{
scanf ("%d",&N);
scanf ("%d",&P);
count=0;
int a[3651]={0};
for (i=0;i<P;i++)
{
scanf ("%d",&d);
n=d;
k=2;
while (d<=N)
{
if (d%7!=6&&d%7!=0)
{
if (a[d]!=1)
{
a[d]=1;
count++;
}
}
d=n*k++;
}
}
printf ("\n%d\n",count);
}
return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10050 - Hartals

Change:
printf ("\n%d\n",count);
to:
printf ("%d\n",count);
Check input and AC output for thousands of problems on uDebug!

shuvrothpol1
New poster
Posts: 17
Joined: Wed Aug 15, 2012 12:37 pm

### Re: 10050 - Hartals

tnx, that is really silly mistake always done by me>>>
anyway, how can i delete my previous post??

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10050 - Hartals

It is probably too late to delete your post after I responded to it. You could edit it out by logging in and then clicking edit next to the post.
Check input and AC output for thousands of problems on uDebug!

mobarak.islam
New poster
Posts: 38
Joined: Wed Dec 05, 2012 11:29 pm

### Re: 10050 - Hartals

@brianfry713 : Here I'm getting wrong answer . I checked all the input output sample regarding this problem and got the appropriate answer.But its getting WA
BTW Thank you for your help in my previous problem.

Code is deleted after getting AC .
Last edited by mobarak.islam on Thu May 23, 2013 10:33 am, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10050 - Hartals

Input:

Code: Select all

``````10
1685
3
1473
975
726
2614
7
1371
2162
2487
906
2179
1858
16
3585
2
908
1112
882
9
29
640
493
431
577
653
523
243
4
1379
12
32
956
1198
451
89
562
837
143
719
34
951
365
2620
10
2
2530
461
1658
297
1929
1923
152
463
2202
2690
6
2545
2348
1959
209
577
967
2130
12
888
877
813
2049
954
310
1765
1920
1951
1294
1033
1032
814
1
794
370
4
120
121
87
226
``````
AC output:

Code: Select all

``````4
121
5
183
86
946
16
19
1
9
``````
Check input and AC output for thousands of problems on uDebug!

mobarak.islam
New poster
Posts: 38
Joined: Wed Dec 05, 2012 11:29 pm

### Re: 10050 - Hartals

@ brianfry713: I checked all the sample input -output given by you and i got AC. But I'm still getting WA while submitting

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10050 - Hartals

The code you posted does not match the I/O I posted. See: https://ideone.com/y3bpwf
Check input and AC output for thousands of problems on uDebug!