diff --git a/week12/wimmings/1005.cpp b/week12/wimmings/1005.cpp new file mode 100644 index 0000000..c441355 --- /dev/null +++ b/week12/wimmings/1005.cpp @@ -0,0 +1,62 @@ +#include +#include +#include +#include +#include +#include + +using namespace std; +typedef long long ll; + +int T, N, K, W, last; + +ll delay[1002]; +ll dp[1002]; + +int in[1002]; +vector order[1002]; + +int main() { + ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); + cin >> T; + while (T--) { + memset(delay, 0, sizeof(delay)); + memset(dp, 0, sizeof(dp)); + memset(in, 0, sizeof(in)); + memset(order, 0, sizeof(order)); + cin >> N >> K; + for (int i = 1; i <= N; ++i) { + cin >> delay[i]; + dp[i] = delay[i]; + } + for (int i = 0; i < K; ++i) { + int first, second; cin >> first >> second; + order[first].push_back(second); + in[second]++; // second로 들어오는 선 개수 증가 + } + cin >> last; + + // in이 0인 거 골라서 쭉 돌기 + queue q; + for (int i = 1; i <= N; ++i) { + if (in[i] == 0) q.push(i); // 젤 끝에 있는 거, 젤 처음해야하는 건물 + } + while (!q.empty()) { + int start = q.front(); + q.pop(); + for (int i = 0; i < order[start].size(); ++i) { // start에서 갈 수 있는 점에다가 더함, 도착지의 in을 빼주고, 만약 0되면 큐에 넣어주기 + int next = order[start][i]; + if (dp[next] < dp[start] + delay[next]) { + dp[next] = dp[start] + delay[next]; + } + in[next]--; + if (in[next] == 0) { + q.push(next); + } + } + } + + cout << dp[last] << '\n'; // last까지 짓는 데 걸리는 시간 + } + return 0; +} \ No newline at end of file diff --git a/week12/wimmings/20922.cpp b/week12/wimmings/20922.cpp new file mode 100644 index 0000000..ba2718f --- /dev/null +++ b/week12/wimmings/20922.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include +#include + +using namespace std; +int n, k; +int map[200002]; +int cnt[100002]; + + +int main() { + ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); + cin >> n >> k; + for (int i = 0; i < n; ++i) { + cin >> map[i]; + } + int en = 0; + int ans = -1; + + for (int st = 0; st < n; ++st) { + while (cnt[map[en]]+1 <= k && en < n) { + cnt[map[en]]++; + en++; + } + if (en == n) { + ans = max(ans, en-st); + break; + } + + ans = max(ans, en-st); + cnt[map[st]]--; + } + cout << ans << '\n'; + + return 0; +} \ No newline at end of file