#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned long long int ull;
const ll md = 998244353;
const int ukr = 6e5+10;
const int ukr2 = 3e5+10;
int read() {
int ketek = 0; bool ne=0;
register char c = getchar();
while(c == ' ' or c =='\n') c =getchar();
if(c=='-'){ne = 1; c = getchar();}
while(c >= '0' and c <='9') { ketek = (ketek<<3)+(ketek<<1)+c-'0'; c = getchar();}
if(ne) ketek*=-1;
return ketek;
}
void print(int x) {
if (x < 0) {putchar('-');x = -x;}
int len = 0, buf[10];
if (x == 0) {putchar('0');return;}
while (x > 0) {buf[len++] = x % 10; x/=10;}
while (len > 0) {putchar('0' + buf[--len]);}
}
void File_Work(){
freopen("test.in","r",stdin);
freopen("test.out","w",stdout);
}
int n, m, a, b, c, d, id;
struct babi{
ll x, y, id;
};
struct babis{
ll x, y;
};
ll gcd(ll a, ll b) {
if (b == 0) return a;
return gcd(b, a % b);
}
ll pgkt(ll rnx, ll rny){
if(rny == 0) return 1;
ll nwrn = pgkt(rnx, rny/2);
if(rny%2){
return (((nwrn*nwrn)%md)*rnx)%md;
}else{
return (nwrn*nwrn)%md;
}
}
vector<int> v;
string s;
ll ar[ukr2];
ll pf[ukr];
ll fak[ukr2];
ll invfak[ukr2];
void solve(){
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> ar[i];
}
for(ll i = 1; i <= n; i++){
pf[i] = pf[i-1]+ar[i];
}
ll kel = pf[n]/2;
ll pr = 0;
ll ans = 0;
for(int i = 0; i <= n; i++){
ll l = i, r = n, res= -1;
while(l <= r){
ll mid = l + (r-l)/2;
if(pf[mid]-pf[i] <= kel){
l = mid+1;
res = mid;
}else{
r = mid-1;
}
}
if(pf[res]-pf[i] == kel){
pr++;
}
}
//cout << pr << endl;
ll tdk = n-(2*pr);
for(int i = 0; i <= min(pr, (ll)m); i++){
ll ss = pr-i;
//cout << ss << "\n";
if(m < i) continue;
ll val1 = ((fak[pr]*invfak[i])%md*invfak[pr-i])%md;
ll val2 = (fak[m]*invfak[m-i])%md;
ll val3 = pgkt(((m-i)*(m-i-1))%md, ss);
ll val4 = pgkt(m-i, tdk);
ans = (ans+(((val1*val2)%md*(val3*val4)%md))%md)%md;
//cout << ans << "\n";
}
cout << ans << "\n";
}
void pre(){
fak[0] = 1;
for(ll i = 1; i <= ukr2/2; i++){
fak[i] = (fak[i-1]*i)%md;
}
invfak[ukr2/2] = pgkt(fak[ukr2/2], md-2);
for(ll i = ukr2/2-1; i >= 0; i--){
invfak[i] = (invfak[i+1]*(i+1))%md;
}
//cout << invfak[2]<<pgkt(2, md-2) << "\n";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
pre();
int t =1;
//cin >> t;
for(int i = 1; i <= t; i++){
//cout << "Case " << i << ": ";
solve();
}
}
Compilation message
lasers.cpp: In function 'int read()':
lasers.cpp:11:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
11 | register char c = getchar();
| ^
lasers.cpp: In function 'void File_Work()':
lasers.cpp:26:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | freopen("test.in","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
lasers.cpp:27:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | freopen("test.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1053 ms |
6744 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1053 ms |
6744 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
18 ms |
15960 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
6748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
18 ms |
15960 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1053 ms |
6744 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |