Submission #167113

#TimeUsernameProblemLanguageResultExecution timeMemory
167113abilLongest beautiful sequence (IZhO17_subsequence)C++14
7 / 100
6 ms504 KiB
#include <bits/stdc++.h>

#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define all(s) s.begin(),s.end()
//#define int long long

using namespace std;

const int N = (1e6 + 12);
const int mod = (1e9 + 7);
const int INF = (0x3f3f3f3f);

int a[N], k[N];
main()
{
	int n;
	cin >> n;
	for(int i = 0;i < n;	i++){
		scanf("%d", &a[i]);
	}
	for(int j = 0;j < n; j++){
		scanf("%d", &k[j]);
	}
	vector<int > ans, vec;
	ans.pb(0);
	for(int mask = 0; mask < (1 << n); mask++){
		vec.clear();
		if(__builtin_popcount(mask) < 2){
			continue;
		}
		for(int i = 0;i < n; i++){
			if(mask & (1 << i)){
				vec.pb(i);
			}
		}
		bool ok = true;
		for(int i = 1;i < vec.size(); i++){
			if(__builtin_popcount((a[vec[i]] & a[vec[i - 1]])) != k[vec[i]]){
				ok = false;
			}
		}
		if(!ok){
			continue;
		}
		if(vec.size() > ans.size()){
			swap(ans, vec);
		}
	}
	cout << ans.size() << endl;
	for(auto to : ans){
		cout << to + 1 << " ";
	}
}

Compilation message (stderr)

subsequence.cpp:17:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
subsequence.cpp: In function 'int main()':
subsequence.cpp:40:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 1;i < vec.size(); i++){
                 ~~^~~~~~~~~~~~
subsequence.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
subsequence.cpp:25:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &k[j]);
   ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...