# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
236699 | Mercenary | Teams (CEOI11_tea) | C++14 | 494 ms | 86648 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#define pb push_back
#define mp make_pair
#define taskname "A"
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
ii a[maxn];
vector<int> s[maxn];
int f[maxn];
int trace[maxn];
int n;
int dp[maxn];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
if(fopen(taskname".INP","r")){
freopen(taskname".INP", "r",stdin);
freopen(taskname".OUT", "w",stdout);
}
cin >> n;
for(int i = 1 ; i <= n ; ++i){
cin >> a[i].first;
a[i].second = i;
}
sort(a + 1 , a + n + 1);
s[0].pb(0);
int tmp = 0;
priority_queue<ii , vector<ii> , greater<ii> > pq;
for(int i = 1 ; i <= n ; ++i){
while(pq.size() && pq.top().first <= i){
s[dp[pq.top().second]].pb(pq.top().second);
pq.pop();
}
if(i - a[i].first >= 0){
tmp = f[i - a[i].first];
trace[i] = *(upper_bound(s[tmp].begin(), s[tmp].end(), i - a[i].first) - 1);
f[i] = max(tmp + 1 , f[i - 1]);
dp[i] = tmp + 1;
pq.push(mp(i + i - trace[i] , i));
}else{
f[i] = f[i - 1];
}
}
cout << tmp + 1 << endl;
while(n > 0){
cout << n - trace[n] << " ";
for(int i = trace[n] + 1 ; i <= n ; ++i){
cout << a[i].second << " ";
assert(a[i].first <= n - trace[n]);
}
cout << '\n';
n = trace[n];
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |