This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define INF LLONG_MAX
#define pii pair<int, int>
using namespace std;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, k, r;
cin >> n >> k >> r;
vector<vector<int>> pos(k);
vector<int> dna(n);
for (int i = 0; i < n; i++)
{
cin >> dna[i];
pos[dna[i]].push_back(i);
}
vector<int> maxx(n, 0);
for (int i = 0; i < r; i++)
{
int nucleo, num;
cin >> nucleo >> num;
if (pos[nucleo].size() < num)
{
cout << "impossible" << endl;
return 0;
}
for (int j = 0; j < n; j++)
{
int idx = lower_bound(pos[nucleo].begin(), pos[nucleo].end(), j) - pos[nucleo].begin();
if (idx + num - 1 < pos[nucleo].size())
maxx[j] = max(maxx[j], pos[nucleo][idx + num - 1] - j + 1);
else
maxx[j] = INF;
}
}
cout << *min_element(maxx.begin(), maxx.end()) << endl;
return 0;
}
Compilation message (stderr)
dna.cpp: In function 'int32_t main()':
dna.cpp:27:34: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
27 | if (pos[nucleo].size() < num)
| ~~~~~~~~~~~~~~~~~~~^~~~~
dna.cpp:35:34: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | if (idx + num - 1 < pos[nucleo].size())
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |