Submission #167116

#TimeUsernameProblemLanguageResultExecution timeMemory
167116abilLongest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
231 ms262144 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];
deque<int > vec[N];
main()
{
	int n;
	bool f = true;
	cin >> n;
	for(int i = 1;i <= n;	i++){
		scanf("%d", &a[i]);
		if(a[i] >= (1 << 8)){
			f = false;
		}
	}
	for(int j = 1;j <= n; j++){
		scanf("%d", &k[j]);
	}
	deque<int > ans;
	if(f){
		for(int i = n;i >= 1; i--){
			for(int j = 1;j < (1 << 8); j++){
				if(vec[a[i]].size() >= vec[j].size() && __builtin_popcount((a[i] & j)) == k[i]){
					vec[j] = vec[a[i]];
					vec[j].pb(i);
				}
			}
			vec[a[i]].pb(i);
			if(vec[i].size() > ans.size()){
				ans = vec[i];
			}
		}
		cout << ans.size() << endl;
		reverse(all(ans));
		for(auto to : ans){
			cout << to << " ";
		}
		return 0;
	}
	for(int i = n;i >= 1; i--){
		for(int j = i + 1;j <= n; j++){
			if(vec[i].size() <= vec[j].size() && __builtin_popcount((a[i] & a[j])) == k[j]){
				vec[i] = vec[j];
				vec[i].pb(i);
			}
		}
		if(vec[i].size() > ans.size()){
			ans = vec[i];
		}
	}
	cout << ans.size() << endl;
	reverse(all(ans));
	for(auto to : ans){
		cout << to << " ";
	}
}

Compilation message (stderr)

subsequence.cpp:18:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
subsequence.cpp: In function 'int main()':
subsequence.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
subsequence.cpp:30: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...