Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <cmath>
  5. #include <vector>
  6. #include <algorithm>
  7. #include <map>
  8. #include <set>
  9.  
  10. using namespace std;
  11.  
  12. #define forn(i,n) for(int i = 0; i < n; i++)
  13. #define ll long long
  14. #define ini(type, n) \
  15.         type n; \
  16.         cin >> n;
  17.  
  18.  
  19. ll transposition(const vector<int> p, const ll fact[])
  20. {
  21.     int size = p.size();
  22.     ll trans = (p[0] - 1)*(fact[size - 1]) + 1;
  23.     vector<bool> used(size);
  24.     used[p[0]-1] = true;
  25.     for (int i = 1; i < size; i++)
  26.     {
  27.         int diff = 0;
  28.         used[p[i]-1] = true;
  29.         for (int j = 0; j < p[i]; j++)
  30.         {
  31.             if (!used[j])
  32.                 diff++;
  33.         }
  34.         trans += diff*fact[size - (i + 1)];
  35.     }
  36.     return trans;
  37. }
  38.  
  39. int main()
  40. {
  41.     ll fact[21];
  42.     fact[0] = 1;
  43.     for (ll i = 1; i <= 20; i++)
  44.         fact[i] = fact[i - 1] * i;
  45.     vector<int> p;
  46.     int a;
  47.     char nl = ' ';
  48.     while (nl != '\n')
  49.     {
  50.         scanf("%d%c", &a, &nl);
  51.         p.push_back(a);
  52.     }
  53.     cout << p.size() << ' ' << transposition(p, fact) << endl;
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement