Skip to content

Commit

Permalink
Merge pull request #84 from HYU-PS-STUDY/wimmings
Browse files Browse the repository at this point in the history
[week-12] 20922, 1005
  • Loading branch information
clean2001 authored Apr 15, 2024
2 parents 951671e + 4b9db6a commit 811ebf8
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
62 changes: 62 additions & 0 deletions week12/wimmings/1005.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include <iostream>
#include <vector>
#include <string>
#include <memory.h>
#include <queue>
#include <algorithm>

using namespace std;
typedef long long ll;

int T, N, K, W, last;

ll delay[1002];
ll dp[1002];

int in[1002];
vector<int> 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<int> 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;
}
39 changes: 39 additions & 0 deletions week12/wimmings/20922.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <iostream>
#include <vector>
#include <string>
#include <memory.h>
#include <queue>
#include <algorithm>

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;
}

0 comments on commit 811ebf8

Please sign in to comment.