## CodeForces 639C Bear and Polynomials

Bear and Polynomials

```#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod =  (int)1e9+7;
const int N = 2e5 + 100;
int a[N];
int n, k;
int solve(){
LL tv = 0, p = n;
int ret = 0;
for(int i = 0; i <= n; ++i){
tv = tv / 2 + a[i];
if(tv&1){
p = i;
break;
}
}
LL val = 0;
for(int i = n; i > p; --i){
val = val * 2 + a[i];
if(abs(val) > INF) {
return ret;
}
}
val = val * 2 + tv;
if(abs(val) > INF) {return ret;}
for(int i = p; i >= 0; --i){
if(abs(val - a[i]) <= k){
if(i == n && val == a[i]) ;
else {
++ret;
}
}
val <<= 1;
if(abs(val) > INF) {return ret;}
}
return ret;
}
int main(){
scanf("%d%d", &n, &k);
for(int i = 0; i <= n; ++i)
scanf("%d", &a[i]);
printf("%d\n", solve());
return 0;
}```
View Code

0条评论