Submission #58853
ソースコード
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 | #include <bits/stdc++.h> using namespace std; #define int int64_t #define rep(i, a, n) for (int i = (a); i < (n); ++i) #define reps(i, a, n) for (int i = (a); i < (n); --i) #define all(x) (x).begin(), (x).end() #define gsort(x, n) sort((x), (x + n) greater<int>()) #define rv(s) reverse((s).begin(), (s).end()) #define setout(n, x) setw(n) << setfill(x) #define Fixed fixed << setprecision(10); #define pb(x, a) (x).push_back(a) #define fb(x, a) (x).flont_back(a) #define eb(x, a) (x).emplaes_back(a) using pii = pair< int , int >; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; const long long mod = 1e9 + 7; signed main() { cin.tie(nullptr); ios_base::sync_with_stdio( false ); int n; cin >> n; vector< int > a(n); priority_queue< int > y; priority_queue< int , vector< int >, greater< int >> x; rep(i, 0, n) cin >> a[i]; cout << a[0] << '\n' ; y.push(a[0]); rep(i, 1, n) { if (y.top() > a[i]) { y.push(a[i]); } else { x.push(a[i]); } if (i % 2 == 1 && x.size() != y.size()){ if (x.size() > y.size()){ y.push(x.top()); x.pop(); } else { x.push(y.top()); y.pop(); } } if (i % 2 == 0){ if (x.size() > y.size()){ cout<<x.top()<< '\n' ; } else { cout<<y.top()<< '\n' ; } } else { cout<<(x.top()+y.top())/2<< '\n' ; } } } |
ステータス
項目 | データ |
---|---|
問題 | 1276 - Median Find |
ユーザー名 | immunity |
投稿日時 | 2020-03-10 23:40:29 |
言語 | C++17 |
状態 | Accepted |
得点 | 400 |
ソースコード長 | 1553 Byte |
最大実行時間 | 108 ms |
最大メモリ使用量 | 53364 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 400 / 400 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
in01.txt | AC | 31 ms | 604 KB |
1
|
in02.txt | AC | 19 ms | 416 KB |
1
|
in03.txt | AC | 33 ms | 1124 KB |
1
|
in04.txt | AC | 24 ms | 1528 KB |
1
|
in05.txt | AC | 37 ms | 3020 KB |
1
|
in06.txt | AC | 25 ms | 2396 KB |
1
|
in07.txt | AC | 77 ms | 10048 KB |
1
|
in08.txt | AC | 16 ms | 4756 KB |
1
|
in09.txt | AC | 105 ms | 17740 KB |
1
|
in10.txt | AC | 106 ms | 22496 KB |
1
|
in11.txt | AC | 25 ms | 14624 KB |
1
|
in12.txt | AC | 21 ms | 14576 KB |
1
|
in13.txt | AC | 27 ms | 14664 KB |
1
|
in14.txt | AC | 18 ms | 14748 KB |
1
|
in15.txt | AC | 24 ms | 14836 KB |
1
|
in16.txt | AC | 20 ms | 14788 KB |
1
|
in17.txt | AC | 72 ms | 23800 KB |
1
|
in18.txt | AC | 67 ms | 24636 KB |
1
|
in19.txt | AC | 72 ms | 25736 KB |
1
|
in20.txt | AC | 89 ms | 30932 KB |
1
|
in21.txt | AC | 97 ms | 35876 KB |
1
|
in22.txt | AC | 104 ms | 40556 KB |
1
|
in23.txt | AC | 103 ms | 45500 KB |
1
|
in24.txt | AC | 108 ms | 50384 KB |
1
|
in25.txt | AC | 91 ms | 53364 KB |
1
|
sample01.txt | AC | 22 ms | 45276 KB |
1
|
sample02.txt | AC | 20 ms | 45228 KB |
1
|
sample03.txt | AC | 24 ms | 45312 KB |
1
|