답안 #482466

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
482466 2021-10-24T15:50:45 Z SamAnd Martian DNA (BOI18_dna) C++17
100 / 100
116 ms 19524 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
 
int n, k, r;
int a[N];
int b[N];
vector<int> v[N];
int j[N];
 
int main()
{
    scanf("%d%d%d", &n, &k, &r);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    while (r--)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        b[x] = y;
    }
    for (int i = 1; i <= n; ++i)
        v[a[i]].push_back(i);
    set<int> s;
    for (int i = 0; i < k; ++i)
    {
        if (!b[i])
            continue;
        if (v[i].size() < b[i])
        {
            printf("impossible\n");
            return 0;
        }
        j[i] = b[i] - 1;
        s.insert(v[i][b[i] - 1]);
    }
    int ans = (*(--s.end()));
    for (int i = 2; i <= n; ++i)
    {
        if (b[a[i - 1]])
        {
            s.erase(v[a[i - 1]][j[a[i - 1]]]);
            ++j[a[i - 1]];
            if (!(j[a[i - 1]] < v[a[i - 1]].size()))
                break;
            s.insert(v[a[i - 1]][j[a[i - 1]]]);
        }
        ans = min(ans, (*(--s.end())) - i + 1);
    }
    printf("%d\n", ans);
    return 0;
}

Compilation message

dna.cpp: In function 'int main()':
dna.cpp:29:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |         if (v[i].size() < b[i])
      |             ~~~~~~~~~~~~^~~~~~
dna.cpp:44:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |             if (!(j[a[i - 1]] < v[a[i - 1]].size()))
      |                   ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
dna.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%d%d%d", &n, &k, &r);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
dna.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
dna.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         scanf("%d%d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 5008 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 5068 KB Output is correct
3 Correct 4 ms 5068 KB Output is correct
4 Correct 3 ms 5140 KB Output is correct
5 Correct 4 ms 5016 KB Output is correct
6 Correct 5 ms 5068 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 2 ms 4940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 7452 KB Output is correct
2 Correct 25 ms 7348 KB Output is correct
3 Correct 31 ms 7216 KB Output is correct
4 Correct 26 ms 7440 KB Output is correct
5 Correct 40 ms 9588 KB Output is correct
6 Correct 20 ms 7296 KB Output is correct
7 Correct 21 ms 7296 KB Output is correct
8 Correct 47 ms 13264 KB Output is correct
9 Correct 31 ms 8140 KB Output is correct
10 Correct 29 ms 7372 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 5 ms 5068 KB Output is correct
13 Correct 4 ms 5068 KB Output is correct
14 Correct 3 ms 5196 KB Output is correct
15 Correct 4 ms 5068 KB Output is correct
16 Correct 4 ms 5068 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
19 Correct 4 ms 5048 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 3 ms 4952 KB Output is correct
23 Correct 4 ms 4940 KB Output is correct
24 Correct 4 ms 4984 KB Output is correct
25 Correct 3 ms 5000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 14352 KB Output is correct
2 Correct 80 ms 12612 KB Output is correct
3 Correct 46 ms 10448 KB Output is correct
4 Correct 27 ms 7324 KB Output is correct
5 Correct 70 ms 11476 KB Output is correct
6 Correct 116 ms 19524 KB Output is correct
7 Correct 32 ms 8388 KB Output is correct
8 Correct 57 ms 9276 KB Output is correct
9 Correct 30 ms 7448 KB Output is correct
10 Correct 25 ms 7380 KB Output is correct
11 Correct 31 ms 7244 KB Output is correct
12 Correct 35 ms 7500 KB Output is correct
13 Correct 32 ms 9624 KB Output is correct
14 Correct 20 ms 7284 KB Output is correct
15 Correct 20 ms 7372 KB Output is correct
16 Correct 49 ms 13404 KB Output is correct
17 Correct 26 ms 8096 KB Output is correct
18 Correct 30 ms 7372 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 3 ms 5068 KB Output is correct
21 Correct 3 ms 5068 KB Output is correct
22 Correct 3 ms 5196 KB Output is correct
23 Correct 4 ms 5068 KB Output is correct
24 Correct 3 ms 5068 KB Output is correct
25 Correct 3 ms 4940 KB Output is correct
26 Correct 3 ms 4940 KB Output is correct
27 Correct 3 ms 4940 KB Output is correct
28 Correct 3 ms 4940 KB Output is correct
29 Correct 2 ms 4940 KB Output is correct
30 Correct 3 ms 4952 KB Output is correct
31 Correct 3 ms 5004 KB Output is correct
32 Correct 3 ms 4940 KB Output is correct
33 Correct 3 ms 4940 KB Output is correct