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

Please Help, TLE #21
Posted by Najmaddin Akhundov 12 Dec 2014 12:31
#include<iostream>

using namespace std;

int arr[500005];

int main()
{
    int n;
    cin >> n;

    long long int a;
    int p = 0;

    arr[0] = -1;
    for (int i = 0; i < n; i++)
    {

        cin >> a;

        if (a == arr[p] || p == 0)
        {
            p++;
            arr[p] = a;
        }
        else
            p--;
    }

    cout << arr[1] << endl;

}

Edited by author 12.12.2014 12:48

Edited by author 12.12.2014 12:48