結果

問題 No.2095 High Rise
ユーザー 👑 p-adicp-adic
提出日時 2022-09-25 11:05:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 119 ms / 2,000 ms
コード長 1,842 bytes
コンパイル時間 2,123 ms
コンパイル使用メモリ 199,832 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-09-02 22:35:42
合計ジャッジ時間 4,619 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 1 ms
4,372 KB
testcase_04 AC 1 ms
4,372 KB
testcase_05 AC 1 ms
4,372 KB
testcase_06 AC 1 ms
4,368 KB
testcase_07 AC 2 ms
4,372 KB
testcase_08 AC 1 ms
4,368 KB
testcase_09 AC 2 ms
4,372 KB
testcase_10 AC 2 ms
4,372 KB
testcase_11 AC 1 ms
4,372 KB
testcase_12 AC 2 ms
4,372 KB
testcase_13 AC 2 ms
4,368 KB
testcase_14 AC 2 ms
4,368 KB
testcase_15 AC 2 ms
4,368 KB
testcase_16 AC 2 ms
4,368 KB
testcase_17 AC 15 ms
4,368 KB
testcase_18 AC 11 ms
4,368 KB
testcase_19 AC 4 ms
4,368 KB
testcase_20 AC 16 ms
4,368 KB
testcase_21 AC 30 ms
4,368 KB
testcase_22 AC 119 ms
4,368 KB
testcase_23 AC 119 ms
4,368 KB
testcase_24 AC 118 ms
4,372 KB
testcase_25 AC 119 ms
4,368 KB
testcase_26 AC 119 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;

#define CIN( LL , A ) LL A; cin >> A 
#define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ) 
#define FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( remove_const<remove_reference<decltype( FINAL_PLUS_ONE )>::type >::type VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ ) 
#define REPEAT( HOW_MANY_TIMES ) FOR( VARIABLE_FOR_REPEAT , 0 , HOW_MANY_TIMES ) 
#define QUIT return 0 
#define RETURN( ANSWER ) cout << ( ANSWER ) << "\n"; QUIT 
#define MIN( A , B ) ( A < B ? A : B ) 

int main()
{
  UNTIE;
  constexpr const int bound_M = 1000;
  CIN( int , N );
  assert( 1 <= N && N <= bound_M );
  CIN( int , M );
  assert( 1 <= M && M <= bound_M );
  int i0 = 0;
  int i1 = 1;
  constexpr const ll bound_Aj = 1000000001;
  ll A[2][bound_M] = {};
  ll opt_all[2] = {};
  ll opt_each[2][bound_M] = {};
  int j0[2] = {};
  constexpr const ll bound_opt = 1000000000001;
  ll opt_up;
  ll opt_shift;
  ll opt_up_shift;
  REPEAT( N ){
    ll ( &A_current )[bound_M] = A[i0];
    int& j0_current = j0[i0];
    ll& opt_all_current = opt_all[i0];
    ll ( &opt_each_current )[bound_M] = opt_each[i0];
    opt_all_current = bound_opt;
    opt_all_current = bound_opt;
    ll ( &A_prev )[bound_M] = A[i1];
    const int j0_prev = j0[i1];
    ll& opt_all_prev = opt_all[i1];
    ll ( &opt_each_prev )[bound_M] = opt_each[i1];
    FOR( j , 0 , M ){
      ll& Aj = A_current[j];
      cin >> Aj;
      assert( 1 <= Aj && Aj < bound_Aj );
      opt_up = opt_each_prev[j];
      opt_shift = opt_all_prev + A_prev[j];
      opt_up_shift = MIN( opt_up , opt_shift ) + Aj;
      if( opt_all_current > opt_up_shift ){
	opt_all_current = opt_up_shift;
	j0_current = j;
      }
      opt_each_current[j] = opt_up_shift;
    }
    swap( i0 , i1 );
  }
  RETURN( N == 1 ? 0 : opt_all[i1] );
}
0