Submission #648673

# Submission time Handle Problem Language Result Execution time Memory
648673 2022-10-07T12:44:18 Z messiuuuuu Teams (CEOI11_tea) C++14
50 / 100
2500 ms 12344 KB
///
#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];
}

pair<int, int> dp[MAXN];
int cs[MAXN], trace[MAXN];

bool upd(pair<int, int>& a, const pair<int, int>& b)
{
    if (a.fi < b.fi || (a.fi == b.fi && a.se > b.se))
    {
        a = b;
        return 1;
    }
    return 0;
}

void Solve()
{
    iota(cs + 1, cs + n + 1, 1);
    sort(cs + 1, cs + n + 1, [](int i, int j)
         {
             return a[i] < a[j];
         });
    for (int i = 1; i <= n; i++)
    {
        dp[i] = {0, INF};
        for (int j = i - a[cs[i]] + 1; j >= 1; j--)
        {
            if (upd(dp[i], {dp[j - 1].fi + 1, max(dp[j - 1].se, i - j + 1)}))
            {
                trace[i] = j;
            }
        }
    }
    cout << dp[n].fi << '\n';
    int i = n;
    while (i > 0)
    {
        int j = trace[i];
        cout << i - j + 1 << ' ';
        for (; i >= j; i--)
            cout << cs[i] << ' ';
        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

tea.cpp: In function 'int main()':
tea.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 468 KB Output is correct
2 Correct 15 ms 464 KB Output is correct
3 Correct 16 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 468 KB Output is correct
2 Correct 11 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2360 ms 2556 KB Output is correct
2 Execution timed out 2560 ms 2220 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2582 ms 2112 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2579 ms 7272 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2587 ms 9620 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2577 ms 12344 KB Time limit exceeded
2 Halted 0 ms 0 KB -