結果
問題 | No.135 とりあえず1次元の問題 |
ユーザー | HiroakiSoftware |
提出日時 | 2015-01-25 23:58:38 |
言語 | C++11 (gcc 11.4.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,179 bytes |
コンパイル時間 | 502 ms |
コンパイル使用メモリ | 23,040 KB |
実行使用メモリ | 9,984 KB |
最終ジャッジ日時 | 2024-06-11 00:30:55 |
合計ジャッジ時間 | 12,648 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | -- | - |
testcase_02 | -- | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
evil01.txt | -- | - |
コンパイルメッセージ
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 ); | ~~~~~~^~~~~~~~~~~~~~~~~ main.cpp:42:9: warning: ‘diff’ may be used uninitialized in this function [-Wmaybe-uninitialized] 42 | if ( diff == -1 ) diff = 0; | ^~
ソースコード
#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; } } if ( diff == 1 )break; } delete []pX; if ( diff == -1 ) diff = 0; 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; if ( Current == 1 ) return Current; } int diff= -1 , idxnext; idxnext = idx2 + 1; diff = ( idxnext < N ) ? GetDiff ( idx1 , idxnext ) : -1; if ( diff == 1 )return diff; if ( bEnableCurrent ) { if (diff != -1 )return ( Current < diff ) ? Current : diff; return Current; } return diff; }