-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
214 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <iostream> | ||
#include <vector> | ||
using namespace std; | ||
|
||
bool check(vector <int>& v, int n, long long length); | ||
int binary_serach(vector <int>& v, int n); | ||
|
||
int main() { | ||
int k, n; | ||
cin >> k >> n; | ||
vector <int> v(k); | ||
for (auto& i : v) { | ||
cin >> i; | ||
} | ||
cout << binary_serach(v, n); | ||
return 0; | ||
} | ||
|
||
bool check(vector <int>& v, int n, long long length) { | ||
int cnt = 0; | ||
for (const auto& i : v) { | ||
cnt += i / length; | ||
} | ||
return cnt >= n; | ||
} | ||
|
||
int binary_serach(vector <int>& v, int n) { | ||
long long lo = 1, hi = 2147483648; //μλ₯Ό μ μλ λμ μ λ²μ | ||
while (lo + 1 < hi) { | ||
long long mid = (lo + hi) / 2; | ||
if (check(v, n, mid)) lo = mid; | ||
else hi = mid; | ||
} | ||
return lo; | ||
} |
File renamed without changes.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import heapq | ||
import sys | ||
|
||
n = int(sys.stdin.readline()) | ||
|
||
heap = [] # λͺ¨λ κ°μμ μμ μκ°κ³Ό μ’ λ£ μκ°μ μ μ₯ν μ΅μ ν | ||
q = [] # νμ¬ μ¬μ© μ€μΈ κ°μμ€μ μ’ λ£ μκ°μ μ μ₯ν μ΅μ ν | ||
|
||
# μ£Όμ΄μ§ κ°μ μλ§νΌ λ°λ³΅νλ©΄μ κ°μ μ 보λ₯Ό μ λ ₯λ°μ μ΅μ νμ μ μ₯ | ||
for _ in range(n): | ||
num, start, end = map(int, sys.stdin.readline().split()) | ||
heapq.heappush(heap, [start, end, num]) | ||
|
||
# 첫 λ²μ§Έ κ°μλ₯Ό μ΅μ νμμ κΊΌλ΄μ ν΄λΉ κ°μμ μ’ λ£ μκ°μ λ€λ₯Έ νμ μ μ₯ | ||
start, end, num = heapq.heappop(heap) | ||
heapq.heappush(q, end) | ||
|
||
while heap: | ||
start, end, num = heapq.heappop(heap) | ||
# κ°μ₯ 빨리 λλλ κ°μμ€μ μ’ λ£ μκ°μ΄ νμ¬ κ°μμ μμ μκ°λ³΄λ€ μκ±°λ κ°μΌλ©΄ μ’ λ£ μκ°μ μ΅μ νμμ μ κ±° | ||
if q[0] <= start: | ||
heapq.heappop(q) | ||
heapq.heappush(q, end) # νμ¬ κ°μμ μ’ λ£ μκ°μ μ΅μ νμ μΆκ° | ||
|
||
print(len(q)) # μ΅μ ν qμ ν¬κΈ°κ° νμν κ°μμ€μ μ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
//14502 : μ°κ΅¬μ | ||
|
||
#include <iostream> | ||
#include <vector> | ||
#include <queue> | ||
#include <algorithm> | ||
using namespace std; | ||
|
||
// λ©ν¬λ‘ μ€μ | ||
#define BLANK 0 | ||
#define WALL 1 | ||
#define VIRUS 2 | ||
|
||
int N, M; // μ§λμ μΈλ‘ ν¬κΈ°, κ°λ‘ ν¬κΈ° | ||
vector<vector<int>> initial_map; // μ΄κΈ° μ§λ | ||
vector<pair<int, int>> blank_map; // λΉ μΉΈ | ||
int directions[4][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} }; // λ°©ν₯ | ||
|
||
// κ°λ₯ν λͺ¨λ λ²½ μΈμ°κΈ° μ‘°ν© κ΅¬νκΈ° | ||
vector<vector<pair<int, int>>> building_walls() { | ||
vector<vector<pair<int, int>>> combinations; | ||
int size = blank_map.size(); // λΉ μΉΈ ν¬κΈ° | ||
for (int i = 0; i < size; i++) { | ||
for (int j = i + 1; j < size; j++) { | ||
for (int k = j + 1; k < size; k++) { | ||
// λΉ μΉΈμ λ²½ 3κ° μΈμ°κΈ° | ||
combinations.push_back({blank_map[i], blank_map[j], blank_map[k]}); | ||
} | ||
} | ||
} | ||
return combinations; | ||
} | ||
|
||
// λλΉ μ°μ νμ(λ°μ΄λ¬μ€μΈ μΉΈ νμ μ μ₯ ν, | ||
// λ°μ΄λ¬μ€ μΉΈ μ£Όλ³ μΉΈμ΄ λ°μ΄λ¬μ€ μλ λΉ μΉΈμ΄λΌλ©΄, | ||
// μ£Όλ³ μΉΈμ λ°μ΄λ¬μ€λ‘ λ°κΎΈκΈ°) | ||
void bfs(vector<vector<int>>& map_copy) { | ||
queue<pair<int, int>> q; | ||
for (int i = 0; i < N; i++) { | ||
for (int j = 0; j < M; j++) { | ||
if (map_copy[i][j] == VIRUS) { | ||
q.push({i, j}); | ||
} | ||
} | ||
} | ||
// λ°μ΄λ¬μ€μΈ μΉΈμ΄ μλκ³ λΉ μΉΈμ΄λΌλ©΄, | ||
while (!q.empty()) { | ||
int x = q.front().first; | ||
int y = q.front().second; | ||
q.pop(); | ||
for (int d = 0; d < 4; d++) { // λ°©ν₯ νμ | ||
int nx = x + directions[d][0]; | ||
int ny = y + directions[d][1]; | ||
if (nx >= 0 && nx < N && ny >= 0 && ny < M && map_copy[nx][ny] == 0) { | ||
map_copy[nx][ny] = VIRUS; // λΉ μΉΈμ λ°μ΄λ¬μ€λ‘ λ°κΎΈκΈ° | ||
q.push({nx, ny}); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// μμ μμ ν¬κΈ° κ³μ° ν¨μ | ||
int calculate_safe_area(vector<vector<int>>& map_copy) { | ||
int safe_area = 0; | ||
for (int i = 0; i < N; i++) { | ||
for (int j = 0; j < M; j++) { | ||
if (map_copy[i][j] == BLANK) { // λΉ μΉΈμ κ°μ | ||
safe_area++; | ||
} | ||
} | ||
} | ||
return safe_area; | ||
} | ||
|
||
int main() { | ||
cin >> N >> M; | ||
initial_map.resize(N, vector<int>(M)); | ||
|
||
for (int i = 0; i < N; i++) { | ||
for (int j = 0; j < M; j++) { | ||
cin >> initial_map[i][j]; | ||
if (initial_map[i][j] == BLANK) { | ||
blank_map.push_back({ i, j }); // λΉ μΉΈ μ§λ μμ± | ||
} | ||
} | ||
} | ||
|
||
vector<vector<pair<int, int>>> wall_combinations = building_walls(); // λΉ μΉΈμ λ²½ μΈμ°κΈ° | ||
int max_safe_area = 0; // μμ μμμ μ΅λ ν¬κΈ° | ||
|
||
for (const auto& walls : wall_combinations) { // λ²½ 3κ°λ₯Ό μΈμ΄ μ¬λ¬ μ‘°ν© λ°λ³΅ | ||
// μ΄κΈ° 맡 볡μ¬ν΄μ κ·Έ 맡μ λ²½ 3κ° μΈμ°λ μ¬λ¬ μ‘°ν© μ€ ν κ²½μ° μ μ© | ||
vector<vector<int>> map_copy = initial_map; | ||
for (const auto& wall : walls) { // ν κ²½μ°μμ μΈμ΄ λ²½ 3κ°μ κ°κ° μμΉμ λ²½ μΈμ°κΈ° | ||
map_copy[wall.first][wall.second] = WALL; // λ²½ μΈμ°κΈ° | ||
} | ||
|
||
bfs(map_copy); // λ°μ΄λ¬μ€ μ£Όλ³ μΉΈ λΉ μΉΈμ΄λΌλ©΄ λ°μ΄λ¬μ€ λ²μ§ | ||
|
||
int safe_area = calculate_safe_area(map_copy); // μμ μμ ν¬κΈ° κ³μ° | ||
max_safe_area = max(max_safe_area, safe_area); | ||
} | ||
|
||
cout << max_safe_area << endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# 11404 : νλ‘μ΄λ | ||
import sys | ||
|
||
input = sys.stdin.readline | ||
INF = float('inf') # μ΅λκ° μ μ | ||
|
||
# λ Έλμ κ°μ(n)κ³Ό κ°μ μ κ°μ(m) μ λ ₯ | ||
n = int(input()) # λμμ κ°μ n | ||
m = int(input()) # λ²μ€μ κ°μ m | ||
|
||
# 2μ°¨μ 리μ€νΈ (κ·Έλν νν) λ§λ€κ³ , 무νλλ‘ μ΄κΈ°ν(νλ‘μ΄λ-μμ = μ΄μ°¨μ λ°°μ΄) | ||
graph = [[INF] * (n + 1) for _ in range(n + 1)] | ||
|
||
# iμμ jλ‘ κ° μ μλ κ²½μ°, | ||
# μκΈ° μμ μμ μκΈ° μμ μΌλ‘ κ°λ λΉμ©μ 0μΌλ‘ μ΄κΈ°ν(λκ°μ μ ν΄λΉνλ λΆλΆ)) | ||
for i in range(1, n + 1): | ||
for j in range(1, n + 1): | ||
if i == j: | ||
graph[i][j] = 0 | ||
|
||
# κ° κ°μ μ λν μ 보λ₯Ό μ λ ₯λ°μ, κ·Έ κ°μΌλ‘ μ΄κΈ°ν | ||
for _ in range(m): | ||
# A -> Bλ‘ κ°λ λΉμ©μ CλΌκ³ μ€μ | ||
i, j, cost = map(int, input().split()) | ||
if graph[i][j] > cost: # μμ λμμ λμ°© λμ μ°κ²°νλ λ Έμ νλκ° x | ||
graph[i][j] = cost | ||
|
||
# μ νμμ λ°λΌ νλ‘μ΄λ μμ μκ³ λ¦¬μ¦μ μν(3μ€ forλ¬Έ) | ||
for k in range(1, n + 1): | ||
for i in range(1, n + 1): | ||
for j in range(1, n + 1): | ||
graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]) | ||
|
||
# μνλ κ²°κ³Όλ₯Ό μΆλ ₯ | ||
for i in range(1, n + 1): | ||
for j in range(1, n + 1): | ||
if graph[i][j] == INF: | ||
print(0, end=' ') | ||
else: | ||
print(graph[i][j], end=' ') | ||
print() |