Advertisement
Ilya_konstantinov

testgen

Aug 22nd, 2024
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | Source Code | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <vector>
  5.  
  6.  
  7. using std::vector;
  8. using std::stringstream;
  9.  
  10. const int INF = 2e9;
  11.  
  12. stringstream solve1(std::istream &cin) {
  13.   stringstream cout;
  14.   int n, k = 0; cin >> n;
  15.   vector<int> v(n);
  16.   for (int &el : v) cin >> el;
  17.   vector<int> dp(n, INF);
  18.   for (int i = 0; i < n; ++i) {
  19.     for (int j = 0; j < n; ++j) {
  20.       if (dp[j] >= v[i]) {
  21.         dp[j] = v[i];
  22.         break;
  23.       }
  24.     }
  25.   }
  26.   for (int &el : dp) {
  27.     if (el != INF) k++;
  28.     else break;
  29.   }
  30.   cout << k;
  31.   return cout;
  32. }
  33.  
  34. stringstream solve2(std::istream &cin) {
  35.   stringstream cout;
  36.   int n, k = 0; cin >> n;
  37.   vector<int> v(n);
  38.   for (int &el : v) cin >> el;
  39.   vector<int> dp(n, INF);
  40.   for (int i = 0; i < n; ++i) {
  41.     int l = 0, r = n - 1, m;
  42.     while (r - l > 1) {
  43.       m = (l + r) / 2;
  44.       if (dp[m] <= v[i]) l = m;
  45.       else r = m;
  46.     }
  47.     if (dp[l] > v[i])
  48.       dp[l] = v[i];
  49.     else if (dp[r] > v[i])
  50.       dp[r] = v[i];
  51.   }
  52.   for (int &el : dp) {
  53.     if (el != INF) k++;
  54.     else break;
  55.   }
  56.   cout << k;
  57.   return cout;
  58. }
  59.  
  60. int randint(int from, int to) {
  61.   return from + (rand()%(to - from));
  62. }
  63.  
  64. #include "func.h"
  65.  
  66. int main() {
  67.   int n; std::cin >> n;
  68.   srand(n);
  69.   stringstream test1 = testgen(n), test2;
  70.   test2 = stringstream(test1.str());
  71.   stringstream ans1 = solve1(test1), ans2 = solve2(test2);
  72.   std::cout << (ans1.str() == ans2.str());
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement