ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1209. 1, 10, 100, 1000...

why runtime error (non zero exit code) in test 3!!!
Posted by Md Iqbal Hafiz 16 Dec 2015 13:50
getting runtime error in this code!!  pls help me
here is my code!!!

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

main()
{
    long long int i,N,j,l;
    vector<long long int>k,cp;
    cin >> N;
    k.resize(N);
    for(i=0;i<N;i++)
        cin >> k[i];
    cp.resize(N);
    cp=k;
    vector<int>ans;
    sort(cp.begin(),cp.end());
    ans.resize(cp[N-1]+1);
    for(l=1,j=0;l<(cp[N-1]+1);l+=(++j))
        ans[l]=1;
    for(i=0;i<N;i++)
        cout << ans[k[i]] << " ";
    return 0;
}

Edited by author 16.12.2015 14:03

Edited by author 16.12.2015 14:05
Re: why runtime error (non zero exit code) in test 3!!!
Posted by ToadMonster 16 Dec 2015 16:33
1) Any reason to use std::sort() instead of std::maximum_element() to find maximum element?

2) > ans.resize(cp[N-1]+1);
What maximum value of "cp[N-1]+1" is? Isn't it 2^31-1?