Algorithm ๐ง๐ป๐ป457 [๋ฐฑ์ค,c++] 17266๋ฒ - ์ด๋์ด ๊ตด๋ค๋ฆฌ ๋ฌธ์ 17266๋ฒ: ์ด๋์ด ๊ตด๋ค๋ฆฌ ์ธํ๋ํ๊ต ํ๋ฌธ ๋ค์ชฝ์๋ ์ด๋์ด ๊ตด๋ค๋ฆฌ๊ฐ ์๋ค. ๊ฒ์์ด ์๋น์ด๋ ๊ธธ์ด ์กฐ๊ธ์ด๋ผ๋ ์ด๋ก๋ค๋ฉด ๊ฐ์ง ์๋๋ค. ๋ฐ๋ผ์ ๊ตด๋ค๋ฆฌ๋ก ๊ฐ๋ฉด ์ต๋จ๊ฑฐ๋ฆฌ๋ก ์ง๊น์ง ๊ฐ์ ์์ง๋ง, ๊ตด๋ค๋ฆฌ๋ ์ด๋ก๊ธฐ ๋๋ฌธ์ ๋น www.acmicpc.net ์ฝ๋ #include #include #include using namespace std; int N, M; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin>>N>>M; vector v(M); double height = 0; for(int i=0; i>v[i]; if(M==1) height = N; height = fmax(v.front(), (ceil(N-v.back()))); for(int i=.. 2022. 8. 18. [๋ฐฑ์ค,c++] 17521๋ฒ - Byte Coin ๋ฌธ์ 17521๋ฒ: Byte Coin ์ ๋ ฅ์ ํ์ค์ ๋ ฅ์ ์ฌ์ฉํ๋ค. ์ฒซ ๋ฒ์งธ ์ค์ ์์ผ ์๋ฅผ ๋ํ๋ด๋ ์์ ์ ์ n๊ณผ ์ด๊ธฐ ํ๊ธ W(1 ≤ n ≤ 15, 1 ≤ W ≤ 100,000)๊ฐ ์ฃผ์ด์ง๋ค. ๋ค์ n ๊ฐ์ ์ค์์, i๋ฒ์งธ ์ค์ i์ผ์ ๋ฐ์ดํธ ์ฝ์ธ ๊ฐ๊ฒฉ์ ๋ www.acmicpc.net ์ฝ๋ #include #include #define ll long long using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); ll n, w; cin>>n>>w; ll coin = 0; vectorv(n+1); for(int i=0; i>v[i]; for(int i=0; i 2022. 8. 18. [๋ฐฑ์ค,c++] 11437๋ฒ - LCA ๋ฌธ์ 11437๋ฒ: LCA ์ฒซ์งธ ์ค์ ๋ ธ๋์ ๊ฐ์ N์ด ์ฃผ์ด์ง๊ณ , ๋ค์ N-1๊ฐ ์ค์๋ ํธ๋ฆฌ ์์์ ์ฐ๊ฒฐ๋ ๋ ์ ์ ์ด ์ฃผ์ด์ง๋ค. ๊ทธ ๋ค์ ์ค์๋ ๊ฐ์ฅ ๊ฐ๊น์ด ๊ณตํต ์กฐ์์ ์๊ณ ์ถ์ ์์ ๊ฐ์ M์ด ์ฃผ์ด์ง๊ณ , ๋ค์ M๊ฐ ์ค์๋ ์ www.acmicpc.net ์ฝ๋ #include #include using namespace std; int N, M; vectorgraph[50001]; int depth[50001]; int parent[50001]; bool visited[50001]; void dfs(int node, int _depth){ visited[node] = 1; depth[node] = _depth; for(auto next: graph[node]){ if(!visited[next]){ par.. 2022. 8. 17. [๋ฐฑ์ค,c++] 15900๋ฒ - ๋๋ฌด ํ์ถ ๋ฌธ์ 15900๋ฒ: ๋๋ฌด ํ์ถ ํ์์ ์ฌ์ด๊ฐ ์ข์ง ์๋ ์ฑ์์ด์ ํ์์ด๊ฐ ๋๋์ด ์ ๋๋ก ํ ํ ๋ถ์ผ๋ ค๊ณ ํ๋ค. ์ฑ์์ด์ ํ์์ด ๋๊ณผ ๋ชจ๋ ๋๊ฐ์ด ์นํ ์ธ์ญ์ด๊ฐ ๋๊ฒฐ ์ข ๋ชฉ์ ์ ํด ๊ฐ์ ธ์๋ค. ๋ฐ๋ก '๋๋ฌด ํ์ถ' ์ด๋ผ๋ ๋ณด๋๊ฒ www.acmicpc.net ์ฝ๋ #include #include using namespace std; int N; vectorgraph[500001]; bool visited[500001]; int odd_height_cnt; void dfs(int node, int depth){ if(graph[node].size()==1 && node != 1){ // ๋ฆฌํ๋ ธ๋์ผ ๋ if(depth&1) odd_height_cnt++; return; } visited[node] = 1; for(a.. 2022. 8. 15. [๋ฐฑ์ค,c++] 1595๋ฒ - ๋ถ์ชฝ๋๋ผ์ ๋๋ก ๋ฌธ์ 1595๋ฒ: ๋ถ์ชฝ๋๋ผ์ ๋๋ก ์ ๋ ฅ์ ์ฌ๋ฌ์ค์ ๊ฑธ์ณ ์ฃผ์ด์ง๋ค. ์ ๋ ฅ์ ๊ฐ ์ค์ ์ธ ๊ฐ์ ์์ ์ ์๋ก ๊ตฌ์ฑ๋์ด์๋๋ฐ, ๊ฐ๊ฐ์ ์ฐจ๋ก๋๋ก ์๋ก ๋ค๋ฅธ ๋ ๋์์ ๋ฒํธ์ ๋ ๋์๋ฅผ ์ฐ๊ฒฐํ๋ ๋๋ก์ ๊ธธ์ด๋ฅผ ์๋ฏธํ๋ค. ๋ชจ๋ ๋๋ก๋ www.acmicpc.net ์ฝ๋ #include #include #include using namespace std; vectorgraph[10001]; bool visited[10001]; int max_cost, max_node; void dfs(int node, int cost){ if(cost>max_cost){ max_cost = cost; max_node = node; } visited[node] = 1; for(auto next: graph[node]){ if(!visit.. 2022. 8. 15. [๋ฐฑ์ค,c++] 14267๋ฒ - ํ์ฌ ๋ฌธํ1 ๋ฌธ์ 14267๋ฒ: ํ์ฌ ๋ฌธํ 1 ์์ ํ์ฌ์๋ ๋งค์ฐ ์ข์ ๋ฌธํ๊ฐ ์๋๋ฐ, ๋ฐ๋ก ์์ฌ๊ฐ ์ง์ ๋ถํ๋ฅผ ์นญ์ฐฌํ๋ฉด ๊ทธ ๋ถํ๊ฐ ๋ถํ์ ์ง์ ๋ถํ๋ฅผ ์ฐ์์ ์ผ๋ก ์นญ์ฐฌํ๋ ๋ด๋ฆฌ ์นญ์ฐฌ์ด ์๋ค. ์ฆ, ์์ฌ๊ฐ ํ ์ง์ ๋ถํ๋ฅผ ์นญ์ฐฌํ๋ฉด ๊ทธ ๋ถํ www.acmicpc.net ์ฝ๋ #include #include using namespace std; vectorgraph[100001]; int point[100001]; void add_point(int node, int _point){ point[node] += _point; for(auto next: graph[node]){ add_point(next, point[node]); } } int main(){ ios_base::sync_with_stdio(false); cin.t.. 2022. 8. 15. [๋ฐฑ์ค,c++] 19542๋ฒ - ์ ๋จ์ง ๋๋ฆฌ๊ธฐ ๋ฌธ์ 19542๋ฒ: ์ ๋จ์ง ๋๋ฆฌ๊ธฐ ํ๋ฏผ์ด๋ ํธ๋ฆฌ ๋ชจ์์ ๊ธธ ์์์ ์คํ ๋ฐ์ด๋ฅผ ํ๊ณ ์ ๋จ์ง๋ฅผ ๋๋ฆฌ๋ ค๊ณ ํ๋ค. ํ๋ฏผ์ด์ ๋ชฉํ๋ ์ผ๋์ํํธ์์ ์ถ๋ฐํ์ฌ ๋ชจ๋ ๋ ธ๋์ ์ ๋จ์ง๋ฅผ ๋๋ฆฌ๊ณ , ๋ค์ ์ผ๋์ํํธ๋ก ๋์์ค๋ ๊ฒ์ด๋ค. ํ๋ฏผ www.acmicpc.net ์ฝ๋ #include #include #include using namespace std; vectorgraph[100001]; int depth[100001]; int N, S, D, ans = 0; int dfs(int node, int before){ for(auto next: graph[node]){ if(next != before){ depth[node] = max(depth[node], dfs(next, node)+1); // ๊ฐ ๋ ธ๋์ ๊น์ด ์์๋ค .. 2022. 8. 14. [๋ฐฑ์ค,c++] 2250๋ฒ - ํธ๋ฆฌ์ ๋์ด์ ๋๋น ๋ฌธ์ 2250๋ฒ: ํธ๋ฆฌ์ ๋์ด์ ๋๋น ์ฒซ์งธ ์ค์ ๋ ธ๋์ ๊ฐ์๋ฅผ ๋ํ๋ด๋ ์ ์ N(1 ≤ N ≤ 10,000)์ด ์ฃผ์ด์ง๋ค. ๋ค์ N๊ฐ์ ์ค์๋ ๊ฐ ์ค๋ง๋ค ๋ ธ๋ ๋ฒํธ์ ํด๋น ๋ ธ๋์ ์ผ์ชฝ ์์ ๋ ธ๋์ ์ค๋ฅธ์ชฝ ์์ ๋ ธ๋์ ๋ฒํธ๊ฐ ์์๋๋ก ์ฃผ์ด์ง๋ค. www.acmicpc.net ์ฝ๋ #include #include #include #include using namespace std; vectorgraph[10001]; unordered_map cnt; vector height_arr[10001]; int N, root; int col[10001]; int seq = 1; int height = 1; void inorder(int node){ for(auto next: graph[node]){ if(next.fir.. 2022. 8. 14. [๋ฐฑ์ค,c++] 19637๋ฒ - IF๋ฌธ ์ข ๋์ ์จ์ค ๋ฌธ์ 19637๋ฒ: IF๋ฌธ ์ข ๋์ ์จ์ค ์ฒซ ๋ฒ์งธ ์ค์๋ ์นญํธ์ ๊ฐ์ N (1 ≤ N ≤ 105)๊ณผ ์นญํธ๋ฅผ ์ถ๋ ฅํด์ผ ํ๋ ์บ๋ฆญํฐ๋ค์ ๊ฐ์ M (1 ≤ M ≤ 105)์ด ๋น์นธ์ ์ฌ์ด์ ๋๊ณ ์ฃผ์ด์ง๋ค. (1 ≤ N, M ≤ 105) ๋ ๋ฒ์งธ ์ค๋ถํฐ N๊ฐ์ ์ค์ ๊ฐ ์นญ www.acmicpc.net ์ฝ๋ #include #include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int N, M; cin>>N>>M; multimap m; for(int i=0; i>a>>b; m.insert({b,a}); } for(int i=0; i>inp; coutsecond 2022. 8. 2. ์ด์ 1 ยทยทยท 5 6 7 8 9 10 11 ยทยทยท 51 ๋ค์