제출 #1290365

#제출 시각아이디문제언어결과실행 시간메모리
1290365M_SH_OBinaria (CCO23_day1problem1)C++20
0 / 25
1 ms572 KiB
/*#pragma GCC optimize("O3") #pragma GCC optimization("Ofast,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")*/ #include <bits/stdc++.h> //#include "jumps.h" /*#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp>*/ #define ll long long #define ll1 long long #define ull unsigned long long #define dou long double #define str string #define vll vector<ll> #define vi vector<int> #define pll pair<ll, ll> #define vpll vector<pair<ll, ll>> #define vbool vector<bool> #define vstr vector<str> #define vvll vector<vll> #define pb push_back #define pf push_front #define endl "\n" #define fr first #define se second // #define sortcmp(a) sort(a.begin(), a.end(), cmp) #define sort(a) sort(a.begin(), a.end()) #define reverse(a) reverse(a.begin(), a.end()) #define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define ordered_set tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> using namespace std; //using namespace __gnu_pbds; const ll INF = 1e9+7; const int lg = 20; //const ll MOD = 1e9+7; //const ll MOD2 = 998244353; const ll MOD2 = 1e6+3; mt19937 rng(1488); ll randll(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rng); } ll f(ll n) { ll fk = 1; for (int i = 2; i <= n; i ++) { fk *= i; fk %= MOD2; } return fk; } ll bp(ll b, ll n) { if (n == 1) return b; if (n % 2 == 1) return b*bp(b, n-1)%MOD2; ll c = bp(b, n/2); return c*c%MOD2; } int main() { speed; ll n, k; cin >> n >> k; vll a(n-k+1); bool q = 1; for (int i = 0; i < n-k+1; i ++) { cin >> a[i]; if (a[i] > k) q = 0; } vll c(n, -1); vpll v; for (int i = 1; i < n-k+1; i ++) { if (a[i] == a[i-1]) { v.pb({i-1, i+k-1}); continue; } if (a[i] < a[i-1]) { c[i+k-1] = 0; if (c[i-1] != -1) q = 0; c[i-1] = 1; } else { c[i-1] = 0; if (c[i+k-1] != -1) q = 0; c[i+k-1] = 1; } } //cout << q << endl; for (auto i : v) { if (c[i.fr] != -1) { if (c[i.se] != -1 && c[i.se] != c[i.fr]) q = 0; c[i.se] = c[i.fr]; } } reverse(v); for (auto i : v) { if (c[i.se] != -1) { if (c[i.fr] != -1 && c[i.fr] != c[i.se]) q = 0; c[i.fr] = c[i.se]; } } ll res = 0; ll s = 0; for (int i = 0; i < k; i ++) { if (c[i] == -1) res ++; else s += c[i]; } s = a[0]-s; if (s > res) q = 0; if (!q) { cout << 0 << endl; return 0; } cout << f(res)*bp(f(res-s)*f(s)%MOD2, MOD2-2)%MOD2; }
#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...