[Codeforces] Educational42 Merge Equals
題目連結:http://codeforces.com/contest/962/problem/D
用map亂做。
好感嘆我當時竟然寫得出來......。
用map亂做。
好感嘆我當時竟然寫得出來......。
#include<bits/stdc++.h> #define int long long using namespace std; map<int,priority_queue<int,vector<int>,greater<int> > > m,ss; int n; vector<pair<int,int> > s; signed main() { cin >> n; for(int i = 0; i < n; i++) { int a; cin >> a; m[a].push(i); } for(auto i:m) { //cout << i.first << endl; while(i.second.size()) { if(i.second.size() == 1) { ss[i.first].push(i.second.top()); break; } //cout << i.second.top() << " "; i.second.pop(); int p = i.second.top(); i.second.pop(); //cout << p << endl; m[i.first*2].push(p); } } s.clear(); for(auto i:ss) { if(i.second.size()) { s.push_back({i.second.top(),i.first}); //cout << i.second.top() << " " << i.first << endl; } } sort(s.begin(),s.end()); cout << s.size() << endl; for(auto i:s) cout << i.second << " "; cout << endl; }
留言
張貼留言