結果

問題 No.281 門松と魔法(1)
ユーザー 0w10w1
提出日時 2016-12-13 15:32:33
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,064 bytes
コンパイル時間 1,681 ms
コンパイル使用メモリ 169,632 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-30 01:04:18
合計ジャッジ時間 2,844 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 53 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef pair< int, int > pii;
typedef vector< pii > vp;
typedef vector< double > vd;
typedef vector< vd > vvd;
typedef vector< string > vs;

template< class T1, class T2 >
int upmin( T1 &x, T2 v ){
  if( x > v ){
    x = v;
    return 1;
  }
  return 0;
}

template< class T1, class T2 >
int upmax( T1 &x, T2 v ){
  if( x < v ){
    x = v;
    return 1;
  }
  return 0;
}

const int INF = 0x3f3f3f3f;

int D;
vi H;

void init(){
  cin >> D;
  H = vi( 3 );
  for( int i = 0; i < 3; ++i )
    cin >> H[ i ];
}

int kado( int a, int b, int c ){
  if( a == b or b == c or c == a )
    return 0;
  return b == min( { a, b, c } ) or b == max( { a, b, c } );
}

void preprocess(){
  if( kado( H[ 0 ], H[ 1 ], H[ 2 ] ) )
    cout << 0 << endl, exit( 0 );
  if( D == 0 )
    cout << -1 << endl, exit( 0 );
}

void solve(){
  int ans = INF;
  if( true ){
    int f = 0;
    int zzz = H[ 0 ];
    if( H[ 0 ] == H[ 2 ] ){
      if( max( 0LL, H[ 0 ] - D ) == H[ 2 ] )
        f = INF;
      else
        ++f,
        H[ 0 ] = max( 0LL, H[ 0 ] - D );
    }
    int minv = min( H[ 0 ], H[ 2 ] );
    if( max( 0LL, H[ 1 ] - ( ( H[ 1 ] - minv ) / D * D + D ) ) < H[ 0 ] )
      upmin( ans, f + ( H[ 1 ] - minv ) / D + 1 );
    H[ 0 ] = zzz;
    if( H[ 1 ] > 0 ){
    int t = 0;
    if( H[ 2 ] >= H[ 1 ] )
      t += ( H[ 2 ] - H[ 1 ] ) / D + 1;
    if( H[ 0 ] >= H[ 1 ] )
      t += ( H[ 0 ] - H[ 1 ] ) / D + 1;
    int x = H[ 2 ] >= H[ 1 ] ? max( 0LL, H[ 2 ] - ( ( H[ 2 ] - H[ 1 ] ) / D * D + D ) ) : H[ 2 ];
    int y = H[ 0 ] >= H[ 1 ] ? max( 0LL, H[ 0 ] - ( ( H[ 0 ] - H[ 1 ] ) / D * D + D ) ) : H[ 0 ];
    if( x == y ){
      if( max( 0LL, x - D ) == y )
        t = INF;
      else
        ++t;
    }
    upmin( ans, t );
  }
  if( ans == INF ) ans = -1;
  cout << ans << endl; 
  }
}

signed main(){
  ios::sync_with_stdio( 0 );
  init();
  preprocess();
  solve();
  return 0;
}
0