Skip to content

Commit

Permalink
Merge pull request #3 from AlgoLeadMe/7-YIM2UL2ET
Browse files Browse the repository at this point in the history
1-YIM2UL2ET
  • Loading branch information
YIM2UL2ET authored Feb 14, 2024
2 parents b5fccbb + e00232b commit 765860f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion YIM2UL2ET/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

| ์ฐจ์‹œ | ๋‚ ์งœ | ๋ฌธ์ œ์œ ํ˜• | ๋งํฌ | ํ’€์ด |
|:----:|:---------:|:----:|:-----:|:----:|
| 1์ฐจ์‹œ | 2023.10.27 | BFS | - | - |
| 1์ฐจ์‹œ | 2023.10.27 | ๊ทธ๋ฆฌ๋”” | [BOJ 18310](https://www.acmicpc.net/problem/18310) | [BOJ 18310 ํ’€์ด](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/3) |
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <iostream>

int main(void)
{
int n, temp, index, result, up, down;
long long value, tvalue;
int villige[100000] = {0};

value = 0;
std::cin >> n;
for (int i = 0; i < n; i++) {
std::cin >> temp;
villige[temp-1]++;
value += temp-1;
}

result = 1, index = 0, up = n - villige[0], down = villige[0], tvalue = value;
// tvalue: ์ž„์‹œ value, up: ๋ด์•ผํ•  ์ง‘์˜ ์ˆ˜, down: ์ง€๊ธˆ๊นŒ์ง€ ๋ด์˜จ ์ง‘์˜ ์ˆ˜

for (int i = 1; i < 100000; i++) { // ๋งˆ์„ ๋Œ์•„๋ณด๊ธฐ
if (villige[i] == 0) continue; // i+1๋ฒˆ์งธ ์œ„์น˜์— ์ง‘์ด ์—†์œผ๋ฉด ๋‹ค์Œ ์œ„์น˜๋กœ ์ด๋™

tvalue += down * (i - index);
tvalue -= up * (i - index);
down += villige[i];
up -= villige[i];

if (tvalue < value) { // ์ง€๊ธˆ ๊ณ„์‚ฐํ•œ value๊ฐ€ ์ €์žฅํ–ˆ๋˜ value๋ณด๋‹ค ์ž‘์œผ๋ฉด
value = tvalue; // ์ง€๊ธˆ ๊ณ„์‚ฐํ•œ value๊ฐ’ ์ €์žฅ.
result = i+1; // ์ •๋‹ต์œผ๋กœ i+1๋ฒˆ์งธ ์œ„์น˜ ์ €์žฅ
}
index = i; // ์ตœ๊ทผ ๋ดค๋˜ ์ง‘์˜ ์œ„์น˜๋ฅผ ๊ธฐ์–ตํ•˜๊ธฐ
}

std::cout << result;
return 0;
}

0 comments on commit 765860f

Please sign in to comment.