답안 #967966

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
967966 2024-04-23T06:08:49 Z willychan Binaria (CCO23_day1problem1) C++17
18 / 25
823 ms 1048576 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
const int MOD = 1e6+3;

struct dsu{
	vector<int> arr;
	int n;
	void init(int _n){
		 n = _n;	
		 arr.resize(n);
		 for(int i=0;i<n;i++) arr[i]=i;
	}
	int query(int a){
		if(arr[a]==a) return a;
		arr[a] = query(arr[a]);
		return arr[a];
	}
	void join(int a,int b){
		a = query(a);
		b = query(b);
		if(a!=b) arr[a]=b;
	}
};

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n,k;cin>>n>>k;	
	vector<int> arr(n-k+1);
	for(int i=0;i<n-k+1;i++){
		cin>>arr[i];
	}
	dsu d;
	d.init(n);
	vector<int> hasto(n,-1);
	for(int i=0;i<n-k;i++){
		if(arr[i]==arr[i+1]){
			d.join(i,i+k);
		}else if(arr[i]+1==arr[i+1]){
			hasto[i]=0;
			hasto[i+k]=1;
		}else{
			hasto[i]=1;
			hasto[i+k]=0;
		}
	}
	for(int i=0;i<n;i++)	{
		int a = d.query(i);
		if(hasto[i]!=-1) hasto[a]=hasto[i];
	}
	for(int i=0;i<n;i++)	{
		hasto[i] = hasto[d.query(i)];
	}
	map<int,int> stuff;
	int cnt = 0;
	for(int i=0;i<k;i++){
		if(hasto[i]==1) cnt++;
		if(hasto[i]==-1){
			stuff[d.query(i)]++;
		}
	}
	int K = arr[0]-cnt;
	vector<int> w;	
	for(auto i : stuff) w.push_back(i.second);
	w.push_back(0);
	sort(w.begin(),w.end());
	vector<vector<int>> dp(w.size(),vector<int>(K+1,0));
	dp[0][0]=1;
	for(int i=1;i<w.size();i++){
		for(int j=0;j<=K;j++){
			dp[i][j] = dp[i-1][j];
			if(j>=w[i]) dp[i][j] = (dp[i][j]+dp[i-1][j-w[i]])%MOD;
		}
	}
	cout<<dp[w.size()-1][K]<<"\n";
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:71:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |  for(int i=1;i<w.size();i++){
      |              ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 600 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 600 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 532 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 388 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 600 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 532 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 388 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 49 ms 12628 KB Output is correct
36 Correct 58 ms 12736 KB Output is correct
37 Correct 56 ms 12808 KB Output is correct
38 Correct 53 ms 12628 KB Output is correct
39 Correct 53 ms 12628 KB Output is correct
40 Correct 59 ms 12808 KB Output is correct
41 Correct 65 ms 12624 KB Output is correct
42 Correct 51 ms 13076 KB Output is correct
43 Correct 50 ms 12880 KB Output is correct
44 Correct 56 ms 25112 KB Output is correct
45 Correct 64 ms 25220 KB Output is correct
46 Correct 69 ms 25108 KB Output is correct
47 Correct 51 ms 18516 KB Output is correct
48 Correct 53 ms 12820 KB Output is correct
49 Correct 52 ms 12628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 600 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 532 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 388 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 49 ms 12628 KB Output is correct
36 Correct 58 ms 12736 KB Output is correct
37 Correct 56 ms 12808 KB Output is correct
38 Correct 53 ms 12628 KB Output is correct
39 Correct 53 ms 12628 KB Output is correct
40 Correct 59 ms 12808 KB Output is correct
41 Correct 65 ms 12624 KB Output is correct
42 Correct 51 ms 13076 KB Output is correct
43 Correct 50 ms 12880 KB Output is correct
44 Correct 56 ms 25112 KB Output is correct
45 Correct 64 ms 25220 KB Output is correct
46 Correct 69 ms 25108 KB Output is correct
47 Correct 51 ms 18516 KB Output is correct
48 Correct 53 ms 12820 KB Output is correct
49 Correct 52 ms 12628 KB Output is correct
50 Correct 79 ms 30032 KB Output is correct
51 Correct 85 ms 35844 KB Output is correct
52 Correct 77 ms 26452 KB Output is correct
53 Correct 67 ms 12116 KB Output is correct
54 Correct 91 ms 41976 KB Output is correct
55 Correct 98 ms 47048 KB Output is correct
56 Correct 83 ms 34128 KB Output is correct
57 Correct 61 ms 12300 KB Output is correct
58 Correct 95 ms 47612 KB Output is correct
59 Correct 81 ms 30800 KB Output is correct
60 Correct 70 ms 12368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 600 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 532 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 388 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 49 ms 12628 KB Output is correct
36 Correct 58 ms 12736 KB Output is correct
37 Correct 56 ms 12808 KB Output is correct
38 Correct 53 ms 12628 KB Output is correct
39 Correct 53 ms 12628 KB Output is correct
40 Correct 59 ms 12808 KB Output is correct
41 Correct 65 ms 12624 KB Output is correct
42 Correct 51 ms 13076 KB Output is correct
43 Correct 50 ms 12880 KB Output is correct
44 Correct 56 ms 25112 KB Output is correct
45 Correct 64 ms 25220 KB Output is correct
46 Correct 69 ms 25108 KB Output is correct
47 Correct 51 ms 18516 KB Output is correct
48 Correct 53 ms 12820 KB Output is correct
49 Correct 52 ms 12628 KB Output is correct
50 Correct 79 ms 30032 KB Output is correct
51 Correct 85 ms 35844 KB Output is correct
52 Correct 77 ms 26452 KB Output is correct
53 Correct 67 ms 12116 KB Output is correct
54 Correct 91 ms 41976 KB Output is correct
55 Correct 98 ms 47048 KB Output is correct
56 Correct 83 ms 34128 KB Output is correct
57 Correct 61 ms 12300 KB Output is correct
58 Correct 95 ms 47612 KB Output is correct
59 Correct 81 ms 30800 KB Output is correct
60 Correct 70 ms 12368 KB Output is correct
61 Runtime error 823 ms 1048576 KB Execution killed with signal 9
62 Halted 0 ms 0 KB -