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

772kb and still got MLE#10, please help me
Posted by quangduytr 10 Mar 2017 12:15
#include <iostream>
using namespace std;
struct duy{
    long long x; int y;
};
int n,x,last[1001];
long long  y;
duy m[100001];
char s[5];
int main()
{
    cin.tie(NULL); cout.tie(NULL);
    cin>>n;
    for(int i=1; i<=n; i++){
        cin>>s>>x;
        if(s[1]=='U'){
            cin>>y;
            m[i].x=y; m[i].y=last[x]; last[x]=i;
        }
        else{
            cout<<m[last[x]].x;
            last[x]=m[last[x]].y;
        }
    }
}
Re: 772kb and still got MLE#10, please help me
Posted by ToadMonster 10 Mar 2017 15:41
By task description, B is an integer (0 ≤ B ≤ 10^9). So
"int x", not "long long x".

But it shouldn't be enough. Please estimate (or just type from local run) sizeof(duy) and sizeof(m). Then read task memory restriction. Assume that even "empty main()" program spends about 100 Kb (see successful runs of "1000 A+B" problem for your compiler).

In this case duy can hold not only one x, but bucket - ~30 values for example. More, 30 bits are required to save B. So it's possible to save 32 values into "int x[30]" array.

Edited by author 10.03.2017 15:50