답안 #483289

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
483289 2021-10-28T13:52:55 Z MohamedAliSaidane Martian DNA (BOI18_dna) C++14
100 / 100
61 ms 4060 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> ti;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ld,ld> pld;
#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front
#define ff first
#define ss second
#define MOD (int)(1e8)
#define INF (ll) (1e18)
ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;}
ll lcm(ll a , ll b) {return (a * b) / gcd(a , b);}
ld pointdist(ld x, ld y, ld point) { return ((x-point)*(y-point))/abs(x-y); }
ld dist(ld x, ld y, ld a, ld b){ return sqrt((x-a)*(x-a) + (y-b)*(y-b)); }
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //East, West, South, North
const int xcav[8] = {1,2,2,1,-1,-2,-2,-1};
const int ycav[8] = {-2,-1,1,2,2,1,-1,-2};
const int crapx[4] = {0,2,0,-2};
const int crapy[4] = {-2,0,2,0};
////////////******SOLUTION******\\\\\\\\\\\

const int MAX_N = 2e5 + 4;
int n, k, r;
vector<int> dna;
int m[MAX_N];

bool f(int x)
{
    int seen[k];
    memset(seen,0,sizeof(seen));
    int cnt = 0;
    for(int i = 0; i <x; i ++)
    {
        seen[dna[i]] ++;
        if(seen[dna[i]] == m[dna[i]])
            cnt ++;
    }
    if(cnt == r)
        return true;
    for(int i = x; i <n; i ++)
    {
        if(m[dna[i-x]] != -1)
        {
            seen[dna[i-x]] --;
            if(seen[dna[i-x]] == m[dna[i-x]] - 1)
                cnt --;
        }
        if(m[dna[i]] != -1)
        {
            seen[dna[i]] ++;
            if(seen[dna[i]] == m[dna[i]])
                cnt ++;
        }
        if(cnt == r)
            return true;
    }
    return false;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> k >> r;
    memset(m,-1,sizeof(m));
    for(int i = 0; i <n; i ++ )
    {
        int a; cin >> a;
        dna.pb(a);
    }
    for(int i = 0; i < r; i ++)
    {
        int a, b;
        cin >> a >> b;
        m[a] = b;
    }
    int ans = -1;
    int debut = 1;
    int fin = n;
    while(debut <= fin)
    {
        int mid = (debut + fin)/2;
        if(f(mid))
        {
            ans = mid;
            fin = mid - 1;
        }
        else
            debut = mid + 1;
    }
    if(ans == -1)
        cout << "impossible\n";
    else
        cout << ans << '\n';
}
/* Case that bugs my program:
5280
11
54 19 70 69 33 27 91 77 30 47 6
*/
/*
Identify problem diagram: Brute force, Greedy, Dynamic Programming, Divide and Conquer
Reformulate the problem into something more theoretical
Search for multiple approaches: select the seemingly optimal one
Remember that you're the king of CP
Change your approach
Imagine Corner cases before submitting
Don't spend too much time on the problem: move on !
*/

Compilation message

dna.cpp:28:1: warning: multi-line comment [-Wcomment]
   28 | ////////////******SOLUTION******\\\\\\\\\\\
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1100 KB Output is correct
2 Correct 1 ms 1088 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 1096 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 1096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1100 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
3 Correct 1 ms 1100 KB Output is correct
4 Correct 1 ms 1100 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 1100 KB Output is correct
7 Correct 1 ms 1100 KB Output is correct
8 Correct 1 ms 1100 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 1 ms 1100 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 1 ms 1088 KB Output is correct
13 Correct 1 ms 1100 KB Output is correct
14 Correct 1 ms 1100 KB Output is correct
15 Correct 1 ms 1096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 2636 KB Output is correct
2 Correct 34 ms 2632 KB Output is correct
3 Correct 20 ms 2652 KB Output is correct
4 Correct 31 ms 2592 KB Output is correct
5 Correct 31 ms 3548 KB Output is correct
6 Correct 20 ms 2636 KB Output is correct
7 Correct 21 ms 2764 KB Output is correct
8 Correct 27 ms 4036 KB Output is correct
9 Correct 19 ms 3120 KB Output is correct
10 Correct 27 ms 2636 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 1 ms 1100 KB Output is correct
13 Correct 1 ms 1100 KB Output is correct
14 Correct 1 ms 1100 KB Output is correct
15 Correct 1 ms 1100 KB Output is correct
16 Correct 1 ms 1100 KB Output is correct
17 Correct 1 ms 1100 KB Output is correct
18 Correct 1 ms 972 KB Output is correct
19 Correct 1 ms 972 KB Output is correct
20 Correct 1 ms 1092 KB Output is correct
21 Correct 1 ms 1100 KB Output is correct
22 Correct 1 ms 1100 KB Output is correct
23 Correct 1 ms 972 KB Output is correct
24 Correct 1 ms 1100 KB Output is correct
25 Correct 1 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 4060 KB Output is correct
2 Correct 40 ms 3392 KB Output is correct
3 Correct 38 ms 3420 KB Output is correct
4 Correct 11 ms 2660 KB Output is correct
5 Correct 46 ms 3552 KB Output is correct
6 Correct 61 ms 3908 KB Output is correct
7 Correct 37 ms 3148 KB Output is correct
8 Correct 50 ms 3228 KB Output is correct
9 Correct 25 ms 2636 KB Output is correct
10 Correct 31 ms 2624 KB Output is correct
11 Correct 17 ms 2636 KB Output is correct
12 Correct 25 ms 2636 KB Output is correct
13 Correct 27 ms 3396 KB Output is correct
14 Correct 23 ms 2636 KB Output is correct
15 Correct 22 ms 2796 KB Output is correct
16 Correct 35 ms 4036 KB Output is correct
17 Correct 20 ms 3148 KB Output is correct
18 Correct 28 ms 2636 KB Output is correct
19 Correct 2 ms 1100 KB Output is correct
20 Correct 2 ms 1100 KB Output is correct
21 Correct 2 ms 1100 KB Output is correct
22 Correct 1 ms 1100 KB Output is correct
23 Correct 1 ms 1100 KB Output is correct
24 Correct 1 ms 1100 KB Output is correct
25 Correct 1 ms 972 KB Output is correct
26 Correct 1 ms 1100 KB Output is correct
27 Correct 1 ms 1100 KB Output is correct
28 Correct 1 ms 972 KB Output is correct
29 Correct 1 ms 1088 KB Output is correct
30 Correct 1 ms 1088 KB Output is correct
31 Correct 1 ms 972 KB Output is correct
32 Correct 1 ms 972 KB Output is correct
33 Correct 1 ms 972 KB Output is correct