제출 #1007374

#제출 시각아이디문제언어결과실행 시간메모리
1007374vqpahmadLongest beautiful sequence (IZhO17_subsequence)C++17
100 / 100
2853 ms175232 KiB
#include<bits/stdc++.h>
using namespace std;
#ifdef ONPC
#include"debug.h"
#else
#define debug(...) 42
#endif
#define endl '\n'
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
const int mod = 1e9 + 7;
const int MAXN = 1e5 + 15;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
int dp[1025][1025][21], n, a[MAXN], b[MAXN];
int pos[1025][1025][21];
int prv[MAXN];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		cin >> b[i];

	memset(prv, -1, sizeof(prv));
	pii best = {0, 0};
	for (int i = 0; i < n; i++){
		int lhs = a[i] % (1 << 10), rhs = (a[i] >> 10);
		int opt = 0;
		for (int j = 0; j < 1024; j++){
			if (b[i] - __popcount(j&rhs) >= 0 && ckmax(opt, dp[j][lhs][b[i] - __popcount(j&rhs)])){
				prv[i] = pos[j][lhs][b[i] - __popcount(j&rhs)];
			}
		}
		for (int j = 0; j < 1024; j++){
			if (ckmax(dp[rhs][j][__popcount(j&lhs)], opt + 1)){
				pos[rhs][j][__popcount(j&lhs)] = i;
			}
		}
		debug(i, opt, prv[i]);
		ckmax(best, {opt + 1, i});
	}
	vector<int> ans;
	for (int i = best.S; i != -1; ans.pb(i), i = prv[i]);
	reverse(all(ans));
	cout << sz(ans) << endl;
	for (auto it : ans) cout << it + 1 << ' ';
}

컴파일 시 표준 에러 (stderr) 메시지

subsequence.cpp: In function 'int main()':
subsequence.cpp:6:20: warning: statement has no effect [-Wunused-value]
    6 | #define debug(...) 42
      |                    ^~
subsequence.cpp:50:3: note: in expansion of macro 'debug'
   50 |   debug(i, opt, prv[i]);
      |   ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...