이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using int64 = int64_t;
#define FOR(i, l, r) for(int i = (l), _r = (r); i <= _r; ++i)
#define FORD(i, r, l) for(int i = (r), _l = (l); i >= _l; --i)
#define rep(i, l, r) for(int i = (l), _r = (r); i < _r; ++i)
#define repd(i, r, l) for(int i = (r) - 1, _l = l; i >= _l; --i)
#define left __left
#define right __right
#define next __next
#define prev __prev
#define div __div
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()
#define compact(v) v.erase(unique(all(v)), end(v))
#define dbg(v) "[" #v " = " << (v) << "]"
#define file(name) if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
template<typename T>
bool minimize(T& a, const T& b){
if(a > b) return a = b, true;
return false;
}
template<typename T>
bool maximize(T& a, const T& b){
if(a < b) return a = b, true;
return false;
}
template<int dimension, typename T>
struct vec : public vector<vec<dimension - 1, T>> {
static_assert(dimension > 0, "Dimension must be positive !\n");
template<typename... Args>
vec(int n = 0, Args... args) : vector<vec<dimension - 1, T>> (n, vec<dimension - 1, T>(args...)) {}
};
template<typename T>
struct vec<1, T> : public vector<T> {
vec(int n = 0, T val = T()) : vector<T>(n, val) {}
};
void preprocess();
void init();
void process();
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
file("antuvu");
preprocess();
int T = 1; //cin >> T;
while(T--){
init();
process();
}
return 0;
}
const int MAX = 1e5 + 5;
const int B = 10;
int n, a[MAX], k[MAX], dp[MAX], trace[MAX];
pair<int, int> max_dp[1 << B][1 << B][B + 1];
int same(int i, int j){
return __builtin_popcount(i & j);
}
void preprocess(){
}
void init(){
cin >> n;
for(int i = 0; i < n; ++i) cin >> a[i];
for(int i = 0; i < n; ++i) cin >> k[i];
for(int i = 0; i < (1 << B); ++i){
for(int j = 0; j < (1 << B); ++j){
for(int k = 0; k < 11; ++k){
max_dp[i][j][k] = {-1, -1};
}
}
}
for(int i = 0; i < n; ++i){
int leftmost_bits = a[i] >> B;
int rightmost_bits = a[i] % (1 << B);
dp[i] = 1; trace[i] = i;
for(int mask = 0; mask < (1 << B); ++mask){
int demand = k[i] - same(mask, leftmost_bits);
if(demand < 0 || demand > B) continue;
if(maximize(dp[i], max_dp[mask][rightmost_bits][demand].first + 1)){
trace[i] = max_dp[mask][rightmost_bits][demand].second;
}
}
for(int mask = 0; mask < (1 << B); ++mask){
int tmp = same(mask, rightmost_bits);
if(maximize(max_dp[leftmost_bits][mask][tmp].first, dp[i])){
max_dp[leftmost_bits][mask][tmp].second = i;
}
}
}
int pos = max_element(dp, dp + n) - dp;
cout << dp[pos] << '\n';
stack<int> st;
st.push(pos);
while(trace[pos] != pos){
st.push(trace[pos]);
pos = trace[pos];
}
while(!st.empty()){
cout << st.top() + 1 << ' ';
st.pop();
}
}
void process(){
}
컴파일 시 표준 에러 (stderr) 메시지
subsequence.cpp: In function 'int main()':
subsequence.cpp:21:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | #define file(name) if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:55:5: note: in expansion of macro 'file'
55 | file("antuvu");
| ^~~~
subsequence.cpp:21:91: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | #define file(name) if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:55:5: note: in expansion of macro 'file'
55 | file("antuvu");
| ^~~~
# | 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... |