답안 #967971

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
967971 2024-04-23T06:13:00 Z owoovo Binaria (CCO23_day1problem1) C++17
25 / 25
265 ms 38992 KB
#include<bits/stdc++.h>
#define ll long long 
#define F first 
#define S second 
using namespace std;
const ll p=1e6+3;
struct Dsu{
    int ori[1000010]={};
    void init(int n){
        for(int i=0;i<=n;i++)ori[i]=i;
    }
    int f(int a){
        if(ori[a]==a)return a;
        ori[a]=f(ori[a]);
        return ori[a];
    }
    void onion(int a,int b){
        a=f(a);
        b=f(b);
        ori[a]=b;
        return ;
    }
}dsu;
int n,k,x[1000010];
ll pre[1000010],erp[1000010];
ll inv(ll a){
    return a==1?1:(p-p/a)*inv(p%a)%p;
}
ll c(ll a,ll b){
    if(a<b)return 0;
    return ((pre[a]*erp[b]%p)*erp[a-b])%p;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>k;
    dsu.init(n+1);
    pre[0]=1;
    erp[0]=1;
    for(int i=1;i<=1000000;i++){
        pre[i]=(pre[i-1]*i)%p;
        erp[i]=inv(pre[i]);
    }
    for(int i=0;i<n-k+1;i++){
        cin>>x[i];
    }
    for(int i=0;i<n-k;i++){
        int f=i+2,b=f+k;
        if(x[i]==x[i+1])dsu.onion(f,b);
        if(x[i]>x[i+1]){
            dsu.onion(f,1);
            dsu.onion(b,0);
        }
        if(x[i]<x[i+1]){
            dsu.onion(f,0);
            dsu.onion(b,1);
        }
    }
    if(dsu.f(0)==dsu.f(1)){
        cout<<"0\n";
        return 0;
    }
    int u=dsu.f(0),v=dsu.f(1);
    int cnt=0,cnt1=0;
    for(int i=2;i<2+k;i++){
        int w=dsu.f(i);
        if(w==v){
            cnt1++;
        }
        if(u!=w&&v!=w){
            cnt++;
        }
    }
    cout<<c(cnt,x[0]-cnt1)<<"\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 183 ms 19024 KB Output is correct
2 Correct 184 ms 19028 KB Output is correct
3 Correct 186 ms 19068 KB Output is correct
4 Correct 184 ms 19064 KB Output is correct
5 Correct 184 ms 19080 KB Output is correct
6 Correct 185 ms 19284 KB Output is correct
7 Correct 184 ms 19024 KB Output is correct
8 Correct 184 ms 19080 KB Output is correct
9 Correct 184 ms 19080 KB Output is correct
10 Correct 184 ms 19084 KB Output is correct
11 Correct 184 ms 19028 KB Output is correct
12 Correct 184 ms 19280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 183 ms 19024 KB Output is correct
2 Correct 184 ms 19028 KB Output is correct
3 Correct 186 ms 19068 KB Output is correct
4 Correct 184 ms 19064 KB Output is correct
5 Correct 184 ms 19080 KB Output is correct
6 Correct 185 ms 19284 KB Output is correct
7 Correct 184 ms 19024 KB Output is correct
8 Correct 184 ms 19080 KB Output is correct
9 Correct 184 ms 19080 KB Output is correct
10 Correct 184 ms 19084 KB Output is correct
11 Correct 184 ms 19028 KB Output is correct
12 Correct 184 ms 19280 KB Output is correct
13 Correct 185 ms 19028 KB Output is correct
14 Correct 184 ms 19064 KB Output is correct
15 Correct 184 ms 19284 KB Output is correct
16 Correct 186 ms 19028 KB Output is correct
17 Correct 184 ms 19028 KB Output is correct
18 Correct 183 ms 19064 KB Output is correct
19 Correct 185 ms 19056 KB Output is correct
20 Correct 183 ms 19076 KB Output is correct
21 Correct 183 ms 19084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 183 ms 19024 KB Output is correct
2 Correct 184 ms 19028 KB Output is correct
3 Correct 186 ms 19068 KB Output is correct
4 Correct 184 ms 19064 KB Output is correct
5 Correct 184 ms 19080 KB Output is correct
6 Correct 185 ms 19284 KB Output is correct
7 Correct 184 ms 19024 KB Output is correct
8 Correct 184 ms 19080 KB Output is correct
9 Correct 184 ms 19080 KB Output is correct
10 Correct 184 ms 19084 KB Output is correct
11 Correct 184 ms 19028 KB Output is correct
12 Correct 184 ms 19280 KB Output is correct
13 Correct 185 ms 19028 KB Output is correct
14 Correct 184 ms 19064 KB Output is correct
15 Correct 184 ms 19284 KB Output is correct
16 Correct 186 ms 19028 KB Output is correct
17 Correct 184 ms 19028 KB Output is correct
18 Correct 183 ms 19064 KB Output is correct
19 Correct 185 ms 19056 KB Output is correct
20 Correct 183 ms 19076 KB Output is correct
21 Correct 183 ms 19084 KB Output is correct
22 Correct 185 ms 19068 KB Output is correct
23 Correct 184 ms 19088 KB Output is correct
24 Correct 185 ms 19080 KB Output is correct
25 Correct 183 ms 19080 KB Output is correct
26 Correct 185 ms 19080 KB Output is correct
27 Correct 184 ms 19080 KB Output is correct
28 Correct 188 ms 19024 KB Output is correct
29 Correct 185 ms 19028 KB Output is correct
30 Correct 185 ms 19280 KB Output is correct
31 Correct 185 ms 19100 KB Output is correct
32 Correct 186 ms 19096 KB Output is correct
33 Correct 184 ms 19028 KB Output is correct
34 Correct 184 ms 19284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 183 ms 19024 KB Output is correct
2 Correct 184 ms 19028 KB Output is correct
3 Correct 186 ms 19068 KB Output is correct
4 Correct 184 ms 19064 KB Output is correct
5 Correct 184 ms 19080 KB Output is correct
6 Correct 185 ms 19284 KB Output is correct
7 Correct 184 ms 19024 KB Output is correct
8 Correct 184 ms 19080 KB Output is correct
9 Correct 184 ms 19080 KB Output is correct
10 Correct 184 ms 19084 KB Output is correct
11 Correct 184 ms 19028 KB Output is correct
12 Correct 184 ms 19280 KB Output is correct
13 Correct 185 ms 19028 KB Output is correct
14 Correct 184 ms 19064 KB Output is correct
15 Correct 184 ms 19284 KB Output is correct
16 Correct 186 ms 19028 KB Output is correct
17 Correct 184 ms 19028 KB Output is correct
18 Correct 183 ms 19064 KB Output is correct
19 Correct 185 ms 19056 KB Output is correct
20 Correct 183 ms 19076 KB Output is correct
21 Correct 183 ms 19084 KB Output is correct
22 Correct 185 ms 19068 KB Output is correct
23 Correct 184 ms 19088 KB Output is correct
24 Correct 185 ms 19080 KB Output is correct
25 Correct 183 ms 19080 KB Output is correct
26 Correct 185 ms 19080 KB Output is correct
27 Correct 184 ms 19080 KB Output is correct
28 Correct 188 ms 19024 KB Output is correct
29 Correct 185 ms 19028 KB Output is correct
30 Correct 185 ms 19280 KB Output is correct
31 Correct 185 ms 19100 KB Output is correct
32 Correct 186 ms 19096 KB Output is correct
33 Correct 184 ms 19028 KB Output is correct
34 Correct 184 ms 19284 KB Output is correct
35 Correct 230 ms 26448 KB Output is correct
36 Correct 237 ms 27252 KB Output is correct
37 Correct 235 ms 27624 KB Output is correct
38 Correct 231 ms 27504 KB Output is correct
39 Correct 228 ms 26488 KB Output is correct
40 Correct 236 ms 27496 KB Output is correct
41 Correct 233 ms 27476 KB Output is correct
42 Correct 237 ms 26748 KB Output is correct
43 Correct 228 ms 26452 KB Output is correct
44 Correct 236 ms 38768 KB Output is correct
45 Correct 234 ms 38992 KB Output is correct
46 Correct 233 ms 38760 KB Output is correct
47 Correct 232 ms 32336 KB Output is correct
48 Correct 235 ms 27256 KB Output is correct
49 Correct 233 ms 27476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 183 ms 19024 KB Output is correct
2 Correct 184 ms 19028 KB Output is correct
3 Correct 186 ms 19068 KB Output is correct
4 Correct 184 ms 19064 KB Output is correct
5 Correct 184 ms 19080 KB Output is correct
6 Correct 185 ms 19284 KB Output is correct
7 Correct 184 ms 19024 KB Output is correct
8 Correct 184 ms 19080 KB Output is correct
9 Correct 184 ms 19080 KB Output is correct
10 Correct 184 ms 19084 KB Output is correct
11 Correct 184 ms 19028 KB Output is correct
12 Correct 184 ms 19280 KB Output is correct
13 Correct 185 ms 19028 KB Output is correct
14 Correct 184 ms 19064 KB Output is correct
15 Correct 184 ms 19284 KB Output is correct
16 Correct 186 ms 19028 KB Output is correct
17 Correct 184 ms 19028 KB Output is correct
18 Correct 183 ms 19064 KB Output is correct
19 Correct 185 ms 19056 KB Output is correct
20 Correct 183 ms 19076 KB Output is correct
21 Correct 183 ms 19084 KB Output is correct
22 Correct 185 ms 19068 KB Output is correct
23 Correct 184 ms 19088 KB Output is correct
24 Correct 185 ms 19080 KB Output is correct
25 Correct 183 ms 19080 KB Output is correct
26 Correct 185 ms 19080 KB Output is correct
27 Correct 184 ms 19080 KB Output is correct
28 Correct 188 ms 19024 KB Output is correct
29 Correct 185 ms 19028 KB Output is correct
30 Correct 185 ms 19280 KB Output is correct
31 Correct 185 ms 19100 KB Output is correct
32 Correct 186 ms 19096 KB Output is correct
33 Correct 184 ms 19028 KB Output is correct
34 Correct 184 ms 19284 KB Output is correct
35 Correct 230 ms 26448 KB Output is correct
36 Correct 237 ms 27252 KB Output is correct
37 Correct 235 ms 27624 KB Output is correct
38 Correct 231 ms 27504 KB Output is correct
39 Correct 228 ms 26488 KB Output is correct
40 Correct 236 ms 27496 KB Output is correct
41 Correct 233 ms 27476 KB Output is correct
42 Correct 237 ms 26748 KB Output is correct
43 Correct 228 ms 26452 KB Output is correct
44 Correct 236 ms 38768 KB Output is correct
45 Correct 234 ms 38992 KB Output is correct
46 Correct 233 ms 38760 KB Output is correct
47 Correct 232 ms 32336 KB Output is correct
48 Correct 235 ms 27256 KB Output is correct
49 Correct 233 ms 27476 KB Output is correct
50 Correct 251 ms 28776 KB Output is correct
51 Correct 242 ms 28756 KB Output is correct
52 Correct 242 ms 28756 KB Output is correct
53 Correct 265 ms 29008 KB Output is correct
54 Correct 244 ms 28792 KB Output is correct
55 Correct 243 ms 28752 KB Output is correct
56 Correct 243 ms 28652 KB Output is correct
57 Correct 249 ms 27732 KB Output is correct
58 Correct 243 ms 28764 KB Output is correct
59 Correct 246 ms 28772 KB Output is correct
60 Correct 249 ms 27732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 183 ms 19024 KB Output is correct
2 Correct 184 ms 19028 KB Output is correct
3 Correct 186 ms 19068 KB Output is correct
4 Correct 184 ms 19064 KB Output is correct
5 Correct 184 ms 19080 KB Output is correct
6 Correct 185 ms 19284 KB Output is correct
7 Correct 184 ms 19024 KB Output is correct
8 Correct 184 ms 19080 KB Output is correct
9 Correct 184 ms 19080 KB Output is correct
10 Correct 184 ms 19084 KB Output is correct
11 Correct 184 ms 19028 KB Output is correct
12 Correct 184 ms 19280 KB Output is correct
13 Correct 185 ms 19028 KB Output is correct
14 Correct 184 ms 19064 KB Output is correct
15 Correct 184 ms 19284 KB Output is correct
16 Correct 186 ms 19028 KB Output is correct
17 Correct 184 ms 19028 KB Output is correct
18 Correct 183 ms 19064 KB Output is correct
19 Correct 185 ms 19056 KB Output is correct
20 Correct 183 ms 19076 KB Output is correct
21 Correct 183 ms 19084 KB Output is correct
22 Correct 185 ms 19068 KB Output is correct
23 Correct 184 ms 19088 KB Output is correct
24 Correct 185 ms 19080 KB Output is correct
25 Correct 183 ms 19080 KB Output is correct
26 Correct 185 ms 19080 KB Output is correct
27 Correct 184 ms 19080 KB Output is correct
28 Correct 188 ms 19024 KB Output is correct
29 Correct 185 ms 19028 KB Output is correct
30 Correct 185 ms 19280 KB Output is correct
31 Correct 185 ms 19100 KB Output is correct
32 Correct 186 ms 19096 KB Output is correct
33 Correct 184 ms 19028 KB Output is correct
34 Correct 184 ms 19284 KB Output is correct
35 Correct 230 ms 26448 KB Output is correct
36 Correct 237 ms 27252 KB Output is correct
37 Correct 235 ms 27624 KB Output is correct
38 Correct 231 ms 27504 KB Output is correct
39 Correct 228 ms 26488 KB Output is correct
40 Correct 236 ms 27496 KB Output is correct
41 Correct 233 ms 27476 KB Output is correct
42 Correct 237 ms 26748 KB Output is correct
43 Correct 228 ms 26452 KB Output is correct
44 Correct 236 ms 38768 KB Output is correct
45 Correct 234 ms 38992 KB Output is correct
46 Correct 233 ms 38760 KB Output is correct
47 Correct 232 ms 32336 KB Output is correct
48 Correct 235 ms 27256 KB Output is correct
49 Correct 233 ms 27476 KB Output is correct
50 Correct 251 ms 28776 KB Output is correct
51 Correct 242 ms 28756 KB Output is correct
52 Correct 242 ms 28756 KB Output is correct
53 Correct 265 ms 29008 KB Output is correct
54 Correct 244 ms 28792 KB Output is correct
55 Correct 243 ms 28752 KB Output is correct
56 Correct 243 ms 28652 KB Output is correct
57 Correct 249 ms 27732 KB Output is correct
58 Correct 243 ms 28764 KB Output is correct
59 Correct 246 ms 28772 KB Output is correct
60 Correct 249 ms 27732 KB Output is correct
61 Correct 187 ms 22352 KB Output is correct
62 Correct 191 ms 21840 KB Output is correct
63 Correct 187 ms 21844 KB Output is correct
64 Correct 186 ms 22100 KB Output is correct
65 Correct 218 ms 27216 KB Output is correct
66 Correct 208 ms 26212 KB Output is correct
67 Correct 241 ms 29540 KB Output is correct
68 Correct 190 ms 22124 KB Output is correct
69 Correct 186 ms 21872 KB Output is correct
70 Correct 190 ms 22096 KB Output is correct
71 Correct 187 ms 21840 KB Output is correct