Submission #648884

#TimeUsernameProblemLanguageResultExecution timeMemory
648884messiuuuuuTeams (CEOI11_tea)C++14
100 / 100
457 ms32544 KiB
/// #include<bits/stdc++.h> #define task "C" #define ll long long #define ld long double #define fi first #define se second #define pb push_back using namespace std; const int MAXN = 1e6 + 5; const ll INF = 1e9 + 5; int n, a[MAXN]; void Input() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; } int cs[MAXN]; int dp[MAXN], last[MAXN], tsz[MAXN]; int Cal(int lim) { dp[n] = 0; for (int i = 1; i <= n; i++) { int x = a[cs[i]]; if (i < x || (dp[last[i - x]] + 1 < dp[last[i - 1]] && i < n)) { last[i] = last[i - 1]; } else { int sz = i - last[i - x]; int newdp = dp[last[i - x]] + 1; if (sz <= lim && (i == n || newdp >= dp[last[i - 1]])) { last[i] = i; dp[i] = newdp; tsz[i] = sz; } else { last[i] = last[i - 1]; } } } return dp[n]; } void Solve() { iota(cs + 1, cs + n + 1, 1); sort(cs + 1, cs + n + 1, [](int i, int j) { return a[i] < a[j]; }); int t = Cal(n); int l = 1, r = n; while (l <= r) { int mid = (l + r) >> 1; if (Cal(mid) == t) { r = mid - 1; } else { l = mid + 1; } } Cal(l); cout << dp[n] << '\n'; int p = n; while (p > 0) { int sz = tsz[p]; cout << sz << ' '; for (int i = 0; i < sz; i++, p--) { cout << cs[p] << ' '; } cout << '\n'; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen(task".INP","r")) { freopen(task".INP","r",stdin); //freopen(task".OUT","w",stdout); } Input(); Solve(); }

Compilation message (stderr)

tea.cpp: In function 'int main()':
tea.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...