제출 #630593

#제출 시각아이디문제언어결과실행 시간메모리
630593Do_you_copyLongest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
71 ms173060 KiB
#include <bits/stdc++.h> //#define int long long #define fi first #define se second #define pb push_back #define faster ios_base::sync_with_stdio(0); cin.tie(0); using namespace std; using ll = long long; using ull = unsigned ll; using ld = long double; using pii = pair <int, int>; using pil = pair <int, ll>; using pli = pair <ll, int>; using pll = pair <ll, ll>; mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count()); ll min(const ll &a, const ll &b){ return (a < b) ? a : b; } ll max(const ll &a, const ll &b){ return (a > b) ? a : b; } //const ll Mod = 1000000007; //const ll Mod2 = 999999999989; //only use when required const int maxN = 1e5 + 1; const int maxH = 1025; const int maxK = 21; int n; int f[2][maxH][maxH][maxK]; pii dp[maxN]; int a[maxN]; int p[maxN]; pii ans; void Init(){ cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= n; ++i) cin >> p[i]; memset(f, -1, sizeof(f)); for (int i = 0; i <= n; ++i){ int pos = i % 2; int l = a[i] >> 10; int r = a[i] & ((1 << 10) - 1); dp[i] = {1, -1}; for (int j = 0; j < 1 << 10; ++j){ int cntl = __builtin_popcount(j & l); const int &k = p[i]; int cntr = k - cntl; if (cntr < 0 || cntr > 10) continue; if (f[pos ^ 1][j][r][k] != -1){ dp[i] = max(dp[i], {dp[f[pos ^ 1][j][r][k]].fi + 1, f[pos ^ 1][j][r][k]}); } } ans = max(ans, {dp[i].fi, i}); for (int j = 0; j < 1 << 10; ++j){ int cntr = __builtin_popcount(j & r); f[pos][l][j][cntr] = i; } } vector <int> res; cout << ans.fi << "\n"; while (ans.se != -1){ res.pb(ans.se); ans = dp[dp[ans.se].fi]; } reverse(res.begin(), res.end()); for (int i: res) cout << i << " "; } #define debu #define taskname "test" signed main(){ if (fopen(taskname".inp", "r")){ freopen(taskname".inp", "r", stdin); #ifdef debug freopen(taskname".out", "w", stdout); #endif } faster; ll tt = 1; //cin >> tt; while (tt--){ Init(); } if (fopen("timeout.txt", "r")){ ofstream timeout("timeout.txt"); timeout << 1000 * double(clock()) / CLOCKS_PER_SEC; #ifndef debug cerr << "\nTime elapsed: " << 1000 * double(clock()) / CLOCKS_PER_SEC << "ms\n"; #endif } }

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

subsequence.cpp: In function 'int main()':
subsequence.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...