제출 #515288

#제출 시각아이디문제언어결과실행 시간메모리
515288MazaalaiLongest beautiful sequence (IZhO17_subsequence)C++17
23 / 100
6088 ms2340 KiB
#include <bits/stdc++.h>
#define pb push_back
#define ALL(x) x.begin(),x.end()
using namespace std;

const int N = 1e5+1;
int n;
int nums[N], bits[N], dp[N], par[N];
int bitCnt(int a) {
	return bitset <20>(a).count();
}
signed main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;

	int ans = 1;
	for (int i = 1; i <= n; i++) cin >> nums[i];
	for (int i = 1; i <= n; i++) cin >> bits[i];
	for (int i = 1; i <= n; i++) {
		for (int j = i+1; j <= n; j++) {
			if (bits[j] == bitCnt(nums[i]&nums[j]) && dp[j] < dp[i]+1) {
				dp[j] = dp[i]+1;
				par[j] = i;
			} 
		}
		if (dp[ans] < dp[i]) ans = i;
	}
	vector <int> tmp;
	while(ans != 0) {
		tmp.pb(ans);
		ans = par[ans];
	}
	cout << tmp.size() << '\n';
	reverse(ALL(tmp));
	for (auto el : tmp) cout << el << ' '; cout << '\n';
}

컴파일 시 표준 에러 (stderr) 메시지

subsequence.cpp: In function 'int main()':
subsequence.cpp:39:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   39 |  for (auto el : tmp) cout << el << ' '; cout << '\n';
      |  ^~~
subsequence.cpp:39:41: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   39 |  for (auto el : tmp) cout << el << ' '; cout << '\n';
      |                                         ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...