Блог пользователя saurabh_coder

Автор saurabh_coder, история, 4 года назад, По-английски

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!

  • Проголосовать: нравится
  • -10
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится +11 Проголосовать: не нравится

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 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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";
    }
}