Guest User

Untitled

a guest
Mar 28th, 2016
111
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.marinshalamanov.codeforces.vkcup2016;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.InputStreamReader;
  7. import java.io.OutputStream;
  8. import java.io.PrintWriter;
  9. import java.math.BigInteger;
  10. import java.util.StringTokenizer;
  11.  
  12. public class D {
  13.     int n, k;
  14.     BigInteger a[];
  15.     BigInteger kBi, mkBi;
  16.    
  17.     public void solve(InputReader in, PrintWriter out) {
  18.         n = in.nextInt();
  19.         k = in.nextInt();
  20.         a = new BigInteger[n+1];
  21.        
  22.         kBi = new BigInteger(Integer.toString(k));
  23.         mkBi =new BigInteger(Integer.toString(-k));
  24.        
  25.         for(int i = 0; i <= n; i++) a[i] = new BigInteger(in.next()); //.nextInt();
  26.        
  27.         BigInteger res = new BigInteger("0");
  28.         BigInteger pow2 = BigInteger.ONE;
  29.        
  30.         for(int i = 0; i <= n; i++) {
  31.            
  32.             res = res.add(pow2.multiply(a[i])) ;
  33. //          System.out.println(pow2.multiply(a[i]));
  34.            
  35.             pow2 = pow2.add(pow2);
  36.         }
  37.        
  38.         pow2 = BigInteger.ONE;
  39. //        System.out.println(res);
  40.         int count = 0;
  41.         for(int i = 0; i <= n; i++) {
  42.             BigInteger[] divrem = res.divideAndRemainder(pow2);
  43.             if (divrem[1].compareTo(BigInteger.ZERO) == 0) {
  44.                
  45.                 BigInteger changed = a[i].subtract(divrem[0]);
  46.                 if(i==n && changed.compareTo(BigInteger.ZERO)==0) {
  47.                     break;
  48.                 }
  49.                
  50. //              System.out.println(changed + "\t" + divrem[0]);
  51.                 if(changed.compareTo(kBi) <= 0 && changed.compareTo(mkBi) >= 0) {
  52.                     count ++;
  53.                 }
  54.             }
  55.             pow2 = pow2.add(pow2);
  56.         }
  57.        
  58.         System.out.println(count);
  59.        
  60.        
  61.        
  62.        
  63.        
  64.     }
  65.    
  66.     public static void main(String[] args) {
  67.         InputStream inputStream = System.in;
  68.         OutputStream outputStream = System.out;
  69.         InputReader in = new InputReader(inputStream);
  70.         PrintWriter out = new PrintWriter(outputStream);
  71.         D solver = new D();
  72.         solver.solve(in, out);
  73.         out.close();
  74.     }
  75.  
  76.     static class InputReader {
  77.         public BufferedReader reader;
  78.         public StringTokenizer tokenizer;
  79.  
  80.         public InputReader(InputStream stream) {
  81.             reader = new BufferedReader(new InputStreamReader(stream), 32768);
  82.             tokenizer = null;
  83.         }
  84.  
  85.         public String next() {
  86.             while (tokenizer == null || !tokenizer.hasMoreTokens()) {
  87.                 try {
  88.                     tokenizer = new StringTokenizer(reader.readLine());
  89.                 } catch (IOException e) {
  90.                     throw new RuntimeException(e);
  91.                 }
  92.             }
  93.             return tokenizer.nextToken();
  94.         }
  95.  
  96.         public int nextInt() {
  97.             return Integer.parseInt(next());
  98.         }
  99.        
  100.         public double nextDouble() {
  101.             return Double.parseDouble(next());
  102.         }
  103.     }
  104. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×