Submission #1038891

#TimeUsernameProblemLanguageResultExecution timeMemory
1038891vjudge1Binaria (CCO23_day1problem1)C++17
25 / 25
137 ms18880 KiB
//ᗜˬᗜ #include<bits/stdc++.h> #define int long long #define vi vector <int> #define bs binary_search #define lb lower_bound #define ub upper_bound #define pb emplace_back #define fu(i, a, b) for(int i = (a); i < (b); i++) #define fub(i, a, b) for(int i = (a); i <= (b); i++) #define pii pair<int, int> #define fastio ios_base::sync_with_stdio(0); cin.tie(0); using namespace std; const int lim = 1e18; const int N = 1e6 + 3; const int M = 1e9 + 7; int n, k, res; int a[N], mp[N]; int expo(int a, int b){ if(b == 0)return 1; if(b%2 == 0)return expo((a*a)%N, b/2)%N; return (a*expo((a*a)%N, b/2))%N; } int bico(int n, int k){ if(k > n or n < 0 or k < 0)return 0; int res = 1; fub(i, k+1, n)res = (res*i)%N; fub(i, 1, n-k)res = (res*expo(i, N-2))%N; return res; } signed main(){ fastio; cin >> n >> k; fub(i, 1, n-k+1)cin >> a[i]; memset(mp, -1, sizeof(mp)); fub(i, 2, n-k+1){ if(abs(a[i] - a[i-1]) > 1){ cout << 0; return 0; } } fub(i, 2, n-k+1){ if(a[i] - a[i-1] == 1){ mp[i+k-1] = 1; mp[i-1] = 0; } else if(a[i] - a[i-1] == -1){ mp[i+k-1] = 0; mp[i-1] = 1; } else mp[i+k-1] = mp[i-1]; } for(int i = n-k; i >= 1; i--)if(a[i] == a[i+1])mp[i] = mp[i+k]; fub(i, 1, k){ res += (mp[i] == -1); a[1] -= (mp[i] == 1); } cout << bico(res, a[1]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...