Submission #752896

# Submission time Handle Problem Language Result Execution time Memory
752896 2023-06-04T08:13:59 Z I_love_Hoang_Yen Sequence (APIO23_sequence) C++17
28 / 100
676 ms 4184 KB
#include "sequence.h"
#include <bits/stdc++.h>
#define SZ(s) ((int) ((s).size()))
using namespace std;

vector<int> medians(const vector<int> values) {
    int n = SZ(values);
    assert(n > 0);
    if (n % 2 == 0) {
        return {values[n/2 - 1], values[n / 2]};
    } else {
        return {values[n/2]};
    }
}

int sub1(const vector<int>& a) {
    int n = SZ(a);
    int res = 0;
    for (int l = 0; l < n; ++l) {
        for (int r = l; r < n; ++r) {
            vector<int> b(a.begin() + l, a.begin() + r + 1);

            unordered_map<int, int> cnt;
            for (int val : b) cnt[val] += 1;

            sort(b.begin(), b.end());
            auto meds = medians(b);
            for (int med : meds) {
                res = max(res, cnt[med]);
            }
        }
    }
    return res;
}

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

using namespace __gnu_pbds;

int sub2(const vector<int>& a) {
    int n = SZ(a);
    int res = 0;
    for (int l = 0; l < n; ++l) {
        unordered_map<int, int> cnt;
        ordered_set values;
        for (int r = l; r < n; ++r) {
            cnt[a[r]]++;
            values.insert(a[r]);

            int k = SZ(values);
            if (k % 2 == 0) {
                res = max(res, cnt[*values.find_by_order(k / 2 - 1)]);
                res = max(res, cnt[*values.find_by_order(k / 2)]);
            } else {
                res = max(res, cnt[*values.find_by_order(k / 2)]);
            }
        }
    }
    return res;
}

int sequence(int n, std::vector<int> a) {
    if (n <= 2000) return sub2(a);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 292 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 3 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 2 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 292 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 3 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 2 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 665 ms 468 KB Output is correct
14 Correct 652 ms 468 KB Output is correct
15 Correct 454 ms 388 KB Output is correct
16 Correct 457 ms 388 KB Output is correct
17 Correct 443 ms 384 KB Output is correct
18 Correct 523 ms 480 KB Output is correct
19 Correct 657 ms 440 KB Output is correct
20 Correct 646 ms 440 KB Output is correct
21 Correct 664 ms 440 KB Output is correct
22 Correct 676 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 46 ms 4168 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 51 ms 4184 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 4180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 292 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 3 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 2 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 665 ms 468 KB Output is correct
14 Correct 652 ms 468 KB Output is correct
15 Correct 454 ms 388 KB Output is correct
16 Correct 457 ms 388 KB Output is correct
17 Correct 443 ms 384 KB Output is correct
18 Correct 523 ms 480 KB Output is correct
19 Correct 657 ms 440 KB Output is correct
20 Correct 646 ms 440 KB Output is correct
21 Correct 664 ms 440 KB Output is correct
22 Correct 676 ms 440 KB Output is correct
23 Incorrect 6 ms 852 KB Output isn't correct
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 292 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 3 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 2 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 665 ms 468 KB Output is correct
14 Correct 652 ms 468 KB Output is correct
15 Correct 454 ms 388 KB Output is correct
16 Correct 457 ms 388 KB Output is correct
17 Correct 443 ms 384 KB Output is correct
18 Correct 523 ms 480 KB Output is correct
19 Correct 657 ms 440 KB Output is correct
20 Correct 646 ms 440 KB Output is correct
21 Correct 664 ms 440 KB Output is correct
22 Correct 676 ms 440 KB Output is correct
23 Incorrect 46 ms 4168 KB Output isn't correct
24 Halted 0 ms 0 KB -