Submission #1076959

# Submission time Handle Problem Language Result Execution time Memory
1076959 2024-08-26T19:49:46 Z andrei_iorgulescu Tortoise (CEOI21_tortoise) C++14
8 / 100
206 ms 600 KB
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;

//#ifndef DLOCAL
//   #define cin fin
//   #define cout fout
//   ifstream cin(".in");
//   ofstream cout(".out");
//#endif

using ll = long long;
using ld = long double;

#define int ll
#define sz(x) ((int)(x).size())

using pii = pair<int,int>;
using tii = tuple<int,int,int>;

const int nmax = 5e5 + 5;

int Ld[nmax], Rd[nmax];
int v[nmax];

bool possible(multiset<int> s)
{
    int last = -1, timer = 0;
    for(auto x : s)
    {
        if(last == -1)
        {
            timer += x - 1;
        }
        else
        {
            if(Ld[last] != Ld[x] || Rd[last] != Rd[x])
                timer += x - last;
            else timer += min(last - Ld[last] + x - Ld[last], Rd[last] - last + Rd[last] - x);
        }
        if(timer > 2 * (x - 1))
        {
            return 0;
        }
        last = x;
        //cerr << timer << '\n';
    }
    //cerr << '\n';
    //for(auto x: s) cerr << x << ' '; cerr << '\n';
    //cerr << "ok\n";
    return 1;
}

signed main()
{
    cin.tie(0) -> sync_with_stdio(0);
    int n;
    cin >> n;

    ll cost = 0;
    for(int i = 1; i <= n; i++)
        cin >> v[i], cost += (v[i] != -1? v[i] : 0);
    for(int lst = -1e9 - 5, i = 1; i <= n; i++)
    {
        if(v[i] == -1) lst = i;
        else Ld[i] = lst;
    }
    for(int lst = 1e9 + 5, i = n; i > 0; i--)
    {
        if(v[i] == -1) lst = i;
        else Rd[i] = lst;
    }

    vector<vector<int>> idxs(n + 1);
    multiset<int> sofar;

    for(int i = 1; i <= n; i++)
    {
        if(v[i] == -1) continue;
        idxs[min(Rd[i] - i, i - Ld[i])].emplace_back(i);
    }

    ll szm = 0;

    srand(time(NULL));
    for(int i = 0; i < 1000; i++)
    {
        for (auto it : sofar)
            v[it]++;
        sofar.clear();
        int itr = 0;
        vector<int> V;
        for(auto &T : idxs)
        {
            for (auto itt : T)
                V.push_back(itt);
            itr++;

            //sort(all(T), greater<int>());
            if (itr % (1 + rand() % 3) == 0)
            {
                shuffle(V.begin(), V.end(), default_random_engine(rand()));
                for(auto x : V)
                {
                    while(v[x] > 0)
                    {
                        sofar.emplace(x);
                        if(possible(sofar)) v[x]--;
                        else
                        {
                            sofar.erase(sofar.find(x));
                            break;
                        }
                    }
                }
                V.clear();
            }

        }
        shuffle(V.begin(), V.end(), default_random_engine(rand()));
        for(auto x : V)
        {
            while(v[x] > 0)
            {
                sofar.emplace(x);
                if(possible(sofar)) v[x]--;
                else
                {
                    sofar.erase(sofar.find(x));
                    break;
                }
            }
        }
        szm = max(szm, (ll)sofar.size());
    }



    cout << cost - szm << '\n';

}

/**
      Töte es durch genaue Untersuchung\Töte es kann es nur noch schlimmer machen\Es lässt es irgendwie atmen
--
*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 480 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 484 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 480 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 484 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 131 ms 344 KB Output is correct
28 Correct 206 ms 344 KB Output is correct
29 Correct 183 ms 592 KB Output is correct
30 Correct 146 ms 348 KB Output is correct
31 Correct 144 ms 348 KB Output is correct
32 Correct 104 ms 344 KB Output is correct
33 Correct 153 ms 476 KB Output is correct
34 Correct 140 ms 480 KB Output is correct
35 Correct 120 ms 344 KB Output is correct
36 Correct 115 ms 344 KB Output is correct
37 Correct 135 ms 600 KB Output is correct
38 Incorrect 129 ms 348 KB Output isn't correct
39 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 480 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 484 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 131 ms 344 KB Output is correct
28 Correct 206 ms 344 KB Output is correct
29 Correct 183 ms 592 KB Output is correct
30 Correct 146 ms 348 KB Output is correct
31 Correct 144 ms 348 KB Output is correct
32 Correct 104 ms 344 KB Output is correct
33 Correct 153 ms 476 KB Output is correct
34 Correct 140 ms 480 KB Output is correct
35 Correct 120 ms 344 KB Output is correct
36 Correct 115 ms 344 KB Output is correct
37 Correct 135 ms 600 KB Output is correct
38 Incorrect 129 ms 348 KB Output isn't correct
39 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 480 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 484 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 131 ms 344 KB Output is correct
28 Correct 206 ms 344 KB Output is correct
29 Correct 183 ms 592 KB Output is correct
30 Correct 146 ms 348 KB Output is correct
31 Correct 144 ms 348 KB Output is correct
32 Correct 104 ms 344 KB Output is correct
33 Correct 153 ms 476 KB Output is correct
34 Correct 140 ms 480 KB Output is correct
35 Correct 120 ms 344 KB Output is correct
36 Correct 115 ms 344 KB Output is correct
37 Correct 135 ms 600 KB Output is correct
38 Incorrect 129 ms 348 KB Output isn't correct
39 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 480 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 484 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 131 ms 344 KB Output is correct
28 Correct 206 ms 344 KB Output is correct
29 Correct 183 ms 592 KB Output is correct
30 Correct 146 ms 348 KB Output is correct
31 Correct 144 ms 348 KB Output is correct
32 Correct 104 ms 344 KB Output is correct
33 Correct 153 ms 476 KB Output is correct
34 Correct 140 ms 480 KB Output is correct
35 Correct 120 ms 344 KB Output is correct
36 Correct 115 ms 344 KB Output is correct
37 Correct 135 ms 600 KB Output is correct
38 Incorrect 129 ms 348 KB Output isn't correct
39 Halted 0 ms 0 KB -