제출 #885179

#제출 시각아이디문제언어결과실행 시간메모리
885179alex_2008Longest beautiful sequence (IZhO17_subsequence)C++14
7 / 100
8 ms444 KiB
#include <bits/stdc++.h> using namespace std; const int N = 16; int a[N], k[N]; int bitCount(int x) { int v = 0; while (x > 0) { v += (x & 1); x >>= 1; } return v; } int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> k[i]; } vector <int> ans = {}; for (int i = 0; i < (1 << n); i++) { vector <int> v; for (int j = 0; j < n; j++) { if ((i & (1 << j)) != 0) { v.push_back(j); } } bool ch = true; for (int j = 1; j < (int)v.size(); j++) { if (k[v[j]] != bitCount((a[v[j - 1]] & a[v[j]]))) ch = false; } if (ch) { if ((int)v.size() > (int)ans.size()) { ans = v; } } } cout << (int)ans.size() << "\n"; for (auto it : ans) { cout << it + 1 << " "; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...