Submission #333560

# Submission time Handle Problem Language Result Execution time Memory
333560 2020-12-07T04:35:35 Z mohamedsobhi777 Martian DNA (BOI18_dna) C++14
100 / 100
118 ms 19820 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#pragma GCC optimize("-Ofast")
//#pragma GCC optimize("trapv")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")

using namespace std;
using namespace __gnu_pbds;

#define vi vector<int>
#define vii vector<pair<int, int>>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define loop(_) for (int __ = 0; __ < (_); ++__)
#define forn(i, n) for (int i = 0; i < n; ++i)
#define pb push_back
#define f first
#define s second
#define sz(_) ((int)_.size())
#define all(_) _.begin(), _.end()
#define uni(_) unique(_)
#define lb lower_bound
#define ub upper_bound
#define si set<int>
#define ms multiset<int>
#define qi queue<int>
#define pq prioriry_queue<int>

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

const int N = 2e5 + 7000;
const ll mod = 1e9 + 7;
const ll inf = 2e18;

auto ra = [] {char *p = new char ; delete p ; return ll(p) ; };
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count() * (ra() | 1));
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> os;

int n, k, r;
int a[N];
int R[N];
int sz[N];
vector<int> adj[N];

int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        //freopen("in.in", "r", stdin);
        cin >> n >> k >> r;
        for (int i = 0; i < n; ++i)
        {
                cin >> a[i];
                adj[a[i]].push_back(i);
        }
        for (int i = 0; i < r; ++i)
        {
                int x, y;
                cin >> x >> y;
                R[x] = y;
        }
        int bad = r;
        int ans = 1e9;
        set<int> st;
        for (int i = 0; i < n; ++i)
        {
                ++sz[a[i]];
                if (R[a[i]] == sz[a[i]])
                {
                        --bad;
                        st.insert(adj[a[i]][0]);
                }
                else if (sz[a[i]] > R[a[i]] && R[a[i]])
                {
                        st.erase(adj[a[i]][sz[a[i]] - R[a[i]] - 1]);
                        st.insert(adj[a[i]][sz[a[i]] - R[a[i]]]);
                }
                if (bad == 0)
                        ans = min(ans, i - (*st.begin()) + 1);
        }
        if (ans == 1e9)
                cout << "impossible";
        else
                cout << ans;
        return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5228 KB Output is correct
2 Correct 3 ms 5228 KB Output is correct
3 Correct 3 ms 5228 KB Output is correct
4 Correct 4 ms 5248 KB Output is correct
5 Correct 4 ms 5240 KB Output is correct
6 Correct 3 ms 5248 KB Output is correct
7 Correct 4 ms 5228 KB Output is correct
8 Correct 3 ms 5228 KB Output is correct
9 Correct 3 ms 5228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5228 KB Output is correct
2 Correct 4 ms 5228 KB Output is correct
3 Correct 5 ms 5356 KB Output is correct
4 Correct 5 ms 5356 KB Output is correct
5 Correct 4 ms 5356 KB Output is correct
6 Correct 4 ms 5228 KB Output is correct
7 Correct 4 ms 5228 KB Output is correct
8 Correct 4 ms 5228 KB Output is correct
9 Correct 4 ms 5228 KB Output is correct
10 Correct 4 ms 5228 KB Output is correct
11 Correct 4 ms 5228 KB Output is correct
12 Correct 4 ms 5228 KB Output is correct
13 Correct 4 ms 5228 KB Output is correct
14 Correct 4 ms 5356 KB Output is correct
15 Correct 4 ms 5228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 7788 KB Output is correct
2 Correct 27 ms 7592 KB Output is correct
3 Correct 29 ms 7400 KB Output is correct
4 Correct 28 ms 7748 KB Output is correct
5 Correct 42 ms 10268 KB Output is correct
6 Correct 19 ms 7660 KB Output is correct
7 Correct 22 ms 7532 KB Output is correct
8 Correct 68 ms 14444 KB Output is correct
9 Correct 30 ms 8428 KB Output is correct
10 Correct 31 ms 7564 KB Output is correct
11 Correct 4 ms 5228 KB Output is correct
12 Correct 4 ms 5228 KB Output is correct
13 Correct 5 ms 5356 KB Output is correct
14 Correct 5 ms 5356 KB Output is correct
15 Correct 4 ms 5356 KB Output is correct
16 Correct 6 ms 5228 KB Output is correct
17 Correct 4 ms 5228 KB Output is correct
18 Correct 4 ms 5228 KB Output is correct
19 Correct 4 ms 5248 KB Output is correct
20 Correct 4 ms 5228 KB Output is correct
21 Correct 4 ms 5228 KB Output is correct
22 Correct 4 ms 5248 KB Output is correct
23 Correct 4 ms 5228 KB Output is correct
24 Correct 4 ms 5228 KB Output is correct
25 Correct 4 ms 5228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 105 ms 14700 KB Output is correct
2 Correct 90 ms 12908 KB Output is correct
3 Correct 54 ms 10732 KB Output is correct
4 Correct 27 ms 7348 KB Output is correct
5 Correct 72 ms 12140 KB Output is correct
6 Correct 118 ms 19820 KB Output is correct
7 Correct 80 ms 8684 KB Output is correct
8 Correct 104 ms 9580 KB Output is correct
9 Correct 25 ms 7788 KB Output is correct
10 Correct 27 ms 7592 KB Output is correct
11 Correct 29 ms 7400 KB Output is correct
12 Correct 27 ms 7748 KB Output is correct
13 Correct 42 ms 10092 KB Output is correct
14 Correct 19 ms 7660 KB Output is correct
15 Correct 22 ms 7532 KB Output is correct
16 Correct 68 ms 14316 KB Output is correct
17 Correct 31 ms 8428 KB Output is correct
18 Correct 30 ms 7564 KB Output is correct
19 Correct 4 ms 5228 KB Output is correct
20 Correct 5 ms 5228 KB Output is correct
21 Correct 5 ms 5356 KB Output is correct
22 Correct 5 ms 5356 KB Output is correct
23 Correct 5 ms 5356 KB Output is correct
24 Correct 5 ms 5228 KB Output is correct
25 Correct 4 ms 5228 KB Output is correct
26 Correct 4 ms 5228 KB Output is correct
27 Correct 4 ms 5228 KB Output is correct
28 Correct 4 ms 5228 KB Output is correct
29 Correct 4 ms 5228 KB Output is correct
30 Correct 4 ms 5228 KB Output is correct
31 Correct 4 ms 5228 KB Output is correct
32 Correct 4 ms 5228 KB Output is correct
33 Correct 4 ms 5228 KB Output is correct