Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

34-gjsk132 #165

Merged
merged 2 commits into from
May 22, 2024
Merged

34-gjsk132 #165

merged 2 commits into from
May 22, 2024

Conversation

gjsk132
Copy link
Member

@gjsk132 gjsk132 commented May 6, 2024

πŸ”— 문제 링크

λ°±μ€€ 1041 : μ£Όμ‚¬μœ„

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

30λΆ„

✨ μˆ˜λ„ μ½”λ“œ

🎯 문제 이해

문제 μš”μ•½
μ•„λž˜ 이미지와 같이 μ£Όμ‚¬μœ„μ˜ 6면에 정해진 μˆ«μžκ°€ μžˆλ‹€.

μ•„λž˜μ™€ 같이 μ£Όμ‚¬μœ„λ₯Ό μ—¬λŸ¬ 개 μŒ“μ•„μ€€λ‹€.

μ΄λ•Œ, ν‘œλ©΄μ— μžˆλŠ” 숫자의 합이 μ΅œμ†Œκ°€ λ˜λŠ” κ°’

N이 μ£Όμ–΄μ§ˆ λ•Œ, 꼭짓점, λͺ¨μ„œλ¦¬, 면에 μ˜€λŠ” 값이 μ •ν•΄μ Έ μžˆλ‹€.
image
3면을 λ³΄μ΄λŠ” μ£Όμ‚¬μœ„λŠ” 항상 4개
2λ©΄ 이상 λ³΄μ΄λŠ” μ£Όμ‚¬μœ„λŠ” λͺ¨μ„œλ¦¬μ— μœ„μΉ˜ν•œ (λͺ¨μ„œλ¦¬κΈΈμ΄ -1) * 8
1λ©΄ 이상 λ³΄μ΄λŠ” μ£Όμ‚¬μœ„λŠ” ν‘œλ©΄μ— λ‚˜μ™€μžˆλŠ” μ£Όμ‚¬μœ„ μˆ˜μ™€ κ°™λ‹€.
( λ³΄μ΄λŠ” λͺ¨λ“  λ©΄μ—μ„œ, 2λ©΄ 이상 λ³΄μ΄λŠ” μ£Όμ‚¬μœ„ μˆ˜μ™€ 3λ©΄ 이상 λ³΄μ΄λŠ” μ£Όμ‚¬μœ„μ˜ 수λ₯Ό λΉΌλ©΄ λœλ‹€. )

μ£Όμ‚¬μœ„λŠ” μ΅œλŒ€ 3λ©΄κΉŒμ§€ λ³΄μ΄λ―€λ‘œ ν‘œλ©΄μ— 보일 3개의 숫자λ₯Ό μ •ν•΄μ•Όν•œλ‹€.

μ—¬κΈ°μ„œ μ£Όμ˜ν•  점은 λ§ˆμ£Όλ³΄λŠ” λ©΄μ—μ„œ 1κ°œμ”© 골라야 ν•œλ‹€.
μ£Όμ‚¬μœ„λ₯Ό λ†“μœΌλ©΄, λ§ˆμ£Όλ³΄λŠ” λ©΄ μ€‘μ—μ„œ ν•œ 면은 λͺ» 보기 λ•Œλ¬Έμ΄λ‹€.

이λ₯Ό κ΅¬ν•˜κΈ° μœ„ν•΄ λ§ˆμ£Όλ³΄λŠ” 면끼리 λ¬ΆμœΌλ©΄μ„œ μ˜€λ¦„μ°¨μˆœ μ •λ ¬ν•˜κ³ , λ¬ΆμŒμ„ μž‘μ€ μˆ˜λŠ” μž‘μ„μˆ˜λ‘, λ§Œμ•½ μž‘μ€ μˆ˜κ°€ κ°™λ‹€λ©΄ 큰 μˆ˜κ°€ 클수둝 λ¨Όμ € μ‚¬μš©ν•˜λ„λ‘ 정렬을 ν•΄μ€€λ‹€. ( 큰 수λ₯Ό 가지고 μžˆλŠ” μŒμ„ λ¨Όμ € μ‚¬μš©ν•˜κΈ° μœ„ν•΄μ„œμ΄λ‹€. )

