Submission #236599

#TimeUsernameProblemLanguageResultExecution timeMemory
236599maskoffLongest beautiful sequence (IZhO17_subsequence)C++14
7 / 100
19 ms388 KiB
#include <bits/stdc++.h>
#include <ext/rope>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
 
#define file ""
 
#define all(x) x.begin(), x.end()
 
#define sc second
#define fr first
 
#define pb push_back
#define mp make_pair
 
#define pss pair<line*, line*>
 
using namespace std;
using namespace __gnu_cxx;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
                                 
const ll inf = 1e18;
const int MOD = 1e9 + 7;
 
const int dx[] = {-1, +1, -2, +2, -2, +2, -1, +1};
const int dy[] = {-2, -2, -1, -1, +1, +1, +2, +2};
 
int const N = 5e3 + 5;
int const M = 2e6;


int get (int x) {
	int res = 0;
 	while (x > 0) {
 		if (x % 2 == 1)
 			res++;
 		x /= 2;
 	}
 	return res;
}


int main() {                 
#ifdef Mask                                                         
  freopen(".in", 	"r", stdin);
  freopen(".out", "w", stdout);  
#endif
	ios_base :: sync_with_stdio(false);               
  cin.tie(nullptr);
  int n;
  cin >> n;
  int a[n + 1], k[n + 1];
  for (int i = 1; i <= n; i++)
  	cin >> a[i];
  for (int i =  1; i <= n; i++)
  	cin >> k[i];
  vector<pii> ans;
  for (int mask = 0; mask < (1 << n); mask++) {
   	vector<pii> res;
   	for (int i = 1; i <= n; i++) {
   	 	if ((1 << (i - 1)) & mask) 
   	 		res.pb({a[i], i});
   	}
   	int ok = true;
		for (int i = 1; i < res.size(); i++)
			if (get(res[i].fr & res[i - 1].fr) != k[res[i].sc])
				ok = false;
   	if (ok == true && res.size() > ans.size())
   		ans = res;
  }
  cout << ans.size() << endl;
  for (auto to : ans)
  	cout << to.sc << " ";
	return 0;
 
}

Compilation message (stderr)

subsequence.cpp: In function 'int main()':
subsequence.cpp:69:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 1; i < res.size(); i++)
                   ~~^~~~~~~~~~~~
subsequence.cpp:76:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   for (auto to : ans)
   ^~~
subsequence.cpp:78:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  return 0;
  ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...