제출 #1082388

#제출 시각아이디문제언어결과실행 시간메모리
1082388steveonalexLongest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
38 ms90704 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define MASK(i) (1LL << (i)) #define GETBIT(mask, i) (((mask) >> (i)) & 1) #define ALL(v) (v).begin(), (v).end() #define block_of_code if(true) ll max(ll a, ll b){return (a > b) ? a : b;} ll min(ll a, ll b){return (a < b) ? a : b;} ll gcd(ll a, ll b){return __gcd(a, b);} ll lcm(ll a, ll b){return a / gcd(a, b) * b;} ll LASTBIT(ll mask){return (mask) & (-mask);} int pop_cnt(ll mask){return __builtin_popcountll(mask);} int ctz(ull mask){return __builtin_ctzll(mask);} int logOf(ull mask){return 63 - __builtin_clzll(mask);} mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);} double rngesus_d(double l, double r){ double cur = rngesus(0, MASK(60) - 1); cur /= MASK(60) - 1; return l + cur * (r - l); } template <class T1, class T2> bool maximize(T1 &a, T2 b){ if (a < b) {a = b; return true;} return false; } template <class T1, class T2> bool minimize(T1 &a, T2 b){ if (a > b) {a = b; return true;} return false; } template <class T> void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){ for(auto item: container) out << item << separator; out << finish; } template <class T> void remove_dup(vector<T> &a){ sort(ALL(a)); a.resize(unique(ALL(a)) - a.begin()); } const int N = 10; pair<int, int> ma[MASK(N)][MASK(N)][N+1]; int main(void){ ios::sync_with_stdio(0);cin.tie(0); cout.tie(0); clock_t start = clock(); int n; cin >> n; vector<int> a(n), k(n); for(int i = 0; i<n; ++i) cin >> a[i]; for(int j = 0; j<n; ++j) cin >> k[j]; for(int i = 0; i<MASK(N); ++i) for(int j = 0; j < MASK(N); ++j) for(int k = 0; k<=N; ++k) ma[i][j][k] = {-1, -1}; vector<pair<int,int>> dp(n, {0, -1}); for(int i = 0; i<n; ++i){ int first_half = a[i] % MASK(N), second_half = a[i] / MASK(N); for(int mask = 0; mask < MASK(N); ++mask){ int cnt = pop_cnt(mask & first_half); if (cnt <= k[i]) maximize(dp[i], ma[mask][second_half][k[i] - cnt]); } dp[i].first++; for(int mask = 0; mask < MASK(N); ++mask){ maximize(ma[first_half][mask][pop_cnt(second_half & mask)], make_pair(dp[i].first, i)); } } int u = max_element(ALL(dp)) - dp.begin(); int step = dp[u].first; cout << step << "\n"; vector<int> ans; while(u >= 0){ ans.push_back(u+1); u = dp[u].second; } reverse(ALL(ans)); printArr(ans); if (ans.size() != step) exit(1); for(int i = 1; i<ans.size(); ++i) if (pop_cnt(a[ans[i-1]] & a[ans[i]]) == k[ans[i]]) exit(2); cerr << "Time elapsed: " << clock() - start << " ms\n"; return 0; }

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

subsequence.cpp: In function 'int main()':
subsequence.cpp:97:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   97 |     if (ans.size() != step) exit(1);
      |         ~~~~~~~~~~~^~~~~~~
subsequence.cpp:98:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |     for(int i = 1; i<ans.size(); ++i) if (pop_cnt(a[ans[i-1]] & a[ans[i]]) == k[ans[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...