제출 #482942

#제출 시각아이디문제언어결과실행 시간메모리
482942hidden1최후의 만찬 (IOI12_supper)C++14
100 / 100
135 ms9828 KiB
#include "advisor.h" #include <bits/stdc++.h> using namespace std; //#pragma GCC optimize ("O3") //#pragma GCC target ("sse4") #ifndef LOCAL #define cerr if(false) cerr #endif #define endl "\n" #define all(x) (x).begin(), (x).end() #define forn(i, n) for(int i = 0; i < n; i ++) #define revn(i, n) for(int i = n - 1; i >= 0; i --) typedef long long ll; template<class T, template<class T2, class A=allocator<T2> > class cont> inline ostream &operator <<(ostream &out, const cont<T> &x) { for(const auto &it : x) { out << it << " ";} return out;} template<class T, template<class T2, class A=allocator<T2> > class cont> inline istream &operator >>(istream &in, cont<T> &x) { for(auto &it : x) { in >> it;} return in;} template<class T, class T2> inline ostream &operator <<(ostream &out, const pair<T, T2> &x) { out << x.first << " " << x.second; return out;} template<class T, class T2> inline istream &operator >>(istream &in, pair<T, T2> &x) { in >> x.first >> x.second; return in;} template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; } template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; } const ll mod = 1e9 + 7; const int MAX_N = 2e5 + 10; ll nxt[MAX_N]; ll change[MAX_N]; bool ans[MAX_N]; int n, k, m; int current[MAX_N]; void ComputeAdvice(int *arr, int n, int k, int m) { for(int i = 0; i < n; i ++) { nxt[i] = n; } for(int i = n - 1; i >= 0; i --) { change[i] = nxt[arr[i]]; nxt[arr[i]] = i; } set<pair<int, int> > st; for(int i = 0; i < k; i ++) { st.insert({nxt[i], i}); current[i] = i; } int cnt = k; auto removeMax = [&st]() { auto it = st.end(); it --; ans[current[(*it).second]] = 1; st.erase(it); }; for(int i = 0; i < n; i ++) { if(st.find({i, arr[i]}) != st.end()) { auto it = st.find({i, arr[i]}); ans[current[(*it).second]] = 0; st.erase(it); } else { removeMax(); } nxt[arr[i]] = change[i]; current[arr[i]] = cnt ++; st.insert({nxt[arr[i]], arr[i]}); } for(int i = 0; i < cnt; i ++) { WriteAdvice(ans[i]); } }
#include "assistant.h" #include <bits/stdc++.h> using namespace std; //#pragma GCC optimize ("O3") //#pragma GCC target ("sse4") #ifndef LOCAL #define cerr if(false) cerr #endif #define endl "\n" #define all(x) (x).begin(), (x).end() #define forn(i, n) for(int i = 0; i < n; i ++) #define revn(i, n) for(int i = n - 1; i >= 0; i --) typedef long long ll; template<class T, template<class T2, class A=allocator<T2> > class cont> inline ostream &operator <<(ostream &out, const cont<T> &x) { for(const auto &it : x) { out << it << " ";} return out;} template<class T, template<class T2, class A=allocator<T2> > class cont> inline istream &operator >>(istream &in, cont<T> &x) { for(auto &it : x) { in >> it;} return in;} template<class T, class T2> inline ostream &operator <<(ostream &out, const pair<T, T2> &x) { out << x.first << " " << x.second; return out;} template<class T, class T2> inline istream &operator >>(istream &in, pair<T, T2> &x) { in >> x.first >> x.second; return in;} template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; } template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; } const ll mod = 1e9 + 7; void Assist(unsigned char *ans, int n, int k, int r) { set<int> st; set<int> bad; for(int i = 0; i < k; i ++) { st.insert(i); if(ans[i]) { bad.insert(i); } } int cnt = k; for(int i = 0; i < n; i ++) { int now = GetRequest(); if(st.find(now) != st.end()) { st.erase(st.find(now)); } else { auto something = bad.begin(); PutBack(*something); st.erase(*something); bad.erase(*something); } st.insert(now); if(ans[cnt]) { bad.insert(now); } cnt ++; } }
#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...