Submission #236699

# Submission time Handle Problem Language Result Execution time Memory
236699 2020-06-02T23:57:03 Z Mercenary Teams (CEOI11_tea) C++14
100 / 100
494 ms 86648 KB
#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

tea.cpp: In function 'int main()':
tea.cpp:31:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".INP", "r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
tea.cpp:32:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".OUT", "w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 19 ms 23808 KB Output is correct
2 Correct 19 ms 23808 KB Output is correct
3 Correct 20 ms 23808 KB Output is correct
4 Correct 19 ms 23808 KB Output is correct
5 Correct 20 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 23808 KB Output is correct
2 Correct 20 ms 23808 KB Output is correct
3 Correct 20 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 23936 KB Output is correct
2 Correct 20 ms 23808 KB Output is correct
3 Correct 19 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 24064 KB Output is correct
2 Correct 21 ms 24056 KB Output is correct
3 Correct 21 ms 24064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 24064 KB Output is correct
2 Correct 21 ms 24064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 26748 KB Output is correct
2 Correct 48 ms 26616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 27128 KB Output is correct
2 Correct 48 ms 26488 KB Output is correct
3 Correct 58 ms 27000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 342 ms 50936 KB Output is correct
2 Correct 286 ms 50552 KB Output is correct
3 Correct 363 ms 51184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 478 ms 60476 KB Output is correct
2 Correct 354 ms 86648 KB Output is correct
3 Correct 398 ms 59768 KB Output is correct
4 Correct 433 ms 56052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 381 ms 58720 KB Output is correct
2 Correct 265 ms 50428 KB Output is correct
3 Correct 403 ms 58872 KB Output is correct
4 Correct 494 ms 60784 KB Output is correct