結果

問題 No.135 とりあえず1次元の問題
ユーザー HiroakiSoftwareHiroakiSoftware
提出日時 2015-01-25 23:56:18
言語 C++11
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 1,057 bytes
コンパイル時間 375 ms
コンパイル使用メモリ 27,264 KB
実行使用メモリ 15,744 KB
最終ジャッジ日時 2025-01-03 03:07:26
合計ジャッジ時間 30,932 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 17 WA * 1 TLE * 4
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:15:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |         scanf ( "%d" , &N );
      |         ~~~~~~^~~~~~~~~~~~~
main.cpp:22:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |                 scanf ( "%d" , pX + i );
      |                 ~~~~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/stdio.h:980,
                 from main.cpp:1:
In function ‘int printf(const char*, ...)’,
    inlined from ‘int main()’ at main.cpp:42:9:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:86:23: warning: ‘diff’ may be used uninitialized [-Wmaybe-uninitialized]
   86 |   return __printf_chk (__USE_FORTIFY_LEVEL - 1, __fmt, __va_arg_pack ());
      |          ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:19:13: note: ‘diff’ was declared here
   19 |         int diff , diffbuf;
      |             ^~~~

ソースコード

diff #

#include <stdio.h>



int *pX = nullptr;
int N = 0;


int GetDiff ( int idx1 , int idx2 );


int main ( void ) {


	scanf ( "%d" , &N );


	pX = new int [ N ];
	int diff , diffbuf;

	for ( int i = 0; i < N; i++ ) {
		scanf ( "%d" , pX + i );
	}


	for ( int i = 0; i < ( N - 1 ); i++ ) {
		//printf ( "Call\n" );
		if ( i == 0 ) {

			diff = GetDiff ( i , i + 1 );

		} else {
			diffbuf = GetDiff ( i , i + 1 );
			if ( diffbuf != -1 ) {
				if ( diffbuf < diff ) diff = diffbuf;
			}
		}
	}
	delete []pX;


	printf ( "%d\n" , diff );
	return 0;
}

int GetDiff ( int idx1 , int idx2 ) {
	//printf ( "%d %d\n" , idx1 , idx2 );
	bool bEnableCurrent = false;
	int Current;

	if ( *( pX + idx1 ) != *( pX + idx2 ) ) {
		bEnableCurrent = true;
		Current = *( pX + idx1 ) - *( pX + idx2 );
		if ( Current < 0 ) Current *= -1;
	}

	int diff= -1 , idxnext;

	idxnext = idx2 + 1;
	diff = ( idxnext < N ) ? GetDiff ( idx1 , idxnext ) : -1;

	if ( bEnableCurrent ) {
		if (diff != -1 )return ( Current < diff ) ? Current : diff;
		return Current;
	}
	return diff;

}
0