이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#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)
using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;
using ll = long long;
//#define int ll
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 6e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);
//template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r) { return uniform_int_distribution<int> (l, r)(rng); }
int n, dp[(1 << 20) + 3], pr[(1<<20)+3], last[(1<<20)+3];
pii a[N];
main() {
file("paint");
ios;
cin >> n;
fo(i, 1, n, 1) cin >> a[i].F;
fo(i, 1, n, 1) cin >> a[i].S;
int mx = 0, st;
fo(i, 1, n, 1) {
bool flag = 0;
chmax(dp[a[i].F], 1);
if (i <= 5000) {
foo(j, i - 1, 1, 1) {
if (bit(a[j].F & a[i].F) == a[i].S) {
int submask = a[j].F;
if (dp[a[i].F] < dp[submask] + 1) {
flag = 1;
pr[i] = last[submask];
dp[a[i].F] = dp[submask] + 1;
}
}
}
} else {
for (int submask = 0; submask < (1 << 8); ++submask) {
if (bit(submask & a[i].F) == a[i].S) {
if (dp[a[i].F] < dp[submask] + 1) {
flag = 1;
pr[i] = last[submask];
chmax(dp[a[i].F], dp[submask] + 1);
}
}
}
}
last[a[i].F] = i;
if (mx < dp[a[i].F]) mx = dp[a[i].F], st = i;
}
cout << mx << "\n";
vi ans;
while (st) ans.eb(st), st = pr[st];
while (!ans.empty()) cout << ans.back() << " ", ans.pop_back();
return 0;
}
/**
4
1 2 3 4
10 0 1 0
5
5 3 5 3 5
10 1 20 1 20
*/
컴파일 시 표준 에러 (stderr) 메시지
subsequence.cpp:63:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
63 | main() {
| ^
subsequence.cpp: In function 'int main()':
subsequence.cpp:71:10: warning: variable 'flag' set but not used [-Wunused-but-set-variable]
71 | bool flag = 0;
| ^~~~
subsequence.cpp:23:48: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
23 | #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
subsequence.cpp:64:3: note: in expansion of macro 'file'
64 | file("paint");
| ^~~~
subsequence.cpp:23:77: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
23 | #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:64:3: note: in expansion of macro 'file'
64 | file("paint");
| ^~~~
# | 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... |