結果

問題 No.2091 Shio Ramen (Easy)
ユーザー 👑 p-adic
提出日時 2022-10-06 16:02:56
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 949 bytes
コンパイル時間 1,977 ms
コンパイル使用メモリ 191,620 KB
最終ジャッジ日時 2025-02-07 22:15:41
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:48: warning: ‘R’ may be used uninitialized [-Wmaybe-uninitialized]
    9 | #define RETURN( ANSWER ) cout << ( ANSWER ) << "\n"; QUIT
      |                                                ^~~~
main.cpp:35:5: note: in expansion of macro ‘RETURN’
   35 |     RETURN( R );
      |     ^~~~~~
main.cpp:22:7: note: ‘R’ was declared here
   22 |   int R;
      |       ^

ソースコード

diff #

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

#define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ) 
#define CIN( LL , A ) LL A; cin >> A 
#define TYPE_OF( VAR ) remove_const<remove_reference<decltype( VAR )>::type >::type
#define FOREQ( VAR , INITIAL , FINAL ) for( TYPE_OF( FINAL ) VAR = INITIAL ; VAR <= FINAL ; VAR ++ )  
#define QUIT return 0 
#define RETURN( ANSWER ) cout << ( ANSWER ) << "\n"; QUIT 

template <typename T> inline T Absolute( const T& a ){ return a > 0 ? a : - a; }

int main()
{
  UNTIE;
  CIN( int , N );
  assert( 1 <= N && N <= 10 );
  CIN( int , S );
  assert( 1 <= S && S <= 10 );
  CIN( int , K );
  assert( 0 <= K && K <= 10 );
  int R;
  int opt = K + 1;
  int opt_current;
  int Ai;
  FOREQ( i , 1 , N ){
    cin >> Ai;
    opt_current = Absolute( Ai - S );
    if( opt_current < opt ){
      R = i;
      opt = opt_current;
    }
  }
  if( opt <= K ){
    RETURN( R );
  }
  RETURN( "Unlucky!" );
}
0