Submission #236699

#TimeUsernameProblemLanguageResultExecution timeMemory
236699MercenaryTeams (CEOI11_tea)C++14
100 / 100
494 ms86648 KiB
#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)

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 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...