Submission #58764
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | #include <iostream> #include <algorithm> #include <vector> #include <queue> using namespace std; signed main( void ){ cin.tie(nullptr); ios_base::sync_with_stdio( false ); int N; cin >> N; vector< int > a(N); for ( int i = 0; i < N; ++i){ cin >> a[i]; } // Aを昇順に並べたときの中央値の左と右をpriority_queueで表す。 priority_queue< int > left; priority_queue< int , vector< int >, greater< int > > right; cout << a[0] << '\n' ; if (N == 1){ return (0); } else { cout << (a[0] + a[1]) / 2 << '\n' ; } // 最初の二つの要素は予め入れておく auto [x, y] = minmax(a[0], a[1]); left.emplace(x); right.emplace(y); // right.size() >= left.size() が常に成り立つようにする for ( int i = 2; i < N; ++i){ // Aの要素数が奇数 if (i % 2 == 0){ if (left.top() > a[i]){ right.emplace(left.top()); left.pop(); left.emplace(a[i]); } else { right.emplace(a[i]); } cout << right.top() << '\n' ; // Aの要素数が偶数 } else { if (right.top() < a[i]){ left.emplace(right.top()); right.pop(); right.emplace(a[i]); } else { left.emplace(a[i]); } cout << (left.top() + right.top()) / 2 << '\n' ; } } return (0); } |
ステータス
項目 | データ |
---|---|
問題 | 1276 - Median Find |
ユーザー名 | ei1903 |
投稿日時 | 2020-02-22 16:10:41 |
言語 | C++17 |
状態 | Accepted |
得点 | 400 |
ソースコード長 | 1574 Byte |
最大実行時間 | 115 ms |
最大メモリ使用量 | 49412 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 400 / 400 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
in01.txt | AC | 26 ms | 600 KB |
1
|
in02.txt | AC | 18 ms | 408 KB |
1
|
in03.txt | AC | 23 ms | 864 KB |
1
|
in04.txt | AC | 27 ms | 1148 KB |
1
|
in05.txt | AC | 31 ms | 2456 KB |
1
|
in06.txt | AC | 25 ms | 2096 KB |
1
|
in07.txt | AC | 80 ms | 7392 KB |
1
|
in08.txt | AC | 30 ms | 4880 KB |
1
|
in09.txt | AC | 110 ms | 13908 KB |
1
|
in10.txt | AC | 101 ms | 18664 KB |
1
|
in11.txt | AC | 17 ms | 14476 KB |
1
|
in12.txt | AC | 20 ms | 14564 KB |
1
|
in13.txt | AC | 17 ms | 14644 KB |
1
|
in14.txt | AC | 24 ms | 14724 KB |
1
|
in15.txt | AC | 19 ms | 14552 KB |
1
|
in16.txt | AC | 20 ms | 14756 KB |
1
|
in17.txt | AC | 60 ms | 19680 KB |
1
|
in18.txt | AC | 59 ms | 20596 KB |
1
|
in19.txt | AC | 75 ms | 21768 KB |
1
|
in20.txt | AC | 85 ms | 27160 KB |
1
|
in21.txt | AC | 83 ms | 32044 KB |
1
|
in22.txt | AC | 100 ms | 36676 KB |
1
|
in23.txt | AC | 101 ms | 41436 KB |
1
|
in24.txt | AC | 115 ms | 46448 KB |
1
|
in25.txt | AC | 86 ms | 49412 KB |
1
|
sample01.txt | AC | 21 ms | 45228 KB |
1
|
sample02.txt | AC | 23 ms | 45184 KB |
1
|
sample03.txt | AC | 20 ms | 45268 KB |
1
|