또 ν•˜λ‚˜ 더 μœ μ˜ν•  점은, 1x1x1을 λ§Œλ“€ λ•Œμ΄λ‹€. μ‰½κ²Œ 말해 μ£Όμ‚¬μœ„κ°€ 1개 μžˆμ„ λ•Œμ—λŠ” κ°€μž₯ 큰 수λ₯Ό μ œμ™Έν•œ λ‚˜λ¨Έμ§€ 숫자λ₯Ό ν•©ν•΄μ•Ό ν•œλ‹€.

πŸ”μ½”λ“œ μ„€λͺ…

size : μ£Όμ‚¬μœ„λ₯Ό μŒ“μ„ 크기
dice_nums : μ£Όμ‚¬μœ„μ˜ 각 면에 쓰일 숫자
find_dice_sum() : μ£Όμ‚¬μœ„λ₯Ό 1보닀 많이 μŒ“μ„ λ•Œ, ν‘œλ©΄ 숫자의 μ΅œμ†Œ 합을 κ΅¬ν•΄μ£ΌλŠ” ν•¨μˆ˜
dice_sets : μ£Όμ‚¬μœ„λ₯Ό λ§ˆμ£Όλ³΄λŠ” 면끼리 λ¬Άμ–΄ μ •λ ¬ν•˜λŠ” 리슀트
vertex : 꼭짓점 면의 수
corner : λͺ¨μ„œλ¦¬ 면의 수
surface : ν‘œλ©΄μ˜ 면의 수

μš°μ„  주어진 μž…λ ₯값을 λ°›μ•„μ€€λ‹€.

size = int(input())
dice_nums = list(map(int,input().split()))

λ§Œμ•½ sizeκ°€ 1이라면, κ°€μž₯ 큰 수λ₯Ό μ œμ™Έν•œ ν‘œλ©΄ 수의 총합을 좜λ ₯ν•˜κ³ ,
1보닀 큰 수라면, find_dice_set()ν•¨μˆ˜λ₯Ό μ‹€ν–‰ν•œλ‹€.

if size == 1:
    print(sum(dice_nums)-max(dice_nums))
else:
    print(find_dice_sum())

find_dice_set()ν•¨μˆ˜μ—μ„œλŠ” 일단 λ§ˆμ£Όλ³΄λŠ” 면끼리 μ •λ ¬ν•˜μ—¬ λ¬Άκ³ ,
λ§ˆμ£Όλ³΄λŠ” λ©΄μ—μ„œ μž‘μ€ μˆ˜λŠ” μž‘μ„μˆ˜λ‘, 큰 μˆ˜λŠ” 클수둝 μ•žμ— μ˜€λ„λ‘ μ •λ ¬ν•œλ‹€.
( λ§ˆμ£Όλ³΄λŠ” 면의 인덱슀의 합이 2둜 κ· μΌν•˜μ—¬ μ•„λž˜μ™€ 같이 μ½”λ“œλ₯Ό μž‘μ„± )

def find_dice_sum():
    dice_sets = [sorted([dice_nums[2-i], dice_nums[3+i]])for i in range(3)]
    dice_sets = sorted(dice_sets, key=lambda x : x[1], reverse = True) #reverseλŠ” λ°˜λŒ€λ‘œ μ •λ ¬ν•œ 것이닀.
    dice_sets = sorted(dice_sets, key=lambda x : x[0])

sizeλ₯Ό ν†΅ν•˜μ—¬ vertex, cormer, surface에 ν•΄λ‹Ήν•˜λŠ” 면이 λͺ‡ κ°œμΈμ§€ μ •μ˜ν•œλ‹€.

    vertex = 4
    corner = (size-1)*8
    surface = pow(size, 2)*5 - corner - vertex 

