結果

問題 No.5 数字のブロック
ユーザー 👑 p-adicp-adic
提出日時 2022-08-07 16:10:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,293 bytes
コンパイル時間 640 ms
コンパイル使用メモリ 73,636 KB
実行使用メモリ 7,760 KB
最終ジャッジ日時 2023-10-17 11:08:09
合計ジャッジ時間 7,956 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 5 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 6 ms
4,348 KB
testcase_06 AC 4 ms
4,348 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 5 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 5 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 6 ms
4,348 KB
testcase_13 AC 5 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 6 ms
4,348 KB
testcase_17 AC 6 ms
4,348 KB
testcase_18 AC 5 ms
4,348 KB
testcase_19 AC 7 ms
4,348 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <list>
#include <string>
#include <stdio.h>
#include <stdint.h>
using namespace std;

using ll = long long;

void Solve( ll& L , list<ll>& W , ll& answer );

int main()
{

  ll L;
  ll N;
  list<ll> W{};
  cin >> L;
  cin >> N;

  for( ll i = 0 ; i < N ; i++ ){

    ll w;
    cin >> w;
    W.push_back( w );

  }
  
  ll answer = 0;
  Solve( L , W , answer );
  cout << answer << endl;
  return 0;

}

void Solve( ll& L , list<ll>& W , ll& answer )
{

  bool computing = true;

  while( computing ){
    
    ll W_min = 0;
    ll num = 0;
    list<list<ll>::iterator> W_min_list{};
  
    for( auto itr = W.begin() , end = W.end() ; itr != end ; itr++ ){

      const ll& w = *itr;
    
      if( W_min == 0 ){

	W_min = w;
	num = 1;
	W_min_list.push_back( itr );

      } else if( W_min == w ){

	num++;
	W_min_list.push_back( itr );

      } else if( W_min > w ){

	W_min = w;
	num = 1;
	W_min_list.clear();
	W_min_list.push_back( itr );

      }

    }

    const ll d = W_min * num;

    if( L <= d ){

      answer += L / W_min;
      computing = false;

    } else {

      L -= d;
  
      for( auto itr = W_min_list.begin() , end = W_min_list.end() ; itr != end ; itr++ ){

	W.erase( *itr );
    
      }

      answer += num;

    }

  }

  return;
  
}
0