Submission #36082

#TimeUsernameProblemLanguageResultExecution timeMemory
36082UncleGrandpa925Longest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
0 ms2180 KiB
/*input
4
1 2 3 4
10 0 1 0
5
5 3 5 3 5
10 1 20 1 20
4
1 2 3 4
10 0 1 0
*/
#include <bits/stdc++.h>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define int long long
#define N 25
#define bit(x,y) ((x>>y)&1LL)
#define na(x) (#x) << ":" << x
ostream& operator << (ostream &os, vector<int>&x) {
	for (int i = 0; i < x.size(); i++) os << x[i] << sp;
	return os;
}
ostream& operator << (ostream &os, pair<int, int> x) {
	cout << x.fi << sp << x.se << sp;
	return os;
}
ostream& operator << (ostream &os, vector<pair<int, int> >&x) {
	for (int i = 0; i < x.size(); i++) os << x[i] << endl;
	return os;
}

int n;
int a[N], b[N];
bool dp[N][N];
int par[N][N];
vector<int> order;
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	if (n>15) return 0;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) cin >> b[i];
	pair<int, int> ans = mp(1, 1);
	for (int i = 1; i <= n; i++) {
		dp[i][1] = true;
		for (int j = 2; j <= i; j++) {
			// cal dp i j
			for (int k = 1; k <= i - 1; k++) {
				if (dp[k][j - 1] && __builtin_popcount(a[k]&a[i]) == b[j]) {
					par[i][j] = k;
					dp[i][j] = true;
					ans = max(ans, mp(j, i));
					break;
				}
			}
		}
	}
	cout << ans.fi << endl;
	int x = ans.fi; int y = ans.se;
	while (x >= 1) {
		order.push_back(y);
		y = par[y][x];
		x--;
	}
	reverse(order.begin(), order.end());
	cout << order << endl;
}

Compilation message (stderr)

subsequence.cpp: In function 'std::ostream& operator<<(std::ostream&, std::vector<long long int>&)':
subsequence.cpp:24:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x.size(); i++) os << x[i] << sp;
                    ^
subsequence.cpp: In function 'std::ostream& operator<<(std::ostream&, std::vector<std::pair<long long int, long long int> >&)':
subsequence.cpp:32:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x.size(); i++) os << x[i] << endl;
                    ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...