제출 #38302

#제출 시각아이디문제언어결과실행 시간메모리
38302Just_Solve_The_ProblemLongest beautiful sequence (IZhO17_subsequence)C++11
0 / 100
0 ms93304 KiB
#include <bits/stdc++.h> using namespace std; #define pii pair < int, int > #define fr first #define sc second const int N = (int)1e5 + 7; const int m = 1 << 10; int a[N], k[N]; int bit[m]; pii dp[m][m][11]; int par[N]; main () { freopen("subsequence.in", "r", stdin); freopen("subsequence.out", "w", stdout); int n; scanf ("%d", &n); for (int j = 0; j < 2; j++) for (int i = 1; i <= n; i++) if (!j) scanf ("%d", a + i); else scanf ("%d", k + i); for (int i = 1; i < m; i++) { bit[i] = __builtin_popcount(i); } int ans, ansid; ans = ansid = 0; for (int i = 1; i <= n; i++) { int pr = (a[i] >> 10); int sf = (a[i] % m); int mx = 1, id = 0; for (int j = 0; j < m; j++) { int need = k[i] - bit[j & pr]; if (need < 0 || need > 10) continue; if (mx < dp[j][sf][need].fr + 1) { mx = dp[j][sf][need].fr + 1; id = dp[j][sf][need].sc; } } par[i] = id; for (int j = 0; j < m; j++) { int need = bit[j & sf]; if (dp[pr][j][need].fr < mx) { dp[pr][j][need] = {mx, i}; } } if (ans < mx) { ans = mx; ansid = i; } } cout << ans << endl; vector < int > asd; while (ansid) { asd.push_back(ansid); ansid = par[ansid]; } reverse(asd.begin(), asd.end()); for (auto to : asd) { cout << to << ' '; } }

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

subsequence.cpp:17:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
subsequence.cpp: In function 'int main()':
subsequence.cpp:18:42: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("subsequence.in", "r", stdin);
                                          ^
subsequence.cpp:19:44: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("subsequence.out", "w", stdout);
                                            ^
subsequence.cpp:20:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int n; scanf ("%d", &n);
                            ^
subsequence.cpp:24:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
                 scanf ("%d", a + i);
                                    ^
subsequence.cpp:26:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
                 scanf ("%d", k + 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...