시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 169 31 20 19.417%

문제

메모리 할당 명령을 시뮬레이팅하는 프로그램을 작성하시오.

메모리는 100,000개의 연속된 공간이고, 1번부터 100,000번까지 번호가 매겨져 있다. 초기에 모든 공간은 할당되지 않은 상태이다.

명령어의 종류는 다음 중 하나이다.

  1. var=malloc(size);
    • 이 함수은 처음 등장하는 size개의 연속된 공간을 찾아, 할당해주는 함수이다. 이 함수의 리턴값은 할당된 공간의 제일 처음 주소이다. 만약, 할당해줄 수 있는 공간이 없다면 0을 리턴한다. (100 ≤ size ≤ 100,000)
  2. free(var);
    • 이 함수는 이전에 malloc을 통해 var에 할당된 공간을 할당 해제시켜주고, var0을 저장하는 함수이다. 만약, var가 이미 0이라면, 아무 일도 일어나지 않는다.
  3. print(var);
    • var에 저장된 값을 출력하는 함수이다.

모든 명령은 세미콜론(';')으로 끝난다. 변수는 알파벳 소문자로 이루어져 있으며, 항상 네글자이다. 서로 다른 변수의 개수는 1,000개보다 작거나 같다. 모든 변수는 0으로 초기화되어있다.

입력

첫째 줄에 명령의 개수 N이 주어진다. (1 ≤ N ≤ 100,000)

다음 N개의 줄에는 명령이 수행된 순서대로 하나씩 주어진다.

print는 한 번 이상 주어진다.

출력

print가 나올 때 마다 결과를 한 줄에 하나씩 출력한다.

예제 입력 1

5
baka=malloc(214);
baka=malloc(123);
free(baka);
deda=malloc(100);
print(deda);

예제 출력 1

215
W3sicHJvYmxlbV9pZCI6IjMyMTciLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJtYWxsb2MiLCJkZXNjcmlwdGlvbiI6IjxwPlx1YmE1NFx1YmFhOFx1YjlhYyBcdWQ1NjBcdWIyZjkgXHViYTg1XHViODM5XHVjNzQ0IFx1YzJkY1x1YmJhY1x1YjgwOFx1Yzc3NFx1ZDMwNVx1ZDU1OFx1YjI5NCBcdWQ1MDRcdWI4NWNcdWFkZjhcdWI3YThcdWM3NDQgXHVjNzkxX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zOTtwcmludCYjMzk7IGNvbW1hbmRzLCBpbiBvcmRlciBvZiB0aGVpciBleGVjdXRpb24sIGVhY2ggb25lIGluIHNlcGFyYXRlIGxpbmUuJm5ic3A7PFwvcD5cclxuXHJcbjxwPiZuYnNwOzxcL3A+XHJcbiIsImhpbnQiOiIiLCJvcmlnaW5hbCI6IjEiLCJwcm9ibGVtX2xhbmdfY29kZSI6Ilx1YzYwMVx1YzViNCJ9XQ==

출처

Olympiad > Croatian Highschool Competitions in Informatics > 2004 > National Competition #2 - Juniors 2번

  • 문제의 오타를 찾은 사람: adh0463
  • 문제를 번역한 사람: baekjoon