Advertisement
leoanjos

Judge infeliz

May 19th, 2021
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define long long long int
  6.  
  7. #define pii pair<int, int>
  8. #define pll pair<long, long>
  9. #define fst first
  10. #define snd second
  11.  
  12. #define all(ds) (ds).begin(), (ds).end()
  13. #define rall(ds) (ds).rbegin(), (ds).rend()
  14. #define size(ds) (int) (ds).size()
  15.  
  16. #define pq priority_queue
  17. #define vi vector<int>
  18. #define pb push_back
  19. #define mp make_pair
  20. #define lb lower_bound
  21. #define ub upper_bound
  22.  
  23. const int MAX = 1e5 + 5;
  24. const int MOD = 1e9 + 7;
  25.  
  26. long exp(long b, long n) {
  27.     if (!n) return 1LL;
  28.  
  29.     long ans = exp(b, n >> 1LL);
  30.     ans = (ans * ans) % MOD;
  31.  
  32.     if (!(n & 1)) return ans;
  33.     return (ans * b) % MOD;
  34. }
  35.  
  36. int main() {
  37.     ios_base::sync_with_stdio(false);
  38.     cin.tie(NULL);
  39.  
  40.     int n; long x;
  41.     cin >> n >> x;
  42.  
  43.     long a[MAX], sum = 0LL;
  44.     for (int i = 0; i < n; i++) {
  45.         cin >> a[i];
  46.         sum += a[i];
  47.     }
  48.  
  49.     if (sum == 0) cout << "1\n";
  50.     else {
  51.         map<long, int> cnt;
  52.         for (int i = 0; i < n; i++)
  53.             cnt[sum - a[i]]++;
  54.  
  55.         while (!(cnt.begin()->snd % x)) {
  56.             int aux = cnt.begin()->snd / x;
  57.             cnt[cnt.begin()->fst + 1] += aux;
  58.             cnt.erase(cnt.begin());
  59.         }
  60.  
  61.         long mn_exp = cnt.begin()->fst;
  62.         long ans = exp(x, mn_exp);
  63.         cout << ans << "\n";
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement