NW1 - EDITORIAL

PROBLEM LINK:

Practice
Contest

Setter : Mohammad Salik

Tester : Hasan Jaddouh

Editorialist : Mohammad Salik

Difficulty

Cakewalk

Prerequisites

None

Problem

You are given an integer W and a string S where W is the number of days in the month and S is the first day of the month. You are required to find the frequencies of all the seven days(monday to sunday) in that month.

Explanation

Each day of the month will come at least 4 times in a month irrespective of the number of days in that month or the start day.

All 7 days coming 4 times each : 7*4=28

Number of Days left: W-28 (lets denote this by X)

Now we assign the frequency 5 to X days starting from S(The start day)

Rest of the days will be assigned the frequency 4

Alternate Explanation

We run a loop from 1 to W updating the count of days according to the day of start

       for(int i=1;i<=W;i++)
       {
            count[id]++;
            id++;
            if(id==7)
            {
               id=0;
            }
        }

where id is initialized according to the first day .

id=0 represents S=mon

id=1 represents S=tues
and so on…

count[0] represent frequency of monday

count$[$1] represent frequency of tuesday

and so on…

Time Complexity

O(1) per testcase

Space Complexity

O(1)

AUTHOR’S AND TESTER’S SOLUTIONS:

Author’s solution can be found here.
Tester’s solution can be found here.

TO @jeioncs

i do not understand what real world implementation u are showing.
but look at calendar and see the month of november 2017
now add one more day i.e. 31st to november. Now calculate the number of occurance for each day.
And remember the starting day is monday here as written in problem statement.

the answer is correct.It doesn’t fail in the reality.
welcome to help.

adios.

To @ujjawal14

Perhaps i am missing something, what i want to say is…

[test data year 2017]

12
31 tues
28 tues
31 fri
30 sun
31 wed
30 fri
31 mon
31 thurs
30 sat
31 tues
30 thurs
30 sun

[Solution proposed in the challenge]

4 5 5 5 4 4 4 
4 4 4 4 4 4 4 
4 4 4 4 5 5 5 
5 4 4 4 4 4 5 
4 4 5 5 5 4 4 
4 4 4 4 5 5 4 
5 5 5 4 4 4 4 
4 4 4 5 5 5 4 
4 4 4 4 4 5 5 
4 5 5 5 4 4 4 
4 4 4 5 5 4 4 
5 4 4 4 4 4 5 

[Solution that i think is correct]

 5 5 4 4 4 4 5
 4 4 4 4 4 4 4
 4 4 5 5 5 4 4
 4 4 4 4 4 5 5
 5 5 5 4 4 4 4
 4 4 4 5 5 4 4
 5 4 4 4 4 5 5
 4 5 5 5 4 4 4
 4 4 4 4 5 5 4
 5 5 4 4 4 4 5
 4 4 5 5 4 4 4
 4 4 4 4 4 5 5

[Reality]

on a linux system --> ncal -M -b -y 2017 or
alt text

There is no need to invent days like November 31

I hope this is better explained.

Thanks for your quick answer.

Bye

simple pen and paper https://www.codechef.com/viewsolution/16709580

while (t-- > 0)
{

int W=s.nextInt();
String str=s.next();

int y=W%7;
if (str.equals(“mon”))
{
if (y==0) System.out.println(“4 4 4 4 4 4 4”);
if (y==1)System.out.println(“5 4 4 4 4 4 4”);
if (y==2)System.out.println(“5 5 4 4 4 4 4”);
if (y==3)System.out.println(“5 5 5 4 4 4 4”);

        }
        if (str.equals("tues"))
        {
            if (y==0) System.out.println("4 4 4 4 4 4 4");
            if (y==1) System.out.println("4 5 4 4 4 4 4");
            if (y==2) System.out.println("4 5 5 4 4 4 4");
            if (y==3) System.out.println("4 5 5 5 4 4 4");
        }
        if (str.equals("wed"))
        {
            if (y==0) System.out.println("4 4 4 4 4 4 4");
            if (y==1) System.out.println("4 4 5 4 4 4 4");
            if (y==2) System.out.println("4 4 5 5 4 4 4");
            if (y==3) System.out.println("4 4 5 5 5 4 4");
        }
        if (str.equals("thurs"))
        {
            if (y==0) System.out.println("4 4 4 4 4 4 4");
            if (y==1) System.out.println("4 4 4 5 4 4 4");
            if (y==2) System.out.println("4 4 4 5 5 4 4");
            if (y==3) System.out.println("4 4 4 5 5 5 4");
        }
        if (str.equals("fri"))
        {
            if (y==0) System.out.println("4 4 4 4 4 4 4");
            if (y==1) System.out.println("4 4 4 4 5 4 4");
            if (y==2) System.out.println("4 4 4 4 5 5 4");
            if (y==3) System.out.println("4 4 4 4 5 5 5");
        }
        if (str.equals("sat"))
    {
        if (y==0) System.out.println("4 4 4 4 4 4 4");
        if (y==1) System.out.println("4 4 4 4 4 5 4");
        if (y==2) System.out.println("4 4 4 4 4 5 5");
        if (y==3) System.out.println("5 4 4 4 4 5 5");
    }
        if (str.equals("sun"))
        {
            if (y==0) System.out.println("4 4 4 4 4 4 4");
            if (y==1) System.out.println("4 4 4 4 4 4 5");
            if (y==2) System.out.println("5 4 4 4 4 4 5");
            if (y==3) System.out.println("5 5 4 4 4 4 5");
        }




    }

