코드#include #include #include #include using namespace std;int n;int timetable[10003], indegree[10003], result[10003];vector adj[10003];int main() { cin >> n; // 입력 처리 for (int i = 1; i > time >> count; timetable[i] = time; // 작업에 걸리는 시간 저장 for (int j = 0; j > pre_task; adj[pre_task].push_back(i); // 선행 작업 관계 설정 indegree[i]++; // 해당 작업의 선행 작업 개수 증가..
C++
코드#include #include #include #include #include #include using namespace std;struct edge { int x, y, cnt;};const int dx[] = { 0, 0, 1, -1 };const int dy[] = { 1, -1, 0, 0 };int n, res, visited[53][53];string s;char a[53][53];int bfs() { deque dq; dq.push_back({ 0, 0, 0 }); visited[0][0] = 1; while (!dq.empty()) { int px = dq.front().x; int py = dq.front().y; int cnt = dq.front().cnt; if (px =..
코드#include #include #include #include using namespace std;int m, n, x, y, z, lst[200003], cnt, res, total;vector>> adj;int find(int x) { if (x == lst[x]) return x; return lst[x] = find(lst[x]);}void merge(int x, int y) { x = find(x); y = find(y); if (x > y) lst[x] = y; else lst[y] = x;}bool cmp(pair> a, pair> b) { return a.first > m >> n; if (m == 0 && n == 0) break; CLEAR(); for (int i = 0; ..
코드#include #include #include #include using namespace std;int n, m, lst[1003], u, v, d, cnt, res;char uv[1003]; // 대학교 성별 저장vector>> adj; // 길 저장// 유니온 파인드 for 크루스칼int find(int x) { if (x == lst[x]) return x; return lst[x] = find(lst[x]);}void merge(int x, int y) { x = find(x); y = find(y); if (x > y) lst[x] = y; else lst[y] = x;}// 비용 순 정렬bool cmp(pair> a, pair> b) { return a.first > n >> m; fo..
코드#include #include #include #include using namespace std;int n;string s;// 유클리드 호제법, 최대공약수 구하기int gcd(int x, int y) { while (y) { int tmp = x; x = y; y = tmp % y; } return x;}// 문자열 파싱vector split(string s, string sp) { vector v; long long idx = -1; while ((idx = s.find(sp)) != string::npos) { string tmp = s.substr(0, idx); v.push_back(tmp); s.erase(0, idx + sp.length()); } v.push_back(s)..
코드#include #include using namespace std;stack st; // 오큰수를 찾을 스택stack answer; // 정답을 넣어줄 스택int n, a[1000003];void FASTIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}int main() { FASTIO(); cin >> n; for (int i = 0; i > a[i]; for (int i = n - 1; i > -1; i--) { // top을 검사하면서 top보다 작은 경우를 탐색 while (st.size()) { int top = st.top(); if (top > a[i]) break; st.pop()..
코드1#include #include #include #include using namespace std;// 아기 상어의 크기는 2// 0은 빈칸, 1,2,3,4,5,6은 물고기의 크기 9는 상어// 먹을 수 있는 물고기가 1마리라면 그 물고기를 먹음// 먹을 수 있는 물고기가 여러 마리라면 가장 가까이에 있는 물고기 먹음// 거리가 가까운 물고기가 많다면 가장 위에 있는 물고기, 그런 게 많다면 가장 왼쪽에 있는 물고기를 먹음 (> 사용)// 이동 시 1초, 물고기를 먹으면 빈 칸// 아기상어는 자신의 크기와 같은 수의 물고기를 먹으면 크기 1 증가// 자신의 크기보다 큰 물고기 칸 통행 X, 나머지칸 지나감// 먹는 것은 자기보다 작은 물고기만// 거리는 bfs로 찾자const int dx[] = ..
코드#include #include #include #include #include using namespace std;typedef long long ll;struct st { int fm, fs, fd;};const int dx[] = {-1, -1, 0, 1, 1, 1, 0, -1};const int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};int n, M, k, r, c, m, s, d, res;vector a[52][52];vector b[52][52];void go() { // 이동 for (int i = 0; i 1) { int nm = 0, ns = 0; bool isodd = true, iseve..
코드#include #include #include #include using namespace std;int n, m, known, kc[53], tmp, cnt, hum, res, lst[53], visited[53];vector> pe;// U-F? dfs?int find(int x) { if (x == lst[x]) return x; return lst[x] = find(lst[x]);}void merge(int x, int y) { x = find(x); y = find(y); if (x > y) lst[x] = y; else lst[y] = x;}int main() { cin >> n >> m; cin >> known; for (int i = 0; i > tmp; lst[tmp] = 0; }..
코드#include #include #include #include using namespace std;typedef long long ll;const ll INF = 987654321;ll n, e, a, b, c, vo, vt, visited[808], res;vector> adj[808];ll dijkstra(ll s, ll e) { fill(visited, visited + 808, INF); priority_queue, vector>, greater>> pq; pq.push(make_pair(0, s)); visited[s] = 0; while(!pq.empty()) { int dist = pq.top().first; int here = pq.top().second; pq.pop(); i..