코딩 테스트/BOJ

C# 1654 랜선 자르기(틀림)

s0002 2023. 1. 26. 02:49

아래 참고한 블로그랑 똑같이 작성한 것 같은데 계속 틀렸다고 나온다

처음에 int 타입으로 변수 정의한 것 때문에 오버플로우로 틀린 것 같아서

uint, long 다 해봤는데도 틀렸다고 나온다

체크 못한 부분이 있는 것 같다

using System;
using System.IO;
using System.Linq;

namespace _1654
{
    class Program
    {
        static void Main(string[] args)
        {
            StreamReader sr = new StreamReader(Console.OpenStandardInput());
            StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());

            int[] kn = Array.ConvertAll(sr.ReadLine().Split(' '),int.Parse);
            int k = kn[0];
            int n = kn[1];
            int[] length = new int[k];

            for (int i =0; i < k; i++)
                length[i] = int.Parse(sr.ReadLine());
               
            int start = 1;
            int end = length.Max();

            int[] quotient = new int[k];
            int quotientSum = 0;

            while(start<=end)
            {
                int mid = (start + end) / 2;
                quotientSum = 0;

                for (int j = 0; j < k; j++)
                {
                    quotient[j]=length[j] / mid;
                    quotientSum += quotient[j];
                }

                if (quotientSum >= n)
                    start=mid+1;
                else
                    end=mid-1;
            }
            sw.WriteLine(end);
        }
    }
}

참고

https://jjini-3-coding.tistory.com/11

 

[백준] 1654번 랜선 자르기 (파이썬)

1654번: 랜선 자르기 첫째 줄에는 오영식이 이미 가지고 있는 랜선의 개수 K, 그리고 필요한 랜선의 개수 N이 입력된다. K는 1이상 10,000이하의 정수이고, N은 1이상 1,000,000이하의 정수이다. 그리고

jjini-3-coding.tistory.com

 

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

 

1654번: 랜선 자르기

첫째 줄에는 오영식이 이미 가지고 있는 랜선의 개수 K, 그리고 필요한 랜선의 개수 N이 입력된다. K는 1이상 10,000이하의 정수이고, N은 1이상 1,000,000이하의 정수이다. 그리고 항상 K ≦ N 이다. 그

www.acmicpc.net

 

'코딩 테스트 > BOJ' 카테고리의 다른 글

C# 10162 전자레인지  (0) 2023.02.01
C# 2231 분해합  (0) 2023.01.31
C# 2003 수들의 합2  (0) 2023.01.20
C# 2979 트럭 주차  (0) 2023.01.19
C# 10808 알파벳 개수  (0) 2023.01.19