Submission #1099708

#TimeUsernameProblemLanguageResultExecution timeMemory
1099708KasymKLongest beautiful sequence (IZhO17_subsequence)C++17
7 / 100
6062 ms1124 KiB
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N = 1e5+5;
const int INF = 1e9;
int a[N], k[N], n, bit[N], answer;
vector<int> A;

void f(int x){
    if(x == n+1){
        vector<int> ind;
        for(int i = 1; i <= n; ++i)
            if(bit[i])
                ind.pb(i);
        bool done = 1;
        for(int i = 1; i < (int)ind.size(); ++i)
            if(__builtin_popcount(a[ind[i-1]]&(a[ind[i]])) != k[ind[i]]){
                done = 0;
                break;
            }
        if(done and umax(answer, (int)ind.size()))
            A = ind;
        return;
    }
    for(int i = 0; i <= 1; ++i){
        bit[x] = i;
        f(x+1);
    }
}

int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i)
        scanf("%d", a+i);
    for(int i = 1; i <= n; ++i)
        scanf("%d", k+i);
    f(1);
    printf("%d\n", answer);
    for(int i : A)
        printf("%d ", i);
    puts("");
    return 0;
}

Compilation message (stderr)

subsequence.cpp: In function 'int main()':
subsequence.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
subsequence.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         scanf("%d", a+i);
      |         ~~~~~^~~~~~~~~~~
subsequence.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         scanf("%d", k+i);
      |         ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...