답안 #656843

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
656843 2022-11-08T09:45:21 Z jcelin Martian DNA (BOI18_dna) C++14
100 / 100
109 ms 19848 KB
#include <bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define ii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vii vector<ii>
#define vll vector<ll>
#define vpll vector<pll>
#define matrix vector<vi>
#define matrixLL vector<vll>
#define vs vector<string>
#define vui vector<ui>
#define msi multiset<int>
#define mss multiset<string>
#define si set<int>
#define ss set<string>
#define PB push_back
#define PF push_front
#define PPB pop_back
#define PPF pop_front
#define X first
#define Y second
#define MP make_pair
#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()

const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const int dxx[] = {-1, 1, 0, 0, 1, 1, -1, -1};
const int dyy[] = {0, 0, -1, 1, -1, 1, -1, 1};
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ld pi = 3.14159265;
const int mod = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 7;
const int inf = mod;
const ll INF = 1e18;
const ll zero = ll(0);
const int logo = 20;
const int off = 1 << logo;
const int trsz = off << 1;

vi ind[MAXN];
int req[MAXN];
int arr[MAXN];
set<int> cur;

//prvi
int point[MAXN];

void solve(){
	int n, r, k;
	cin >> n >> k >> r;
	for(int i=0; i<n; i++){
		int x;
		cin >> x;
		arr[i] = x; 
		ind[x].PB(i);
	}
	
	for(int i=0; i<r; i++){
		int a, b;
		cin >> a >> b;
		req[a] = b;
	}
	
	
	
	for(int i=0; i<k; i++){
		if(req[i] > ind[i].size()){
			cout << "impossible\n";
			return;
		}
		
		for(int j=0; j<req[i]; j++) cur.insert(ind[i][j]);
		point[i] = req[i] - 1;
	}
	
	int ans = 0;
	if(cur.size()) ans = *(--cur.end()) - *cur.begin();
	
	
	for(int i=1; i<n; i++){
		int pre = arr[i - 1];
		if(req[pre] == 0) continue;
		
		cur.erase(i - 1);
		if(point[pre] >= ind[pre].size() - 1) break;
		point[pre]++;
		cur.insert(ind[pre][point[pre]]);
		if(cur.size()) ans = min(ans, *(--cur.end()) - *cur.begin());
	}
	
	cout << ans + 1 << "\n";
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
	//cin >> t;
	while(t--)solve();
	return 0;
}






Compilation message

dna.cpp: In function 'void solve()':
dna.cpp:81:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |   if(req[i] > ind[i].size()){
      |      ~~~~~~~^~~~~~~~~~~~~~~
dna.cpp:99:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |   if(point[pre] >= ind[pre].size() - 1) break;
      |      ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 5032 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5036 KB Output is correct
2 Correct 5 ms 5076 KB Output is correct
3 Correct 4 ms 5176 KB Output is correct
4 Correct 3 ms 5204 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 5032 KB Output is correct
9 Correct 3 ms 5028 KB Output is correct
10 Correct 3 ms 5032 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5032 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 11312 KB Output is correct
2 Correct 49 ms 8856 KB Output is correct
3 Correct 32 ms 7124 KB Output is correct
4 Correct 39 ms 10028 KB Output is correct
5 Correct 30 ms 9972 KB Output is correct
6 Correct 47 ms 16664 KB Output is correct
7 Correct 14 ms 7292 KB Output is correct
8 Correct 44 ms 14136 KB Output is correct
9 Correct 26 ms 8192 KB Output is correct
10 Correct 54 ms 10720 KB Output is correct
11 Correct 3 ms 5040 KB Output is correct
12 Correct 3 ms 5168 KB Output is correct
13 Correct 3 ms 5172 KB Output is correct
14 Correct 4 ms 5204 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 3 ms 5076 KB Output is correct
17 Correct 3 ms 5020 KB Output is correct
18 Correct 3 ms 5032 KB Output is correct
19 Correct 3 ms 5032 KB Output is correct
20 Correct 3 ms 5032 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 5032 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 14452 KB Output is correct
2 Correct 76 ms 12652 KB Output is correct
3 Correct 46 ms 10436 KB Output is correct
4 Correct 18 ms 7152 KB Output is correct
5 Correct 49 ms 11456 KB Output is correct
6 Correct 109 ms 19848 KB Output is correct
7 Correct 62 ms 11808 KB Output is correct
8 Correct 58 ms 10684 KB Output is correct
9 Correct 38 ms 11348 KB Output is correct
10 Correct 50 ms 8828 KB Output is correct
11 Correct 31 ms 7124 KB Output is correct
12 Correct 38 ms 10064 KB Output is correct
13 Correct 30 ms 9872 KB Output is correct
14 Correct 51 ms 16656 KB Output is correct
15 Correct 16 ms 7344 KB Output is correct
16 Correct 44 ms 14088 KB Output is correct
17 Correct 23 ms 8108 KB Output is correct
18 Correct 45 ms 10604 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
20 Correct 4 ms 5176 KB Output is correct
21 Correct 3 ms 5172 KB Output is correct
22 Correct 3 ms 5172 KB Output is correct
23 Correct 3 ms 5076 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 2 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
29 Correct 2 ms 5032 KB Output is correct
30 Correct 3 ms 4948 KB Output is correct
31 Correct 3 ms 4948 KB Output is correct
32 Correct 3 ms 4956 KB Output is correct
33 Correct 3 ms 4948 KB Output is correct