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 1915. Titan Ruins: Reconstruction of Bygones

OH my god!!!!! Use vc++2010 or g++4.7.2 instead of G++4.7.2c++11
Posted by Pegasus 23 Apr 2013 18:45
When I use G++11 I always get TLE,but once I try vc++2010 to submit my code , I got AC.
I wasted too much time.Any can expalin it for me ?
This is my code:#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
const int MAXN = 1000000 + 10;
int a[2 * MAXN];
using namespace std;
int main()
{
    int n;
    scanf("%d", &n);
    int i = 1;
    while (n--)
    {
        int t;
        scanf("%d", &t);
        if (t > 0)
            a[i++] = t;
        else if (t == -1)
            printf("%d\n", a[--i]);
        else if (t == 0)
        {
            if (i - 1 <= n)
            {
                int num = min(i - 1, n);
                for (int j = 1; j <= num; ++j)
                {
                    a[i] = a[i-num];
                    ++i;
                }
            }
        }
    }
    //system("pause");
    return 0;
}

Edited by author 26.04.2013 15:20
REALLY!
Posted by BORODA 9 Dec 2013 21:06
MY LIFE WILL NEVER BE THE SAME! How does it works? could anybody explain it?
Re: OH my god!!!!! Use vc++2010 or g++4.7.2 instead of G++4.7.2c++11
Posted by Chitanda Eru 10 Dec 2013 08:17
Apparently, printf is painfully slow in C++11 for some reason. I was having the same issue while trying to submit problem #1976 (where answer consists of up to 1000000 integers) and ended up implementing manual output via putchar. Now i know a simple change of language would've worked as well.

Edited by author 10.12.2013 08:17