# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
661049 | Kaztaev_Alisher | Longest beautiful sequence (IZhO17_subsequence) | C++17 | 49 ms | 588 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optomize ("Ofast")
//#pragma GCC optomize ("unroll-loops")
//#pragma GCC target ("avx,avx2,fma")
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define sz size
#define cl clear
#define ins insert
#define ers erase
#define pii pair < int , int >
#define pll pair< long long , long long >
#define all(x) x.begin() , x.end()
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define tostr(x) to_string(x)
#define tonum(s) atoi(s.c_str())
#define seon(x) setprecision(x)
#define bpop(x) __builtin_popcount(x)
#define deb(x) cerr << #x << " = " << x << endl;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
const double PI = 3.14159265;
const ll N = 5000+5;
const ll mod = 1e9+7;
const ll inf = 1e9;
const ll INF = 1e18;
using namespace std;
int a[N] , k[N] , dp[N] , p[N];
void solve(){
int n;
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i] , p[i] = i;
for(int i = 1; i <= n; i++) cin >> k[i];
for(int i = 1; i <= n; i++){
for(int j = 1; j < i; j++){
if(bpop((a[i] & a[j])) == k[i]){
if(dp[i] < dp[j]+1){
p[i] = j;
dp[i] = dp[j] + 1;
}
}
}
}
int ans = 0 , x = 1;
for(int i = 1; i <= n; i++){
if(dp[i] > ans){
x = i;
ans = dp[i];
}
}
vector<int> v;
while(p[x] != x){
v.pb(x);
x = p[x];
}
v.pb(x);
reverse(all(v));
cout << v.sz() <<"\n";
for(int x : v) cout << x <<" ";
}
signed main(){
file("subsequence");
ios;
solve();
return 0;
}
/*
*/
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |