# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
211286 | vinhhung053 | Longest beautiful sequence (IZhO17_subsequence) | C++14 | 6 ms | 384 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORE(it,v) for(__typeof((v).begin() it=(v).begin();it!=(v).end();i++)
#define IN(v) cerr<<v<<endl
#define SET(a,x) memset((a),(x),sizeof(a))
#define mod 1000000000
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
typedef pair<ll,int> lii;
template <typename T> inline void read(T &x)
{
int am=0;char k;
while(!(isdigit(k=getchar()))&&k!='-');
if (k=='-') k=getchar(),am=1;
x=k-48;
while(isdigit(k=getchar())) x=x*10+k-48;
if (am) x=-x;
}
template <typename T> inline void writep(T x)
{
if (x>=10) writep(x/10);
putchar(x%10+48);
}
template <typename T> inline void write(T x)
{
if(x<0) putchar ('-'),x=-x;
writep(x);
}
template <typename T> inline void writeln(T x)
{
write(x);
putchar('\n');
}
template <typename T> inline void writesp(T x)
{
write(x);
putchar(' ');
}
const int N=1000005;
int n, a[N], k[N], f[N],trace[N];
int bitcount(int so)
{
int dem=0;
while(so) dem+=so%2,so=so/2;
return dem;
}
void Solve()
{
cin >> n;
FOR(i,1,n) cin >> a[i];
FOR(i,1,n) cin >> k[i];
int mx=1,vt=1;
FOR(i,1,n) f[i]=1;
FOR(i,2,n)
FOR(j,1,i-1) if (bitcount(a[i]&a[j])==k[i])
if(f[i]<f[j]+1)
{
f[i]=f[j]+1;
trace[i]=j;
mx=f[i];vt=i;
}
cout << mx <<endl;
deque<int> g;
while(mx) g.push_front(vt),mx--,vt=trace[vt];
FOR(i,0,(int)g.size()-1) cout << g[i] << " ";
}
int main()
{
if (fopen("text.inp","r"))
{
freopen("text.inp","r",stdin);
freopen("text.out","w",stdout);
}
else
{
freopen("subsequence.in","r",stdin);
freopen("subsequence.out","w",stdout);
}
ios_base::sync_with_stdio(false);
Solve();
}
컴파일 시 표준 에러 (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... |