# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
674638 |
2022-12-25T14:38:51 Z |
tamthegod |
Teams (CEOI11_tea) |
C++14 |
|
2500 ms |
115748 KB |
// Make the best become better
// No room for laziness
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e6 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n, a[maxN], id[maxN];
int f[maxN], trace[maxN];
int pos[maxN];
int dp[maxN];
void ReadInput()
{
cin >> n;
for(int i=1; i<=n; i++)
cin >> a[i];
}
bool chk(int val)
{
memset(f, -3, sizeof f);
dp[0] = 0;
for(int i=1; i<=n; i++)
{
int t = id[i];
for(int j=i-a[t]+1; j>=i-val+1; j--)
{
if(dp[i] < dp[j - 1] + 1)
{
dp[i] = dp[j - 1] + 1;
trace[i] = j;
}
}
}
return dp[n] == f[n];
}
void Print(int val)
{
memset(f, -3, sizeof f);
f[0] = 0;
for(int i=1; i<=n; i++)
{
int t = id[i];
for(int j=i-a[t]+1; j>=i-val; j--)
{
if(f[i] < f[j - 1] + 1)
{
f[i] = f[j - 1] + 1;
trace[i] = j;
}
}
}
cout << f[n] << '\n';
int i = n;
while(i)
{
cout << i - trace[i] + 1 << " ";
for(int j=i; j>=trace[i]; j--)
cout << id[j] << " ";
i = trace[i] - 1;
cout << '\n';
}
}
void Solve()
{
iota(id + 1, id + n + 1, 1);
sort(id + 1, id + n + 1, [](int i, int j)
{
return a[i] < a[j];
});
int low = a[id[n]], high = n, mid;
while(low <= high)
{
mid = (low + high) / 2;
if(chk(mid)) high = mid - 1;
else low = mid + 1;
}
Print(low);
}
int32_t main()
{
//freopen("x.inp", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ReadInput();
Solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8148 KB |
Output is correct |
2 |
Execution timed out |
2598 ms |
115748 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2584 ms |
114004 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2584 ms |
114112 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2568 ms |
106668 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2590 ms |
106016 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
25 ms |
18900 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
114 ms |
19276 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
128 ms |
40088 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
175 ms |
48008 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
189 ms |
47956 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |