Skip to content

Commit

Permalink
17-yuyu0830
Browse files Browse the repository at this point in the history
17-yuyu0830
  • Loading branch information
yuyu0830 authored Jul 14, 2024
2 parents d1aa6c6 + 81cf867 commit 6ecb574
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
3 changes: 2 additions & 1 deletion yuyu0830/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
| 11μ°¨μ‹œ| 2024.05.08 | 그리디 | [μ—°λ£Œ μ±„μš°κΈ°](https://www.acmicpc.net/problem/1826) | - |
| 12μ°¨μ‹œ| 2024.05.13 | ν•΄μ‹œ | [두 λ°°μ—΄μ˜ ν•©](https://www.acmicpc.net/problem/2143) | - |
| 13μ°¨μ‹œ| 2024.05.21 | LIS | [κ°€μž₯ κΈ΄ μ¦κ°€ν•˜λŠ” λΆ€λΆ„ μˆ˜μ—΄ 2](https://www.acmicpc.net/problem/12015) | - |
| 14μ°¨μ‹œ| 2024.07.02 | μœ„μƒμ •λ ¬ | [ACM Craft](https://www.acmicpc.net/problem/1005) | - |
| 15μ°¨μ‹œ| 2024.06.01 | κΈ°ν•˜ | [λ‹€κ°ν˜•μ˜ 면적](https://www.acmicpc.net/problem/2166) | - |
| 16μ°¨μ‹œ | 2024.06.04 | λ³„μžλ¦¬ λ§Œλ“€κΈ° | [λ³„μžλ¦¬ λ§Œλ“€κΈ°](https://www.acmicpc.net/problem/4386) | - |
| 16μ°¨μ‹œ| 2024.06.04 | λ³„μžλ¦¬ λ§Œλ“€κΈ° | [λ³„μžλ¦¬ λ§Œλ“€κΈ°](https://www.acmicpc.net/problem/4386) | - |
---
73 changes: 73 additions & 0 deletions yuyu0830/μœ„μƒμ •λ ¬/1005.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include <iostream>
#include <queue>

#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

using namespace std;

int f() {
int n, m, t;
cin >> n >> m;

deque<bool> visited(n + 1, 0);
vector<int> arr(n + 1, 0), enter(n + 1, 0), rule[n + 1];

// 건물 μ§“λŠ” 속도
for (int i = 1; i <= n; i++)
cin >> arr[i];

// 건물 μˆœμ„œ
for (int i = 0; i < m; i++) {
int a, b; cin >> a >> b;
rule[a].push_back(b);
enter[b]++;
}

cin >> t;

int ret = 0;

vector<int> tmp[2];
bool e = false;

// μ›ν•˜λŠ” 건물 지을 수 μžˆμ„ λ•ŒκΉŒμ§€ 반볡
while (true) {
// ret μ‹œκ°„μ— 지을 수 μžˆλŠ” 건물듀 탐색 및 tmp 큐에 push
// μ›ν•˜λŠ” 건물을 지을 수 있으면 ν•¨μˆ˜ μ’…λ£Œ 및 κ°’ λ°˜ν™˜
for (int i = 1; i <= n; i++) {
if (!enter[i] && !visited[i]) {
if (i == t) return ret + arr[i];

visited[i] = true;
tmp[e].push_back(i);
}
}

int m = 99999999;

// μ§€κΈˆ μ§“κ³ μžˆλŠ” 건물 + 지을 수 μžˆλŠ” 건물 쀑 μ‹œκ°„ κ°€μž₯ 적게 남은 κ°’ 탐색
for (int i : tmp[e]) { m = min(m, arr[i]); }

// tmp 큐에 μžˆλŠ” λͺ¨λ“  건물듀 m만큼 건섀 진행, μ™„μ„±λ˜λ©΄ νμ—μ„œ 제거
while (!tmp[e].empty()) {
int a = tmp[e].back();
tmp[e].pop_back();

arr[a] -= m;

if (arr[a]) { tmp[!e].push_back(a); }
else { for (int i : rule[a]) { enter[i]--; } }
}

e = !e;
ret += m;
}
}

int main() {
fastio

int testCase; cin >> testCase;
while (testCase--)
printf("%d\n", f());
}

0 comments on commit 6ecb574

Please sign in to comment.