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...

WA #3 Please Help what's wrong with my program
Posted by Rashad 5 May 2010 22:29
I didn't solve it by the easiest way..
This is my program, it gives right answers for my tests, but I have WA #3 , give me please this test

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

using namespace std;

int main(int argc, char *argv[])
{
    long n,i,j,a;
    long na=65536;
    vector <long> pos,test;
    vector <long>:: iterator it;

    pos.push_back(1); pos.push_back(2);
    for (i=2;i<na;i++) { pos.push_back(pos[i-1]+i); }

    cin>>n;
    for (i=0;i<n;i++) { cin>>a; test.push_back(a); }

    sort(test.begin(),test.end());

    j=0;
    for (i=0;i<n;i++)
    {
        while ((j<na) && (test[i]>pos[j])) { j++; }
        if (j==na) { cout<<"0 "; }
        else if (test[i]==pos[j]) { cout<<"1 "; }
        else { cout<<"0 "; }
    }
    cout<<endl;

    system("PAUSE");
    return EXIT_SUCCESS;
}

Edited by author 05.05.2010 22:29
Re: WA #3 Please Help what's wrong with my program
Posted by Nevena 29 May 2011 07:05
Have you tried for large values for k? It possibly overflows