This problem can be easily solved if you can visualize the geometric structure of a cube. Perhaps that’s why its difficulty level is quite low. The difficulty is Silver III. While it is harder than Bronze-level problems, it’s not too difficult.
As of now, the correct answer rate is 22.6%, which is quite low, and there are 531 correct submissions.
The goal of the problem is to calculate the minimum possible sum of the visible faces when dice are arranged to form a cube of size \(N \times N \times N\), using standard 6-sided dice. Each edge of the cube consists of N dice.
I approached the problem by dividing it into two cases: when N = 1 and when \(N \geq 2\).
• For N = 1, since five faces of the die are visible, you can place the largest number on the bottom, which will be hidden.
• For \(N \geq 2\), you can organize the solution using a specific table of values.
Once you derive this table, the problem becomes much more manageable. The reason I separated the N = 1 case is that the table only applies when \(N \geq 2\).
visible dice faces | number of dices |
3 | 4 |
2 | \(8N-12\) |
1 | \(5N^2 -16N + 12\) |
Here are the answers for several input values.
Input1:
1
1 2 3 4 5 6
15
Input2:
2
1 3 5 7 9 11
52
Input3:
987654
31 33 35 37 39 41
151196381478444
Note: Since the input numbers can be large, you should use the long long data type.
There aren’t many exceptional cases to handle.
The following is the source code I wrote. Please use it for reference only.
//----------------------------------------------------------
// baekjoon #1041 - Dice
// - by Aubrey Choi
// - created at 2019-12-06
//----------------------------------------------------------
#include <stdio.h>
int main()
{
int n, v[6], i, j, sum=0, max=0, min=200, min2=200, min3=200;
scanf("%d",&n);
for(i=0;i<6;i++) scanf("%d",v+i);
for(i=0;i<6;i++) sum+=v[i], max=v[i]>max?v[i]:max, min=v[i]<min?v[i]:min;
if(n==1) { printf("%d\n", sum-max); return 0; }
int p3[8][3] = { 0,1,2, 0,2,4, 0,3,4, 0,1,3, 1,2,5, 1,3,5, 2,4,5, 3,4,5 };
int p2[12][2] = { 0,1, 0,2, 0,3, 0,4, 1,2, 1,3, 1,5, 2,4, 2,5, 3,4, 3,5, 4,5 };
for(i=0;i<8;i++)
{
for(j=0,sum=0;j<3;j++) sum+=v[p3[i][j]];
if(sum<min3) min3=sum;
}
for(i=0;i<12;i++)
{
for(j=0,sum=0;j<2;j++) sum+=v[p2[i][j]];
if(sum<min2) min2=sum;
}
printf("%lld\n", 4*min3+(8LL*n-12)*min2+(5LL*n*n-16*n+12)*min);
}
'Programming > BOJ' 카테고리의 다른 글
[C/C++] BOJ #1038 - Decreasing Number (0) | 2025.04.03 |
---|---|
[C/C++] BOJ #1037 - Divisors (0) | 2025.03.13 |
[C/C++] BOJ #1036 - Base 36 (0) | 2025.02.17 |
[C/C++] BOJ #1032 - Command Prompt (0) | 2025.02.11 |
[C/C++] BOJ #1026 - Treasure (0) | 2025.02.04 |