I just see now!!!
I misinterpreted the problem. The day of the week in not the las day of the month, even the first.

Thanks for the patience an answers!!!

Thanks to @ujjawal14 and @paranoia

This is my not so appreciable code:

//AUTHOR ANUPAM PRAKASH MMMUT

#include<bits/stdc++.h>
#define ll long long int
#define FAST ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main()
{
//your code goes here
FAST
int t;
cin>>t;
while(t–)
{
int mon=0,tue=0,wed=0,thurs=0,fri=0,sat=0,sun=0;
int w;cin>>w;
string s;cin>>s;
if(s==“mon”)
{
for(int i=1;i<=w;i+=7)
if(i<=w)
mon++;
for(int i=2;i<=w;i+=7)
if(i<=w)
tue++;
for(int i=3;i<=w;i+=7)
if(i<=w)
wed++;
for(int i=4;i<=w;i+=7)
if(i<=w)
thurs++;
for(int i=5;i<=w;i+=7)
if(i<=w)
fri++;
for(int i=6;i<=w;i+=7)
if(i<=w)
sat++;
for(int i=7;i<=w;i+=7)
if(i<=w)
sun++;
}
else if(s==“tues”)
{
for(int i=7;i<=w;i+=7)
if(i<=w)
mon++;
for(int i=1;i<=w;i+=7)
if(i<=w)
tue++;
for(int i=2;i<=w;i+=7)
if(i<=w)
wed++;
for(int i=3;i<=w;i+=7)
if(i<=w)
thurs++;
for(int i=4;i<=w;i+=7)
if(i<=w)
fri++;
for(int i=5;i<=w;i+=7)
if(i<=w)
sat++;
for(int i=6;i<=w;i+=7)
if(i<=w)
sun++;
}
else if(s==“wed”)
{
for(int i=6;i<=w;i+=7)
if(i<=w)
mon++;
for(int i=7;i<=w;i+=7)
if(i<=w)
tue++;
for(int i=1;i<=w;i+=7)
if(i<=w)
wed++;
for(int i=2;i<=w;i+=7)
if(i<=w)
thurs++;
for(int i=3;i<=w;i+=7)
if(i<=w)
fri++;
for(int i=4;i<=w;i+=7)
if(i<=w)
sat++;
for(int i=5;i<=w;i+=7)
if(i<=w)
sun++;
}
else if(s==“thurs”)
{
for(int i=5;i<=w;i+=7)
if(i<=w)
mon++;
for(int i=6;i<=w;i+=7)
if(i<=w)
tue++;
for(int i=7;i<=w;i+=7)
if(i<=w)
wed++;
for(int i=1;i<=w;i+=7)
if(i<=w)
thurs++;
for(int i=2;i<=w;i+=7)
if(i<=w)
fri++;
for(int i=3;i<=w;i+=7)
if(i<=w)
sat++;
for(int i=4;i<=w;i+=7)
if(i<=w)
sun++;
}
else if(s==“fri”)
{
for(int i=4;i<=w;i+=7)
if(i<=w)
mon++;
for(int i=5;i<=w;i+=7)
if(i<=w)
tue++;
for(int i=6;i<=w;i+=7)
if(i<=w)
wed++;
for(int i=7;i<=w;i+=7)
if(i<=w)
thurs++;
for(int i=1;i<=w;i+=7)
if(i<=w)
fri++;
for(int i=2;i<=w;i+=7)
if(i<=w)
sat++;
for(int i=3;i<=w;i+=7)
if(i<=w)
sun++;
}
else if(s==“sat”)
{
for(int i=3;i<=w;i+=7)
if(i<=w)
mon++;
for(int i=4;i<=w;i+=7)
if(i<=w)
tue++;
for(int i=5;i<=w;i+=7)
if(i<=w)
wed++;
for(int i=6;i<=w;i+=7)
if(i<=w)
thurs++;
for(int i=7;i<=w;i+=7)
if(i<=w)
fri++;
for(int i=1;i<=w;i+=7)
if(i<=w)
sat++;
for(int i=2;i<=w;i+=7)
if(i<=w)
sun++;
}
else
{
for(int i=2;i<=w;i+=7)
if(i<=w)
mon++;
for(int i=3;i<=w;i+=7)
if(i<=w)
tue++;
for(int i=4;i<=w;i+=7)
if(i<=w)
wed++;
for(int i=5;i<=w;i+=7)
if(i<=w)
thurs++;
for(int i=6;i<=w;i+=7)
if(i<=w)
fri++;
for(int i=7;i<=w;i+=7)
if(i<=w)
sat++;
for(int i=1;i<=w;i+=7)
if(i<=w)
sun++;
}
cout<<mon<<" “<<tue<<” “<<wed<<” “<<thurs<<” “<<fri<<” “<<sat<<” "<<sun<<endl;

}
return 0;

}

https://www.codechef.com/viewsolution/33327804
can anyone pls tell how to resolve the runtime error NZEC ( on submitting the code)