제출 #705716

#제출 시각아이디문제언어결과실행 시간메모리
705716abysmalLongest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
128 ms191776 KiB
#include<iostream> #include<stdio.h> #include<stdint.h> #include<vector> #include<algorithm> #include<utility> #include<set> #include<map> #include<queue> #include<stack> #include<deque> #include<string> #include<time.h> #include<iomanip> #include<assert.h> #include<math.h> #include<chrono> #include<random> #include<bitset> using namespace std; const int64_t INF = (int64_t) 5 * 1e5 + 5; const int64_t mINF = (int64_t) 1e9 + 5; const int64_t MOD = (int64_t) 1e9 + 9; const int nbit = 30; const int ndig = 10; const int nchar = 26; const int p1 = 31; const int p2 = 53; const int D = 4; int dr[D] = {0, 1, 0, -1}; int dc[D] = {1, 0, -1, 0}; // 0 right // 1 down // 2 left // 3 up struct Solution { int n; vector<int> a; vector<int> k; Solution() {} void solve() { cin >> n; a.resize(n, 0); k.resize(n, 0); for(int i = 0; i < n; i++) { cin >> a[i]; } for(int i = 0; i < n; i++) { cin >> k[i]; } int ans = 0; int e = -1; int max_val = (1 << 10); vector<int> p(n, -1); vector<vector<vector<int> > > pos(11, vector<vector<int> >(max_val, vector<int>(max_val, -1))); vector<vector<vector<int> > > dp(11, vector<vector<int> >(max_val, vector<int>(max_val, 0))); for(int i = 0; i < n; i++) { int left = a[i] & ((1 << 11) - 1); int right = a[i] >> 10; int max_ = 1; int id = -1; for(int mask = 0; mask < max_val; mask++) { int need = k[i] - __builtin_popcount(left & mask); if(need < 0 || need > 10) continue; if(max_ < dp[need][mask][right] + 1) { max_ = dp[need][mask][right] + 1; id = pos[need][mask][right]; } } p[i] = id; if(ans < max_) { ans = max_; e = i; } for(int mask = 0; mask < max_val; mask++) { int cnt = __builtin_popcount(right & mask); if(dp[cnt][left][mask] < max_) { dp[cnt][left][mask] = max_; pos[cnt][left][mask] = i; } } } cout << ans << "\n"; vector<int> path; while(e != -1) { path.push_back(e + 1); e = p[e]; } reverse(path.begin(), path.end()); for(int i = 0; i < (int) path.size(); i++) { cout << path[i] << " "; } cout << "\n"; } }; void __startup() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); } int main() { __startup(); int t = 1; // cin >> t; for(int i = 1; i <= t; i++) { Solution().solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...