Advertisement
shek_shek

acm.sgu.ru/lang problem-2049

Oct 7th, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stack>
  3. #include <math.h>
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <string.h>
  7. #include <string>
  8. #include <set>
  9. #include <memory.h>
  10. #include <vector>
  11. #include <map>
  12. #include <queue>
  13. #include <iomanip>
  14. #include <ctime>
  15. #include <cassert>
  16.  
  17.  
  18.  
  19. #define forn(i, n) for (int i = 0; i < int(n); i++)
  20. #define ll long long
  21. #define mp(a, b) make_pair(a, b)
  22. #define sqr(x) ( (x) * (x) )
  23. #define all(a) a.begin(), a.end()
  24.  
  25. using namespace std;
  26.  
  27. typedef pair <int, int> pt;
  28. typedef long double ld;
  29. const int INF = 1e9;
  30. const ld EPS = 1e-9;
  31.  
  32. int a[101];
  33.  
  34. int main() {
  35. #ifdef _DEBUG
  36.     freopen("input.txt", "r", stdin);
  37.     freopen("output.txt", "w", stdout);
  38. #endif
  39.     int t, m;
  40.     cin >> t >> m; 
  41.     int id = 1;
  42.     forn (i, t) {
  43.         string s;
  44.         int x;
  45.         cin >> s;
  46.         if (s == "alloc") {
  47.             cin >> x;
  48.             bool ok = true;
  49.             if (x > m) {
  50.                 cout << "NULL" << endl;
  51.                 continue;
  52.             }
  53.             forn (j, m - x + 1) {
  54.                 ok = true;
  55.                 for (int k = j; k < j + x && ok; k++) {
  56.                     if (a[k] != 0)
  57.                         ok = false;
  58.                 }
  59.                 if (ok) {
  60.                     for (int k = j; k < j + x && ok; k++) {
  61.                         a[k] = id;
  62.                     }
  63.                     cout << id << endl;
  64.                     id++;
  65.                     break;
  66.                 }
  67.             }
  68.             if (!ok)
  69.                 cout << "NULL" << endl;
  70.         }
  71.         if (s == "erase") {
  72.             cin >> x;
  73.             if (x < 1) {
  74.                 cout << "ILLEGAL_ERASE_ARGUMENT" << endl;
  75.                 continue;
  76.             }
  77.             bool ok = false;
  78.             forn (j, m) {
  79.                 if (a[j] == x) {
  80.                     a[j] = 0;
  81.                     ok = true;
  82.                 }
  83.             }
  84.             if (!ok) {
  85.                 cout << "ILLEGAL_ERASE_ARGUMENT" << endl;
  86.             }
  87.         }
  88.         if (s == "defragment") {
  89.             forn (j, m) {
  90.                 int k = j;
  91.                 while (k != 0 && a[k] != 0 && a[k - 1] == 0) {
  92.                     a[k - 1] = a[k];
  93.                     a[k] = 0;
  94.                     k--;
  95.                 }
  96.             }
  97.         }
  98.     }
  99.     return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement