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

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

This code snippet is giving: Segmentation fault (core dumped) on my laptop, but running just fine on Custom test on codeforces when I give input like 10^6 or so.

I think the problem is related to space taken by recursive calls, but i don't understand it completely.

Help!!

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

int n;

int solve(int i){
    if(i==(n-1)){
        return 1;
    }
    int sum1 = solve(i+1);    
    return 1;    
}

int main(){
    int i;
    cin>>n;
    int ans =solve(1);
    cout<<ans;
    return 0;
}

Полный текст и комментарии »

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

Автор jiraiya_777, история, 5 лет назад, По-английски

Hello Codeforces,

I was solving this problem on hackerrank.

I successfully solved it in (O(nlogm)) by submitting this (for hackkerank site). All test cases passed.

But this submission (for hackkerank site) (O(n+m)) passes all but fails this test case. Why??

Also when i try to implement the above solutions on my computer they run indefinitely on other test cases(which got accepted on hackerrank) for large values of n and m.

Help!!

Note- I have already solved the question in O(nlog(m)), so i tried for O(n+m) and this solution passed all but 1 test case.

I need help in knowing what's wrong with the 2nd approach.

Полный текст и комментарии »

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