結果

問題 No.2095 High Rise
ユーザー 👑 p-adicp-adic
提出日時 2022-09-24 23:28:49
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 1,981 bytes
コンパイル時間 2,047 ms
コンパイル使用メモリ 198,704 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-09-02 22:33:04
合計ジャッジ時間 5,091 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 2 ms
4,368 KB
testcase_05 AC 1 ms
4,372 KB
testcase_06 AC 2 ms
4,368 KB
testcase_07 AC 1 ms
4,368 KB
testcase_08 AC 1 ms
4,372 KB
testcase_09 AC 2 ms
4,372 KB
testcase_10 AC 1 ms
4,372 KB
testcase_11 AC 1 ms
4,368 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,372 KB
testcase_14 AC 2 ms
4,372 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 10 ms
4,372 KB
testcase_19 AC 4 ms
4,368 KB
testcase_20 AC 16 ms
4,368 KB
testcase_21 AC 29 ms
4,368 KB
testcase_22 AC 117 ms
4,372 KB
testcase_23 AC 118 ms
4,368 KB
testcase_24 AC 118 ms
4,372 KB
testcase_25 AC 118 ms
4,368 KB
testcase_26 AC 118 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 opt0[2] = {};
  ll opt1[2] = {};
  ll optn[2][bound_M] = {};
  int j0[2] = {};
  constexpr const ll bound_opt = 1000000000001;
  ll opt_up;
  ll opt_shift;
  ll opt_total;
  REPEAT( N ){
    ll ( &A_current )[bound_M] = A[i0];
    int& j0_current = j0[i0];
    ll& opt0_current = opt0[i0];
    ll& opt1_current = opt1[i0];
    ll ( &optn_current )[bound_M] = optn[i0];
    opt0_current = bound_opt;
    opt0_current = bound_opt;
    ll ( &A_prev )[bound_M] = A[i1];
    const int j0_prev = j0[i1];
    ll& opt0_prev = opt0[i1];
    ll& opt1_prev = opt1[i1];
    ll ( &optn_prev )[bound_M] = optn[i1];
    FOR( j , 0 , M ){
      ll& Aj = A_current[j];
      cin >> Aj;
      assert( 1 <= Aj && Aj < bound_Aj );
      opt_up = optn_prev[j];
      opt_shift = ( j == j0_prev ? opt1_prev : opt0_prev ) + A_prev[j];
      opt_total = MIN( opt_up , opt_shift ) + Aj;
      if( opt0_current > opt_total ){
	opt1_current = opt0_current;
	opt0_current = opt_total;
	j0_current = j;
      } else if( opt1_current > opt_total ){
	opt1_current = opt_total;
      }
      optn_current[j] = opt_total;
    }
    swap( i0 , i1 );
  }
  RETURN( N == 1 ? 0 : opt0[i1] );
}
0