Submission #486671

#TimeUsernameProblemLanguageResultExecution timeMemory
486671my04Longest beautiful sequence (IZhO17_subsequence)C++17
7 / 100
1 ms332 KiB
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define sz(x) (int)(x).size() #define S second #define F first #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; void setIO(string name = "") { ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); if (sz(name)) { freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } } const int inf = 1e9; const ll INF = 1e18; const int mod = 1e9 + 7; const int MAXN = 1e6 + 5; int n; int a[MAXN]; int k[MAXN]; void solve() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> k[i]; } int best = 0; int res = 0; for (int mask = 0; mask < (1 << n); mask++) { int prev = -1; int cur = 0; bool bad = 0; for (int i = 0; i < n; i++) { if (mask & (1 << i)) { if (prev == -1) { prev = i; cur++; continue; } int x = (a[prev] & a[i]); if (__builtin_popcount(x) == k[i]) { cur++; prev = i; } else { bad = 1; break; } } } if (bad == 0 && best <= cur) { best = cur; res = mask; } } cout << best << '\n'; for (int i = 0; i < n; i++) { if (res & (1 << i)) cout << i + 1 << ' '; } } main() { setIO(); int tt = 1; // cin >> tt; while (tt--) { solve(); } return 0; }

Compilation message (stderr)

subsequence.cpp:89:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   89 | main() {
      | ^~~~
subsequence.cpp: In function 'void setIO(std::string)':
subsequence.cpp:19:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   freopen((name + ".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:20:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |   freopen((name + ".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...