saurabh_coder's blog

By saurabh_coder, history, 4 years ago, In English

I participate in google kick start 2020 round D. Whenever I submitted my solution, it shows " Wrong Answer: test cases skipped". After the competition, when I look for other's solution, I skipped one corner cases, which was not clear to me. Recently, I tried to solve another problem: https://codingcompetitions.withgoogle.com/kickstart/round/000000000019ff43/00000000003380d2#problem and face the same problem. My solution is https://ideone.com/7xGHUO, which I expect to be correct. Please help me out!

  • Vote: I like it
  • -10
  • Vote: I do not like it

»
4 years ago, # |
  Vote: I like it +11 Vote: I do not like it

Write a naive solution (or take someone's solution if the contest is over) and make a script to run it on many random small test cases.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Your Solution is Wrong .

Test Case :

1

5 3

3 2 3 2 1

Correct Output :- 1

Your Output :- 0

Correct Solution Using your code only and changing only few lines :

#include<bits/stdc++.h>
using namespace std;

int solve()
{
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0 ; i < n ; i++) 
        cin >> a[i];
    int ans = 0, m = k;
    for(int i = 0 ; i < n ; i++)
    {
        if (a[i] != m)
            m = k;
        if(a[i] == m)
        {
            m--;
            if(m==0) 
            {
                ans++; 
                m = k;
            }
        }
    }
    return ans;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin >> t;
    for(int tc = 1 ; tc <= t ; tc++)
    {
        cout << "Case #" << tc << ": " << solve() << "\n";
    }
}