이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
DEATH-MATCH
Davit-Marg
*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iterator>
#include <ctype.h>
#include <stdlib.h>
#include <cassert>
#include <fstream>
#define mod 998244353ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
using namespace std;
int bitCount(int x)
{
int res=0;
while (x)
{
res += x % 2;
x /= 2;
}
return res;
}
int bitCount(int a, int b)
{
return bitCount(a&b);
}
int n, a[100005], k[100005],dp[100005],nxt[100005],last[(1<<20)+10],mx;
vector<int> ans;
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
mx = max(mx,a[i]);
}
for (int i = 1; i <= n; i++)
cin >> k[i];
if (n<=5000 && 0)
{
dp[n] = 1;
for (int i = n - 1; i >= 1; i--)
{
dp[i] = 1;
for (int j = i + 1; j <= n; j++)
if (bitCount(a[i], a[j]) == k[j] && dp[i] < 1 + dp[j])
{
dp[i] = 1 + dp[j];
nxt[i] = j;
}
}
mx = 0;
for (int i = 1; i <= n; i++)
mx = max(dp[i], mx);
for (int i = 1; i <= n; i++)
if (dp[i] == mx)
{
while (i)
{
ans.PB(i);
i = nxt[i];
}
break;
}
}
else
{
for (int i = 1; i <= n; i++)
{
dp[i] = 1;
for (int j = 0; j <= (1 << 9); j++)
if (last[j] != 0 && bitCount(a[i], j) == k[i] && dp[i] <= 1 + dp[last[j]])
{
dp[i] = 1 + dp[last[j]];
nxt[i] = last[j];
}
last[a[i]] = i;
}
mx = 0;
for (int i = 1; i <= n; i++)
mx = max(dp[i], mx);
for (int i = 1; i <= n; i++)
if (dp[i] == mx)
{
while (i)
{
ans.PB(i);
i = nxt[i];
}
break;
}
}
cout << ans.size() << endl;
sort(ans.begin(), ans.end());
for (int i = 0; i < ans.size(); i++)
cout << ans[i] << " ";
cout << endl;
return 0;
}
/*
11
5 5 13 17 7 17 5 5 1 5 5
2 2 2 1 2 2 1 1 1 1 2
7
5 5 13 17 7 17 5
2 2 2 1 2 1 1
2
8 9
20 0
5
5 3 5 3 5
10 1 20 1 20
4
1 2 3 4
10 0 1 0
*/
컴파일 시 표준 에러 (stderr) 메시지
subsequence.cpp: In function 'int main()':
subsequence.cpp:118:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < ans.size(); i++)
~~^~~~~~~~~~~~| # | 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... |