제출 #855229

#제출 시각아이디문제언어결과실행 시간메모리
855229mzhStone Arranging 2 (JOI23_ho_t1)C++17
100 / 100
61 ms13808 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(x) begin(x), end(x) int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<pair<int, int>> stones; unordered_map<int, int> freq; for (int i = 0; i < n; i++) { int to_add = 1; if (freq[a[i]] > 0) { while (stones.back().first != a[i]) { to_add += stones.back().second; freq[stones.back().first] -= stones.back().second; stones.pop_back(); } } if (stones.empty() || stones.back().first != a[i]) { stones.push_back({a[i], 0}); } stones.back().second += to_add; freq[a[i]] += to_add; } for (auto p : stones) { for (int i = 0; i < p.second; i++) { cout << p.first << ' '; } } cout << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...