이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME (1.0 * clock() / CLOCKS_PER_SEC)
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 1e6 + 5, B = 1024;
const int oo = 1e9, mod = 1e9 + 7;
int n, a[N], k[N], p[N], dp[21][B][B], g[21][B][B];
array<int, 2> res;
signed process() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
foru(i, 0, n - 1) cin >> a[i];
foru(i, 0, n - 1) {
cin >> k[i];
int curr = 1, req, x = (a[i] & (B - 1)), r = (a[i] ^ x) >> 10;
p[i] = -1;
foru(l, 0, B - 1) {
req = k[i] - __builtin_popcount(l & x);
if (0 <= req && curr <= dp[req][r][l]) {
curr = dp[req][r][l] + 1;
p[i] = g[req][r][l];
}
}
foru(j, 0, B - 1) {
req = __builtin_popcount(j & r);
if (dp[req][j][x] < curr) {
dp[req][j][x] = curr;
g[req][j][x] = i;
}
}
res = max(res, {curr, i});
}
cout << res[0] << '\n';
int ans[res[0]];
foru(i, 0, res[0] - 1) {
ans[i] = res[1];
res[1] = p[res[1]];
}
ford(i, res[0]-1, 0) cout << ans[i] + 1 << ' ';
}
signed main() {
cin.tie(0)->sync_with_stdio(false);
//freopen(".inp", "r", stdin);
//freopen(".out", "w", stdout);
process();
cerr << "Time elapsed: " << __TIME << " s.\n";
return 0;
}
// dont stop
컴파일 시 표준 에러 (stderr) 메시지
subsequence.cpp: In function 'int process()':
subsequence.cpp:58:1: warning: no return statement in function returning non-void [-Wreturn-type]
58 | }
| ^
# | 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... |