Notice
Recent Posts
Recent Comments
Link
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Archives
Today
Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Lennon FE

[๋ฐฑ์ค€ 16917๋ฒˆ] ์–‘๋… ๋ฐ˜ ํ›„๋ผ์ด๋“œ ๋ฐ˜ - ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(nodejs) ๋ณธ๋ฌธ

๐Ÿ”ฅ Algorithm/Baekjoon

[๋ฐฑ์ค€ 16917๋ฒˆ] ์–‘๋… ๋ฐ˜ ํ›„๋ผ์ด๋“œ ๋ฐ˜ - ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(nodejs)

Lennon 2022. 1. 21. 18:01
728x90
๋ฐ˜์‘ํ˜•

https://www.acmicpc.net/problem/16917

 

16917๋ฒˆ: ์–‘๋… ๋ฐ˜ ํ›„๋ผ์ด๋“œ ๋ฐ˜

ํ˜„์ง„ ์น˜ํ‚จ์—์„œ ํŒ๋งคํ•˜๋Š” ์น˜ํ‚จ์€ ์–‘๋… ์น˜ํ‚จ, ํ›„๋ผ์ด๋“œ ์น˜ํ‚จ, ๋ฐ˜๋ฐ˜ ์น˜ํ‚จ์œผ๋กœ ์ด ์„ธ ์ข…๋ฅ˜์ด๋‹ค. ๋ฐ˜๋ฐ˜ ์น˜ํ‚จ์€ ์ ˆ๋ฐ˜์€ ์–‘๋… ์น˜ํ‚จ, ์ ˆ๋ฐ˜์€ ํ›„๋ผ์ด๋“œ ์น˜ํ‚จ์œผ๋กœ ์ด๋ฃจ์–ด์ ธ์žˆ๋‹ค. ์–‘๋… ์น˜ํ‚จ ํ•œ ๋งˆ๋ฆฌ์˜ ๊ฐ€๊ฒฉ์€

www.acmicpc.net

const fs = require('fs');
let input = fs
  .readFileSync('dev/stdin')
  .toString()
  .trim()
  .split(' ')
  .map((v) => +v);

let [seasoning, fried, half, seasoningCount, friedCount] = input;
let answer = 0;
let min = Math.min(seasoningCount, friedCount);
if (seasoning + fried > half * 2) {
  answer += min * half * 2;
  seasoningCount -= min;
  friedCount -= min;

  if (seasoningCount !== 0) {
    if (seasoning > half * 2) {
      answer += half * 2 * seasoningCount;
    } else {
      answer += seasoning * seasoningCount;
    }
  }
  if (friedCount !== 0) {
    if (fried > half * 2) {
      answer += half * 2 * friedCount;
    } else {
      answer += fried * friedCount;
    }
  }
} else {
  answer += seasoningCount * seasoning;
  answer += friedCount * fried;
}

console.log(answer);

๋ธŒ๋ฃจํŠธํฌ์Šค ๋ฌธ์ œ์ด๋‹ค.

์šฐ์„  (์–‘๋…๋ฐ˜+ํ›„๋ผ์ด๋“œ๋ฐ˜) * 2 ์™€ ์–‘๋…1 + ํ›„๋ผ์ด๋“œ1 ์˜ ๊ฐ’์„ ๋จผ์ € ๋น„๊ตํ•œ๋‹ค. 

์ „์ž๊ฐ€ ๋” ์‹ธ๋‹ค๋ฉด ์ตœ์†Œ ์–‘๋… ํ›„๋ผ์ด๋“œ ๊ฐœ์ˆ˜์—์„œ ์ž‘์€ ๊ฐœ์ˆ˜ ๋งŒํผ ๋ฐ˜๋ณตํ•ด ๊ฐ€๊ฒฉ์„ ๋”ํ•ด์ค€๋‹ค.

๊ทธ ํ›„ (์–‘๋…๋ฐ˜+ํ›„๋ผ์ด๋“œ๋ฐ˜) * 2์˜ ๊ฐ€๊ฒฉ์ด ์–‘๋…1 ๋ณด๋‹ค ์‹ผ ์ง€ ํ™•์ธํ•œ๋‹ค. ์ตœ์†Œ ๊ฐœ์ˆ˜์ด๋ฏ€๋กœ ๊ฐœ์ˆ˜๊ฐ€ ๋„˜์–ด๋„ ์ƒ๊ด€์—†๋‹ค.

์‹ธ๋‹ค๋ฉด ๋ฐ˜๋ฐ˜์œผ๋กœ ๋‚˜๋จธ์ง€ ๊ฐœ์ˆ˜๋ฅผ ์ฑ„์šฐ๊ณ  ํ›„๋ผ์ด๋“œ๋„ ๋˜‘๊ฐ™์ด ํ•ด์ค€๋‹ค.

 

(์–‘๋…๋ฐ˜+ํ›„๋ผ์ด๋“œ๋ฐ˜) * 2 ์™€ ์–‘๋…1 + ํ›„๋ผ์ด๋“œ1์—์„œ ํ›„์ž๊ฐ€ ์‹ธ๋‹ค๋ฉด ๊ทธ๋ƒฅ ์ตœ์†Œ ๊ฐœ์ˆ˜๋งŒํผ ๊ฐ๊ฐ ๊ณฑํ•ด์ฃผ๋ฉด ๋๋‚œ๋‹ค.

 

์ด ๋ฌธ์ œ์˜ ํ•ต์‹ฌ์€ (์–‘๋…๋ฐ˜+ํ›„๋ผ์ด๋“œ๋ฐ˜) * 2์˜ ๊ฐ€๊ฒฉ์ด ์–‘๋…1 or ํ›„๋ผ์ด๋“œ1๋ณด๋‹ค ์‹ผ ์ง€ ํ™•์ธํ•˜๋Š” ๊ฒƒ์ด์˜€๋‹ค. 

 

728x90
๋ฐ˜์‘ํ˜•
Comments