StoneHaos

(849)

Nov 2nd, 2019
154
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //849 не проходит по времени
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cstdlib>
  5. #include <vector>
  6. using namespace std;
  7.  
  8. typedef unsigned long long int li;
  9.  
  10. typedef union {
  11.     unsigned long long int x;
  12.     unsigned int y:4;
  13. } uni;
  14.  
  15. bool if_interes(li n, int t) {
  16.     vector<int> a(16, 0);
  17.     bool ret = true;
  18.     uni b;
  19.     while (n != 0) {
  20.         b.x = n;
  21.         ++ a[b.y];
  22.         n >>= 4;
  23.     }
  24.     if (*max_element(a.begin(), a.end()) > t)
  25.         ret = false;
  26.     return ret;
  27. }
  28.  
  29. int main(void) {
  30.     FILE* fin = fopen("input.txt", "r");
  31.     FILE* fout = fopen("output.txt", "w");
  32.  
  33.     int k, t;
  34.     fscanf(fin, "%d%d", &k, &t);
  35.     fclose(fin);
  36.     li n = 1;
  37.     for (int i = 0; i < k; ++ n) {
  38.         if (if_interes(n, t))
  39.             ++ i;
  40.     }
  41.     fprintf(fout, "%llx\n", n - 1);
  42.     fclose(fout);
  43.     return 0;
  44. }
RAW Paste Data