SHARE
TWEET

Untitled

a guest Nov 16th, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5. //https://atcoder.jp/contests/abc145/tasks/abc145_d
  6. long int modo = 1000000007;
  7.  
  8. long int binNewt(long int N,long int n1){
  9.     if(n1 == 0)
  10.         return 1;
  11.     long int i, j, iMin = N - n1, jMin = 0, *C;
  12.     C = malloc((n1 + 1) * sizeof(long int));
  13.     C[0] = 1;
  14.     for (i = 1; i <= n1; i++){
  15.         C[i] = 1;
  16.         for (j = i - 1; j > 0; j--){
  17.             C[j] = C[j - 1] + C[j];
  18.             if(C[j] > modo)
  19.                 C[j] -= modo;
  20.         }
  21.     }
  22.     for (i = n1 + 1; i <= iMin; i++)
  23.         for (j = n1; j > 0; j--){
  24.             C[j] = (C[j - 1] + C[j]);
  25.             if(C[j] > modo)
  26.                 C[j] -= modo;
  27.         }
  28.     for (i = iMin + 1; i < N; i++){
  29.         for (j = n1; j > jMin; j--){
  30.             C[j] = (C[j - 1] + C[j]);
  31.             if(C[j] > modo)
  32.                 C[j] -= modo;
  33.         }
  34.         jMin++;
  35.     }
  36.     return (C[n1] + C[n1 - 1]) % modo;
  37. }
  38.  
  39. int main() {
  40.     long int x, y, n1, N;
  41.     scanf("%ld %ld\n", &x, &y);
  42.     n1 =  (x < y) ? (2 * x - y) / 3 : (2 * y - x) / 3;
  43.     N = y + x;
  44.     if((N % 3 != 0) || n1 < 0 || n1 > N)
  45.         printf("0\n");
  46.     else{
  47.         N /= 3;
  48.         printf("%ld\n", binNewt(N, n1));
  49.     }
  50.     return 0;
  51. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top