제출 #306155

#제출 시각아이디문제언어결과실행 시간메모리
306155richyrichArranging Shoes (IOI19_shoes)C++17
10 / 100
1088 ms22776 KiB
//#include "shoes.h" #include<bits/stdc++.h> using namespace std; using ll = long long; set<pair<int, int>> left_shoes; ll n, now,idx, ans; map<int, set<int>>i_r_shoes; queue<pair<int, int>> q; void shift() { for(auto c : left_shoes) { int IDX = c.first; if(now <= IDX && IDX <= idx) { ans++; q.push({IDX, c.second}); } } while(!q.empty()) { int a = q.front().first , b = q.front().second; left_shoes.erase({a, b}); left_shoes.insert({a + 1, b}); q.pop(); } for(auto &c : i_r_shoes) { queue<int> q_p; for(int d : c.second) { if(now <= d && d <= idx) q_p.push(d), ans++; } while(!q_p.empty()) { int a = q_p.front(); //if(c.second.find(a) != c.second.end()) printf("YES\n"); c.second.erase(a); c.second.insert(a+1); //printf("now %d %d\n", c.first, a+1); q_p.pop(); } } } long long count_swaps(std::vector<int> s) { n = s.size(); for(int i = 0; i < n; i++) { if(s[i] < 0) left_shoes.insert({i, s[i]}); else i_r_shoes[s[i]].insert(i); } while(!left_shoes.empty()) { idx = (*left_shoes.begin()).first; int type = (*left_shoes.begin()).second; left_shoes.erase({idx, type}); shift(); now++; /*printf("here --> %d %d \n", type, idx); for(auto c : left_shoes) { printf("%d %d\n", c.second, c.first); } for(auto c : i_r_shoes) { for(auto d : c.second)printf("%d %d\n", c.first, d); } */ idx = *i_r_shoes[-type].begin(); i_r_shoes[-type].erase(idx); shift(); now++;/* printf("%d\n", ans); for(auto c : left_shoes) { printf("%d %d\n", c.second, c.first); } for(auto c : i_r_shoes) { for(auto d : c.second)printf("%d %d\n", c.first, d); }*/ } return ans; } /*int main() { int N; cin >> N; vector<int> v; for(int i = 0; i < 2*N; i++) { int x; cin >> x; v.push_back(x); } printf("%lld\n", count_swaps(v)); }*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...