提出 #45437738


ソースコード 拡げる

#include<bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while(t--){
       long long n, m, mx=0;
       cin >> n >> m;
       long long a[n];
       long long b[n];
       for(int i = 0; i < n; i++){
           cin >> a[i];
           b[i] = a[i];
           mx = max(mx, a[i]);
       }
       sort(b, b + n);
       long long line = n / m + (n % m != 0);
       long long w = 0;
       for(int i = n - 1; i >= n - line; i--){
           w += (long long)b[i] + 1;
       }
       long long l = mx;
       long long r = w;
       while(l <= r){
           bool flag = true;
           long long mid = l + (r - l) / 2;
           //long long mid = (long long)10000000008;
           long long cur_sum = 0;
           int cur_line = m;
           for(int i = 0; i < n; i++){
               if(cur_sum == 0 && cur_sum + a[i] <= mid){
                   cur_sum += a[i];
               }
               else if(cur_sum + 1 + a[i] <= mid){
                   cur_sum += a[i] + 1;
               }
               else{
                   cur_line--;
                   if(cur_sum == 0 || cur_line == 0){
                       flag = false;
                       break;
                   }
                   cur_sum = a[i];
               }
           }
           if(flag == true){
               w = mid;
               r = mid - 1;
           }
           else{
               l = mid + 1;
           }
       }
       cout << w;

    }
    return 0;
}

提出情報

提出日時
問題 D - Minimum Width
ユーザ llc5pg
言語 C++ 17 (gcc 12.2)
得点 400
コード長 1599 Byte
結果 AC
実行時間 48 ms
メモリ 6616 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 3
AC × 25
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 02_handmade_19.txt, 02_handmade_20.txt, 02_handmade_21.txt, 02_handmade_22.txt, 02_handmade_23.txt, 02_handmade_24.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3416 KiB
00_sample_01.txt AC 1 ms 3388 KiB
00_sample_02.txt AC 1 ms 3456 KiB
01_random_03.txt AC 48 ms 6536 KiB
01_random_04.txt AC 46 ms 6564 KiB
01_random_05.txt AC 46 ms 6568 KiB
01_random_06.txt AC 42 ms 6608 KiB
01_random_07.txt AC 22 ms 5036 KiB
01_random_08.txt AC 16 ms 4488 KiB
01_random_09.txt AC 19 ms 4656 KiB
01_random_10.txt AC 44 ms 6392 KiB
01_random_11.txt AC 36 ms 5836 KiB
01_random_12.txt AC 23 ms 4996 KiB
01_random_13.txt AC 15 ms 4488 KiB
01_random_14.txt AC 29 ms 5440 KiB
01_random_15.txt AC 6 ms 4036 KiB
01_random_16.txt AC 26 ms 6268 KiB
01_random_17.txt AC 14 ms 4728 KiB
01_random_18.txt AC 5 ms 4008 KiB
02_handmade_19.txt AC 21 ms 6616 KiB
02_handmade_20.txt AC 10 ms 6612 KiB
02_handmade_21.txt AC 10 ms 6612 KiB
02_handmade_22.txt AC 13 ms 6536 KiB
02_handmade_23.txt AC 15 ms 6560 KiB
02_handmade_24.txt AC 15 ms 6496 KiB