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 time limit exceeded in test#3 ?
Posted by Shadab 26 Apr 2016 00:38
My Code:
#include <bits/stdc++.h>
using namespace std;

int main()
{
    //freopen("in.txt","r", stdin);

    unsigned long long int n,k,x,j; cin >> n;
    for(int i=1; i<=n; i++)
    {
        cin >> k;
        x=1;
        j=0;
        while(j<k)
        {
            j+=x;
            if(j<k) x++;
        }
        x--;

        if(j-k < x) cout << 0 << " ";
        else cout << 1 << " ";
    }
    cout << endl;

    return 0;
}

Edited by author 26.04.2016 00:41
Re: Why time limit exceeded in test#3 ?
Posted by ToadMonster 26 Apr 2016 10:32
Optimal solution description:
http://acm.timus.ru/forum/thread.aspx?id=30833&upd=635783259604987487

Not optimal solution:
To precalculate postions of "1" once, save them into container with quick lookup (sorted vector+binary saearch/set/unordered_set) and check if position is in container
Re: Why time limit exceeded in test#3 ?
Posted by Shadab 26 Apr 2016 10:42
Thanx :)