Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

17-yuyu0830 #65

Merged
merged 3 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions yuyu0830/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
| 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) | - |
---
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());
}