結果

問題 No.275 中央値を求めよ
ユーザー y32M-71693993y32M-71693993
提出日時 2015-10-01 21:59:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 3,472 bytes
コンパイル時間 1,446 ms
コンパイル使用メモリ 160,020 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-24 23:21:00
合計ジャッジ時間 2,719 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:38:27: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   38 | #define SCANF_INT(a) scanf("%d", &(a));
      |                      ~~~~~^~~~~~~~~~~~
main.cpp:8:9: note: in expansion of macro ‘SCANF_INT’
    8 |         FIRST(A)
      |         ^~~~~
main.cpp:5:69: note: in expansion of macro ‘EXPAND_01’
    5 | #define GET_MACRO_09(A1, A2, A3, A4, A5, A6, A7, A8, A9, NAME, ...) NAME
      |                                                                     ^~~~
main.cpp:29:28: note: in expansion of macro ‘EXPAND_ADD’
   29 | #define EXPAND(MACRO, ...) EXPAND_ADD(MACRO, MACRO, __VA_ARGS__)
      |                            ^~~~~~~~~~
main.cpp:41:33: note: in expansion of macro ‘EXPAND’
   41 | #define I(...) int __VA_ARGS__; EXPAND(SCANF_INT, __VA_ARGS__);
      |                                 ^~~~~~
main.cpp:95:9: note: in expansion of macro ‘I’
   95 |         I(n);
      |         ^
main.cpp:98:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   98 |                 scanf("%d", a+i);
      |                 ~~~~~^~~~~~~~~~~

ソースコード

diff #

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

// Macro Tools /////////////////////////////////////////////////////////////////
#define GET_MACRO_09(A1, A2, A3, A4, A5, A6, A7, A8, A9, NAME, ...) NAME

#define EXPAND_01(FIRST, NEXT, A) \
	FIRST(A)
#define EXPAND_02(FIRST, NEXT, A, B) \
	FIRST(A) NEXT(B)
#define EXPAND_03(FIRST, NEXT, A, B, C) \
	FIRST(A) NEXT(B) NEXT(C)
#define EXPAND_04(FIRST, NEXT, A, B, C, D) \
	FIRST(A) NEXT(B) NEXT(C) NEXT(D)
#define EXPAND_05(FIRST, NEXT, A, B, C, D, E) \
	FIRST(A) NEXT(B) NEXT(C) NEXT(D) NEXT(E)
#define EXPAND_06(FIRST, NEXT, A, B, C, D, E, F) \
	FIRST(A) NEXT(B) NEXT(C) NEXT(D) NEXT(E) NEXT(F)
#define EXPAND_07(FIRST, NEXT, A, B, C, D, E, F, G) \
	FIRST(A) NEXT(B) NEXT(C) NEXT(D) NEXT(E) NEXT(F) NEXT(G)
#define EXPAND_08(FIRST, NEXT, A, B, C, D, E, F, G, H) \
	FIRST(A) NEXT(B) NEXT(C) NEXT(D) NEXT(E) NEXT(F) NEXT(G) NEXT(H)
#define EXPAND_09(FIRST, NEXT, A, B, C, D, E, F, G, H, I) \
	FIRST(A) NEXT(B) NEXT(C) NEXT(D) NEXT(E) NEXT(F) NEXT(G) NEXT(H) NEXT(I)
#define EXPAND_ADD(FIRST, NEXT, ...) \
	GET_MACRO_09(__VA_ARGS__, EXPAND_09, EXPAND_08, EXPAND_07, EXPAND_06, \
		EXPAND_05, EXPAND_04, EXPAND_03, EXPAND_02, EXPAND_01) \
	(FIRST, NEXT, __VA_ARGS__)
#define EXPAND(MACRO, ...) EXPAND_ADD(MACRO, MACRO, __VA_ARGS__)

#define Q(x) #x
#define QUOTE(x) Q(x)

// Input ///////////////////////////////////////////////////////////////////////
#define RIGHT_SHIFT_BEFORE(a) >>a
#define CAMMA_AND_ADDRESS(a) , &a
#define INT_FORMATTER(a) %d
#define SCANF_INT(a) scanf("%d", &(a));
// #define SCANF_LL(a) scanf("%I64d", &(a));

#define I(...) int __VA_ARGS__; EXPAND(SCANF_INT, __VA_ARGS__);
// #define L(...) long long __VA_ARGS__; EXPAND(SCANF_LL, __VA_ARGS__);

#define input(t,v) t v;cin>>v;
#define input2(t,v1,v2) t v1,v2;cin>>v1>>v2;
#define input3(t,v1,v2,v3) t v1,v2,v3;cin>>v1>>v2>>v3;

#if __cplusplus > 199711L  //C++11
template<class T=int>
#else
template<class T>
#endif
T read() {
	T t;
	cin >> t;
	return t;
}

// Types ///////////////////////////////////////////////////////////////////////
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef set<int> si;
typedef set<ll, ll> sll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef list<int> li;
typedef list<ll> lll;
typedef map<int, int> mii;
typedef map<int, ll> mil;
typedef map<ll, int> mli;
typedef map<ll, ll> mll;

// Loop & Iteration ////////////////////////////////////////////////////////////
#define FOR(i, a, b) for(int i = (a), loop_end_##i=(b); i < (loop_end_##i); i++)
#define REP(i, n) FOR(i, 0, n)
#define rep(v,n) for(int (v)=0;(v)<(n);(v)++)
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort((c).begin(),(c).end())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define PB push_back

// Range ///////////////////////////////////////////////////////////////////////
#define IN(x, a, b) (a<=x && x<b)
int dx[8] = { 1, 0, 0,-1, 1, 1,-1,-1};
int dy[8] = { 0,-1, 1, 0,-1, 1,-1, 1};

// Debug ///////////////////////////////////////////////////////////////////////
#define dump(x)  cout << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

////////////////////////////////////////////////////////////////////////////////

int main(){
	I(n);
	int a[n];
	REP(i, n){
		scanf("%d", a+i);
	}
	sort(a, a+n);
	if(n%2==0){
		printf("%.3f\n", (a[n/2-1]+a[n/2])/2.0);
	}else{
		printf("%d\n", a[n/2]);
	}
}
0