ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1220. Stacks

use same memory in all test but MLE test 10, WHY?
Послано Alexander J. Villalba G. 14 сен 2009 18:50
OK Denis Koshman, I did (thanks) but MLE test 10

why?

the program in all test use same memory and no use dinamic memory BUT MLE test 10

WHY?

is unbelive !!!

#include <iostream>
#include <string>
using namespace std;

unsigned int a[100000];
unsigned short b[100000];
int f[1000];

int nn=0;

inline int get_value(unsigned x)
{
return a[x] & 0x7FFFFFFF;
}

inline void set_value(unsigned x, unsigned v)
{
(a[x] &= 0x80000000) |= v;
}

inline int get_next(unsigned x)
{
return b[x] | ((a[x]>>31)<<16);
}

inline int set_next(unsigned x, unsigned v)
{
b[x] = v, (a[x] &= 0x7FFFFFFF) |= (v>>16)<<31;
}

void push (int pila, int v) {


int x = nn++; // 'nn' is global ever-growing variable
set_value(x, v);
set_next(x, f[pila]);
f[pila] = x;
}

void pop(int pila) {

cout << get_value(f[pila]) << endl;
f[pila] = get_next(f[pila]);

}


int main (void) {
int n;
int pila, v;

cin >> n;
string s;
unsigned int a,b,ss=0;

for(int i=0; i<n; i++)
{
cin >> s;
if(s=="PUSH")
{
cin >> pila;
cin >> v;

push(pila, v);
}

if(s=="POP")
{

cin >> pila;
pop (pila);

}
}
return 0;
}
Re: use same memory in all test but MLE test 10, WHY?
Послано nikonoff (ONPU) 14 сен 2009 19:10
1. remove

#include <iostream>
#include <string>
using namespace std;
...cin...
...cout...

2. but use

#include <cstdio>
...scanf ()...
...printf ()...

3. You'll get AC

because <iostream> use some extra memory more than <stdio.h>

4. about MLE

Timus Judge counts only real used memory for current test while executable running.
e.g.

static int vector [4*1024*1024];
...
for (int i = 0; i < 1024*1024; ++i)
{
    ...vector [i]...
}

this code gives you only 4MB used (not 16MB as expected)
this fact checked experimentally...
Re: use same memory in all test but MLE test 10, WHY?
Послано Alexander J. Villalba G. 14 сен 2009 19:48
thanks , : D