SHARE
TWEET

Untitled

a guest Feb 19th, 2018 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //g++ filename.cpp -std=c++14 -DH
  2. #ifdef H
  3. #include "/Users/michaelw/stdc++.h"
  4. #else
  5. #include <bits/stdc++.h>
  6. #endif
  7.  
  8. using namespace std;
  9.  
  10. #define endl '\n'
  11. #define pb push_back
  12. #define f first
  13. #define s second
  14. #define lb lower_bound
  15. #define ub upper_bound
  16. #define all(x) x.begin(), x.end()
  17. #define pq priority_queue
  18.  
  19. typedef long long ll;
  20. typedef pair<int, string> pis;
  21. typedef pair<int,int> pii;
  22.  
  23. const ll MOD = 1000000007;
  24.  
  25. ll GCD(ll a, ll b)
  26. {
  27.    if (b==0) return a;
  28.  
  29.    return GCD(b,a%b);
  30. }
  31.  
  32. void reduce_fraction(ll &num, ll&denom){
  33.     ll both = GCD(num, denom);
  34.     num /= both;
  35.     denom /= both;
  36. }
  37. ll realMod(ll num, ll denom, ll MOD){
  38.     for(int i = 0; ; i++){
  39.         if((num + MOD*i) % denom == 0){
  40.             return (num + MOD*i) / denom;
  41.         }
  42.     }
  43. }
  44.  
  45. int main(){
  46.     ios_base::sync_with_stdio(false);
  47.     cin.tie(nullptr);
  48.     ifstream fin("filename.in");
  49.     ofstream fout("filename.out");
  50.     ll n, m;
  51.     cin >> n >> m;
  52.     ll prob = 0;
  53.     ll num = 1, denom = 1;
  54.     bool weird = 0;
  55.     vector<int> s1 (n), s2 (n);
  56.     for(int i = 0; i < n; i++){
  57.         cin >> s1[i];
  58.     }
  59.     for(int i = 0; i < n; i++){
  60.         cin >> s2[i];
  61.     }
  62.     for(int i = 0; i < n; i++){
  63.         if(s1[i] != 0 && s2[i] != 0){
  64.             if(s1[i] > s2[i]){
  65.                 reduce_fraction(num, denom);
  66.                 if(denom == 1) cout << 1 << endl;
  67.                 // cout << num << " " << denom << endl;
  68.                 else cout << prob + << endl;
  69.                 return 0;
  70.             }
  71.             else if(s2[i] > s1[i]){
  72.                 reduce_fraction(num, denom);
  73.                 if(denom == 1){
  74.                     cout << 0 << endl;
  75.                 }
  76.                 else{
  77.                     cout << prob << endl;
  78.                 }
  79.                 return 0;
  80.             }
  81.         }
  82.         else if(s1[i] == 0 && s2[i] != 0){
  83.             num *= (m-s2[i]);
  84.             num %= MOD;
  85.             denom *= m;
  86.             denom %= MOD;
  87.             reduce_fraction(num, denom);
  88.             prob += realMod(num, denom, MOD);
  89.             num = 1;
  90.             denom = m;
  91.             // prob *= (m-s2[i]) / m % MOD;
  92.         }      
  93.         else if(s1[i] != 0 && s2[i] == 0){
  94.             num *= s1[i]-1;
  95.             num %= MOD;
  96.             denom *= m;
  97.             denom %= MOD;
  98.             reduce_fraction(num, denom);
  99.             prob += realMod(num, denom, MOD);
  100.             num = 1;
  101.             denom = m;
  102.             // prob *= s1[i]-1 / m % MOD;
  103.  
  104.         }
  105.         if(s1[i] == 0 || s2[i] == 0){
  106.             weird = 1;
  107.         }
  108.     }
  109.     if(!weird){
  110.         cout << 0 << endl;
  111.     }
  112.     else{
  113.         // cout << num << " " << denom << endl;
  114.         cout << prob << endl;
  115.     }
  116.    
  117.    
  118. }
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