SHARE
TWEET

Untitled

a guest Aug 25th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <algorithm>
  2. #include <vector>
  3. #include <map>
  4.  
  5. #define ll long long
  6. #define MOD 1000000007
  7.  
  8. using namespace std;
  9.  
  10. ll fact[100010];
  11.  
  12. vector<int> librero(vector<int> bases, vector<int> libros, vector<int> &orden)
  13. {
  14.     ll cant = 1;
  15.     int minV = *min_element(bases.begin(), bases.end()), maxV = *max_element(libros.begin(), libros.end());
  16.     int n = (int)bases.size(), alt = (maxV + minV), diff, mz;
  17.  
  18.     fact[1] = 1LL;
  19.  
  20.     map < int, vector < int > > mapa;
  21.     map < int, bool > usado;
  22.  
  23.     for(int i = 0; i < n; i++)
  24.         mapa[libros[i]].push_back(i + 1);
  25.  
  26.     for(ll i = 2LL; i <= 100000; i++)
  27.         fact[i] = (((fact[i - 1] % MOD) * (i % MOD)) % MOD);
  28.  
  29.     for(int i = 0; i < n; i++)
  30.     {
  31.         diff = (alt - bases[i]);
  32.         mz = (int)mapa[diff].size();
  33.  
  34.         if(mz > 0)
  35.         {
  36.             if(!usado[diff])
  37.             {
  38.                 cant = (((cant % MOD) * (fact[mz] % MOD)) % MOD);
  39.  
  40.                 usado[diff] = true;
  41.             }
  42.  
  43.             orden.push_back(mapa[diff].back());
  44.  
  45.             mapa[diff].pop_back();
  46.         }
  47.         else
  48.             cant = 0;
  49.     }
  50.  
  51.     if(!cant)
  52.     {
  53.         orden.clear();
  54.  
  55.         return {-1, 0};
  56.     }
  57.  
  58.     return {(int)alt, (int)cant};
  59. }
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