κ°€μž₯ λ§Žμ€ surface, cormer, vertex 순으둜 κ°€μž₯ μž‘μ€ 값을 κ³±ν•΄μ„œ 총합을 κ΅¬ν•œλ’€ returnν•΄μ€€λ‹€.

    return dice_sets[0][0]*surface + dice_sets[1][0]*corner + dice_sets[2][0]*vertex
전체 μ½”λ“œ
input = open(0).readline

size = int(input())
dice_nums = list(map(int,input().split()))

def find_dice_sum():
    dice_sets = [sorted([dice_nums[2-i], dice_nums[3+i]])for i in range(3)]
    dice_sets = sorted(dice_sets, key=lambda x : x[1], reverse = True)
    dice_sets = sorted(dice_sets, key=lambda x : x[0])

    vertex = 4
    corner = (size-1)*8
    surface = pow(size, 2)*5 - corner - vertex 

    return dice_sets[0][0]*surface + dice_sets[1][0]*corner + dice_sets[2][0]*vertex

if size == 1:
    print(sum(dice_nums)-max(dice_nums))
else:
    print(find_dice_sum())

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

Copy link
Collaborator

@9kyo-hwang 9kyo-hwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이게 λŒ€μ²΄ λ­” λ¬Έμ œμ§€.... ν•˜κ³  ν•œμ°Έ 생각해닀가 PR 보고 겨우 μ΄ν•΄ν–ˆλ„€μš” γ…‹γ…‹
κ²°κ΅­ μ •μœ‘λ©΄μ²΄λ₯Ό λ§Œλ“€λ©΄

  • ν•œ 면이 λ³΄μ΄λŠ” μ£Όμ‚¬μœ„
  • 두 면이 λ³΄μ΄λŠ” μ£Όμ‚¬μœ„
  • μ„Έ 면이 λ³΄μ΄λŠ” μ£Όμ‚¬μœ„

μ΄λ ‡κ²Œ 3μ’…λ₯˜κ°€ μ‘΄μž¬ν•˜λ―€λ‘œ, μ„Έ 면이 λ³΄μ΄λŠ” μ£Όμ‚¬μœ„μ˜ (개수 * μ΅œμ†Œ 눈 μ‘°ν•©) + 두 면이 λ³΄μ΄λŠ” μ£Όμ‚¬μœ„μ˜ (개수 * μ΅œμ†Œ 눈 μ‘°ν•©) + ν•œ 면이 λ³΄μ΄λŠ” μ£Όμ‚¬μœ„μ˜ (개수 * μ΅œμ†Œ 눈 μ‘°ν•©)을 μ°ΎλŠ” κ±°μ˜€λ„€μš”...

그리고 두 λ©΄/μ„Έ 면이 λ³΄μ΄λŠ” μ£Όμ‚¬μœ„μ˜ 경우 "λ§ˆμ£Όλ³΄λŠ” λ©΄"에 λŒ€ν•œ μ˜ˆμ™Έ 처리λ₯Ό μž‘μ•„μ£Όλ©΄ λ˜λŠ” κ±°μ˜€κ΅¬μš”.

λ­”κ°€ 되게 μˆ˜ν•™μŠ€λŸ¬μš΄λ° 그리디 관점이 μ ‘λͺ©λœ λŠλ‚Œμ΄λ„€μš”...

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main()
{
    cin.tie(nullptr)->sync_with_stdio(false);
    
    int64_t N; cin >> N;
    vector<int> Dice(6, 0);
    for(int& Pip : Dice)
    {
        cin >> Pip;
    }
    
    int SumPip = reduce(Dice.begin(), Dice.end(), 0);
    int MaxPip = *max_element(Dice.begin(), Dice.end());

    if(N == 1)
    {
        cout << SumPip - MaxPip;
        return 0;
    }
    
    int Min1D = *min_element(Dice.begin(), Dice.end()), Min2D = 101, Min3D = 151;
    for(int i = 0; i < 6; ++i)
    {
        for(int j = i + 1; j < 6; ++j)
        {
            if(i + j == 5)  // λ§ˆμ£Όλ³΄λŠ” 면은 두 면은 λ™μ‹œμ— 보일 수 μ—†μŒ
            {
                continue;
            }
            
            Min2D = min(Min2D, Dice[i] + Dice[j]);
            
            for(int k = j + 1; k < 6; ++k)
            {
                if(i + k == 5 || j + k == 5)  // λ§ˆμ£Όλ³΄λŠ” 면은 두 면은 λ™μ‹œμ— 보일 수 μ—†μŒ
                {
                    continue;
                }
                
                Min3D = min(Min3D, Dice[i] + Dice[j] + Dice[k]);
            }
        }
    }
    
    int64_t Answer = 0;
    Answer += 4 * Min3D;
    Answer += (8 * N - 12) * Min2D;
    Answer += (5 * N * N - 16 * N + 12) * Min1D;
    cout << Answer;
    
    return 0;
}

