Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- typedef long long ll;
- #define fr first
- #define sc second
- #define pii pair <int, int>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0); cout.tie(0);
- int cnt_1 = 1, cnt_2 = 1;
- int t_1 = 30, t_2 = 15;
- int t_need_1 = 11, t_need_2 = 6;
- int mem_1 = 8, mem_2 = 4;
- vector <bool> use(36);
- queue <pii> need_1, need_2;
- int crash = -1, num = 0;
- ll time = 0;
- while (crash == -1) {
- if (!need_1.empty() && need_1.front().fr <= time) {
- for (int i = need_1.front().sc; i < need_1.front().sc + mem_1; i++) use[i] = 0;
- need_1.pop();
- }
- if (!need_2.empty() && need_2.front().fr <= time) {
- for (int i = need_2.front().sc; i < need_2.front().sc + mem_2; i++) use[i] = 0;
- need_2.pop();
- }
- if (cnt_1 > 0 && time % t_need_1 == 0) {
- bool ok = 0;
- int n_ans = -1;
- for (int i = 0; i < 36; i++) {
- if (!use[i]) {
- int cnt = 0;
- for (int j = 0; j + i < 36 && j < mem_1; j++, cnt++) {
- if (use[i + j]) {
- cnt = -1;
- break;
- }
- }
- if (cnt == mem_1) {
- n_ans = i;
- ok = 1;
- break;
- }
- }
- }
- if (!ok) crash = 1, num = cnt_1;
- if (crash == -1) for (int i = n_ans; i < n_ans + mem_1; i++) use[i] = 1;
- if (n_ans != -1) need_1.push({time + t_1, n_ans});
- cnt_1++;
- }
- if (cnt_2 > 0 && time % t_need_2 == 0) {
- bool ok = 0;
- int n_ans = -1;
- for (int i = 0; i < 36; i++) {
- if (!use[i]) {
- int cnt = 0;
- for (int j = 0; j + i < 36 && j < mem_2; j++, cnt++) {
- if (use[i + j]) {
- cnt = -1;
- break;
- }
- }
- if (cnt == mem_2) {
- n_ans = i;
- ok = 1;
- break;
- }
- }
- }
- if (!ok) crash = 2, num = cnt_2;
- if (crash == -1) for (int i = n_ans; i < n_ans + mem_2; i++) use[i] = 1;
- cnt_2++;
- if (n_ans != -1) need_2.push({time + t_2, n_ans});
- }
- time++;
- }
- cout << crash << " " << num;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement