fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #pragma GCC optimize("Ofast")
  4. #pragma GCC target("avx,avx2,fma")
  5. #pragma GCC optimization ("O3")
  6. #pragma GCC optimization ("unroll-loops")
  7. typedef long long int ll;
  8. #define INF 1e17
  9. #define PI 3.14159265358979323846
  10. int del_x[4] = {-1, 1, 0, 0};
  11. int del_y[4] = {0, 0, 1, -1};
  12. int XX[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
  13. int YY[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
  14.  
  15. string bin(ll num, ll m){
  16. string s;
  17. while(num){
  18. int r = num%2;
  19. num = num /2;
  20. s += r + '0';
  21. }
  22. while(s.length() < m){
  23. s += '0';
  24. }
  25. reverse(s.begin(), s.end());
  26. return s;
  27. }
  28. int main(){
  29. #ifndef ONLINE_JUDGE
  30. clock_t tStart = clock();
  31. #endif
  32. ios_base:: sync_with_stdio(false);
  33. cin.tie(0);
  34. int t;
  35. cin >> t;
  36. while(t--){
  37. int n, m;
  38. cin >> n >> m;
  39. string s;
  40. vector<ll> v(n);
  41. cin.ignore(n,'\n');
  42. for(int i = 0; i < n; i++){
  43. getline(cin, s);
  44. for(int j = 0; j < m; j++){
  45. v[i] *= 2;
  46. v[i] += s[j] - '0';
  47. }
  48. }
  49.  
  50. ll index = ((1LL << m)-n-1)/2;
  51. bool Find = false;
  52. int prevCnt = 0;
  53. while(!Find){
  54. int cnt = 0;
  55. for(int i = 0; i < n; i++){
  56. //cout << "v[i] is "<< v[i]<<"\n";
  57. if(v[i] <= index){
  58. cnt++;
  59. }
  60. }
  61. index += (cnt-prevCnt);
  62. //cout << "cnt is "<<cnt<<"\n";
  63.  
  64. if(cnt-prevCnt == 0){
  65. Find = true;
  66. break;
  67. }
  68. prevCnt = cnt;
  69. }
  70. cout << bin(index, m)<<"\n";
  71.  
  72. }
  73.  
  74.  
  75. /* #ifndef ONLINE_JUDGE
  76.   printf("\nRun Time -> %.10fs\n", (double)(clock()-tStart) / CLOCKS_PER_SEC);
  77.   #endif */
  78.  
  79. }
Success #stdin #stdout 0s 4400KB
stdin
5
3 3
010
001
111
4 3
000
111
100
011
1 1
1
1 1
0
3 2
00
01
10
stdout
100
010
0
1
11