Copy link
Member

@xxubin04 xxubin04 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ œκ°€ μ—„μ²­ λ³΅μž‘ν•˜κ²Œ ν’€λ €κ³  ν–ˆλ˜ 것 κ°™λ„€μš”...
μ €λŠ” 3λ©΄, 2λ©΄, 1면이 λ³΄μ΄λŠ” μ£Όμ‚¬μœ„ 개수λ₯Ό κ΅¬ν•˜λŠ” 곡식을 λ„μΆœν•΄μ„œ ν’€λ €κ³  ν–ˆλŠ”λ°, λ­”κ°€ 쀑간에 였λ₯˜κ°€ μžˆλŠ” 것 κ°™μŠ΅λ‹ˆλ‹€..
λ‚˜μ€‘μ— κ³ μΉ  수 μžˆμ§€ μ•Šμ„κΉŒ ν•˜μ—¬ 계속 미루닀가 μ΄μ œμ„œμ•Ό λ¦¬λ·°ν•˜κ²Œ λ˜μ—ˆλ„€μš©..πŸ§ŽπŸ»β€β™€οΈ

참고사진

image

ν‹€λ Έμ§€λ§Œ ν˜Ήμ‹œλ‚˜ ν•˜μ—¬ μ˜¬λ¦¬λŠ” μ½”λ“œ..!
input = open(0).readline

n = int(input())
num = list(map(int, input().split()))
dice = []

for i in enumerate(num):
    dice.append(i)

select = []
if dice[2][1] > dice[3][1]:
    select.append(dice.pop(3)[1])
    dice.pop(2)
else:
    select.append(dice.pop(2)[1])
    dice.pop(3)
dice.sort(key=lambda x: x[1])
select.append((a := dice.pop(0))[1])
for j in range(3):
    if a[0] == 1 and dice[j][0] != 4:
        select.append(dice[j][1])
        break
    elif a[0] == 4 and dice[j][0] != 1:
        select.append(dice[j][1])
        break
    elif a[0] == 0 and dice[j][0] != 5:
        select.append(dice[j][1])
        break
    elif a[0] == 5 and dice[j][0] != 0:
        select.append(dice[j][1])
        break

select.sort()
min_1 = select[0]
min_2 = select[1]
min_3 = select[2]
ans = 8 * (min_1 + min_2 + min_3) + 12 * (n - 2) * (min_1 + min_2) + 6 * (n - 2) ** 2 * min_1
ans -= (min_1 * (n - 2) ** 2 + min_2 * 4 * (n - 2) + min_3 * 4)
print(ans)

ν…ŒμΌ€λ“€μ€ 잘 ν†΅κ³Όν•˜μ§€λ§Œ, min_1, min_2, min_3으둜 κ΅¬ν•˜μ§€ μ•Šκ³  λ§ˆμ£Όλ³΄λŠ” 면을 κΈ°μ€€μœΌλ‘œ 풀도둝 ν•΄λ΄μ•Όκ² μŠ΅λ‹ˆλ‹€!!

@gjsk132 gjsk132 merged commit 232ec6a into main May 22, 2024
@gjsk132 gjsk132 deleted the 34-gjsk132 branch May 22, 2024 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants