Submission #395209

# Submission time Handle Problem Language Result Execution time Memory
395209 2021-04-28T02:25:55 Z ak2006 Teams (CEOI11_tea) C++14
50 / 100
75 ms 66804 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
const ll mod = 1e9 + 7,inf = 1e18;
#define pb push_back
#define flash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n;
int main()
{
    flash;
    cin>>n;
    vvi a(n + 1,vi(2));
    vi dp1(n + 1),dp2(n + 1),p(n + 1);
    if (n <= 5e3){

        for (int i = 1;i<=n;i++)cin>>a[i][0],a[i][1] = i;

        sort(a.begin() + 1,a.end());
        dp1[0] = 0,dp2[0] = 0;

        for (int i = 1;i<=n;i++){
            if (a[i][0] > i){dp1[i] = 0,dp2[i] = -1e9;continue;}
            dp1[i] = 1,dp2[i] = i;
            p[i] = 0;
            for (int j = i - a[i][0];j>=1;j--){
                if (dp1[i] < dp1[j] + 1){
                    dp1[i] = dp1[j] + 1;
                    dp2[i] = max(i - j,dp2[j]);
                    p[i] = j;
                }
                else if (dp1[j] + 1 == dp1[i] && dp2[j] != -1e9){
                    if (dp2[i] > max(i - j,dp2[j])){
                        dp2[i] = max(i - j,dp2[j]);
                        p[i] = j;
                    }
                }
            }
        }
        cout<<dp1[n]<<endl;
        int i = n;
        while (i > 0){
            int j = p[i];
            vi cur;
            for (;i>j;i--)
                cur.pb(a[i][1]);
            cout<<cur.size()<<" ";
            for (auto it:cur)cout<<it<<" ";
            cout<<'\n';
        }
    }
    else return -1;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 656 KB Output is correct
2 Correct 12 ms 664 KB Output is correct
3 Correct 13 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 588 KB Output is correct
2 Correct 11 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 5596 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 6220 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 54 ms 50112 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 72 ms 66804 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 75 ms 66788 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -