답안 #548621

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
548621 2022-04-14T02:29:30 Z Olympia Martian DNA (BOI18_dna) C++17
100 / 100
312 ms 7092 KB
#include <cmath>
#include <iostream>
#include <set>
#include <climits>
#include <algorithm>
#include <cassert>
#include <vector>
#include <iomanip>
#include <type_traits>
#include <string>
#include <queue>
#include <map>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef long long ll;

using namespace std;
template<class T>
class SegmentTree {
public:

    void resz (int N) {
        N = (1 << ((int)floor(log2(N - 1)) + 1));
        this->N = N;
        val.assign(2 * N, ID);
    }

    void update (int x, T y) {
        x += N - 1;
        val[x] = y;
        while (x != 0) {
            x = (x - 1)/2;
            val[x] = merge(val[2 * x + 1], val[2 * x + 2]);
        }
    }

    T query (int ind, const int l, const int r, int tl, int tr) {
        if (tl >= l && tr <= r) {
            return val[ind];
        }
        if (tr < l || tl > r) {
            return ID;
        }
        return merge(query(2 * ind + 1, l, r, tl, (tl + tr)/2), query(2 * ind + 2, l, r, (tl + tr)/2 + 1, tr));
    }

    T query (int l, int r) {
        return query(0, l, r, 0, N - 1);
    }
private:
    vector<T> val;
    T ID = 1;
    T merge (T x, T y) {
        return x & y;
    }
    int N;
};
vector<int> arr;
vector<pair<int,int>> queries;
SegmentTree<bool> valid;
vector<int> cnt;
map<int,int> myMap;
void updater (int x, int d) {
    if (!myMap.count(arr[x])) {
        return;
    }
    cnt[myMap[arr[x]]] += d;
    valid.update(myMap[arr[x]], cnt[myMap[arr[x]]] >= queries[myMap[arr[x]]].second);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, K, R;
    cin >> N >> K >> R;
    arr.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> arr[i];
    }
    queries.resize(R);
    for (int i = 0; i < R; i++) {
        cin >> queries[i].first >> queries[i].second;
        myMap[queries[i].first] = i;
    }
    cnt.resize(R);
    valid.resz(R);
    for (int i = 0; i < R; i++) {
        valid.update(i, 0);
    }
    int l = -1;
    int r = -1;
    int myMin = INT_MAX;
    while (l + 1 < N && r < N) {
        if (l != -1) {
            updater(l, -1);
        }
        l++;
        while (r != N - 1 && !valid.query(0, R - 1)) {
            updater(r + 1, 1);
            r++;
        }
        if (!valid.query(0, R - 1)) {
            break;
        }
        myMin = min(myMin, r - l + 1);
    }
    if (myMin == INT_MAX) {
        cout << "impossible\n";
    } else {
        cout << myMin;
    }
    //cout << ((myMin == INT_MAX) ? "impossible" : myMin);
}

Compilation message

dna.cpp:14: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   14 | #pragma GCC optimization ("O3")
      | 
dna.cpp:15: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   15 | #pragma GCC optimization ("unroll-loops")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 1108 KB Output is correct
2 Correct 15 ms 1108 KB Output is correct
3 Correct 31 ms 1108 KB Output is correct
4 Correct 36 ms 1108 KB Output is correct
5 Correct 29 ms 1108 KB Output is correct
6 Correct 28 ms 1108 KB Output is correct
7 Correct 16 ms 1108 KB Output is correct
8 Correct 23 ms 1108 KB Output is correct
9 Correct 21 ms 1108 KB Output is correct
10 Correct 33 ms 1108 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 288 ms 5824 KB Output is correct
2 Correct 312 ms 4636 KB Output is correct
3 Correct 117 ms 2284 KB Output is correct
4 Correct 15 ms 1108 KB Output is correct
5 Correct 176 ms 5708 KB Output is correct
6 Correct 299 ms 7092 KB Output is correct
7 Correct 119 ms 1492 KB Output is correct
8 Correct 168 ms 2004 KB Output is correct
9 Correct 25 ms 1108 KB Output is correct
10 Correct 17 ms 1108 KB Output is correct
11 Correct 34 ms 1108 KB Output is correct
12 Correct 27 ms 1108 KB Output is correct
13 Correct 22 ms 1108 KB Output is correct
14 Correct 23 ms 1108 KB Output is correct
15 Correct 16 ms 1108 KB Output is correct
16 Correct 24 ms 1108 KB Output is correct
17 Correct 22 ms 1108 KB Output is correct
18 Correct 30 ms 1108 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct