제출 #1314203

#제출 시각아이디문제언어결과실행 시간메모리
1314203tredsused70Longest beautiful sequence (IZhO17_subsequence)C++20
컴파일 에러
0 ms0 KiB
//#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("avx,avx2") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2") //#pragma GCC optimize("trapv") #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define all(x) x.begin(), x.end() #define mpr make_pair typedef long long ll; typedef unsigned long long ull; typedef long double ld; const int nmax = 100001, mod = 1000000007, inf = 2000010000, key = 200003, lg = 20, block = 300; const ll infll = 4000000000000000000; const ld eps = 1e-9; int pr[nmax]; array<int, 2> max_seq[1 << 10][1 << 10][21]; int nums[nmax], bits[nmax]; int popcount[1024][1024]; void solve() { int n; cin >> n; for(int i = 1; i <= n; i++) cin >> nums[i]; for(int i = 0; i < 1024; i++) for(int j = 0; j < 1024; j++) { popcount[i][j] = __builtin_popcount(i & j); for(int k = 0; k <= 20; k++) max_seq[i][j][k] = {0, -1}; } int ans = 0, last_ind = -1; for(int i = 1; i <= n; i++) { cin >> bits[i]; int first_half = nums[i] & (1023); int second_half = (nums[i] >> 10); array<int, 2> prev_max = {0, -1}; for(int j = 0; j < 1024; j++) { int &cnt_first = popcount[first_half][j]; int cnt_req = bits[i] - cnt_first; if(cnt_req < 0) continue; prev_max = max(prev_max, max_seq[j][second_half][cnt_req]); } pr[i] = prev_max[1]; if(prev_max[0] + 1 > ans) { ans = prev_max[0] + 1; last_ind = i; } array<int, 2> cur_max = {prev_max[0] + 1, i}; for(int j = 0; j < 1024; j++) { int &cnt_second = popcount[second_half][j]; max_seq[first_half][j][cnt_second] = max(max_seq[first_half][j][cnt_second], cur_max); } } cout << ans << "\n"; vector<int> seq; seq.pb(last_ind); for(int i = 1; i < ans; i++) { last_ind = pr[last_ind]; seq.pb(last_ind); } reverse(all(seq)); for(int i : seq) cout << i << " "; cout << "\n"; return ; } int main() { //freopen("movie.in","r",stdin); //freopen("movie.out","w",stdout); ios_base::sync_with_stdio(0);cin.tie(0); srand(8713); //init(); int t = 1; //cin >> t; //int t_ = t; //t = rdi(); while(t--) { //cout << "Case #" << t_ - t << ": "; solve(); } //flush(); return 0; } /* 9 5 3 1 5 7 8 6 9 7 3 3 C 7 C 5 W */

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

subsequence.cpp: In function 'void solve()':
subsequence.cpp:35:13: error: reference to 'popcount' is ambiguous
   35 |             popcount[i][j] = __builtin_popcount(i & j);
      |             ^~~~~~~~
In file included from /usr/include/c++/13/bits/stl_algobase.h:76,
                 from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from subsequence.cpp:6:
/usr/include/c++/13/bit:426:5: note: candidates are: 'template<class _Tp> constexpr std::_If_is_unsigned_integer<_Tp, int> std::popcount(_Tp)'
  426 |     popcount(_Tp __x) noexcept
      |     ^~~~~~~~
subsequence.cpp:25:5: note:                 'int popcount [1024][1024]'
   25 | int popcount[1024][1024];
      |     ^~~~~~~~
subsequence.cpp:46:30: error: reference to 'popcount' is ambiguous
   46 |             int &cnt_first = popcount[first_half][j];
      |                              ^~~~~~~~
/usr/include/c++/13/bit:426:5: note: candidates are: 'template<class _Tp> constexpr std::_If_is_unsigned_integer<_Tp, int> std::popcount(_Tp)'
  426 |     popcount(_Tp __x) noexcept
      |     ^~~~~~~~
subsequence.cpp:25:5: note:                 'int popcount [1024][1024]'
   25 | int popcount[1024][1024];
      |     ^~~~~~~~
subsequence.cpp:59:31: error: reference to 'popcount' is ambiguous
   59 |             int &cnt_second = popcount[second_half][j];
      |                               ^~~~~~~~
/usr/include/c++/13/bit:426:5: note: candidates are: 'template<class _Tp> constexpr std::_If_is_unsigned_integer<_Tp, int> std::popcount(_Tp)'
  426 |     popcount(_Tp __x) noexcept
      |     ^~~~~~~~
subsequence.cpp:25:5: note:                 'int popcount [1024][1024]'
   25 | int popcount[1024][1024];
      |     ^~~~~~~~