제출 #465425

#제출 시각아이디문제언어결과실행 시간메모리
465425YuisuyunoLongest beautiful sequence (IZhO17_subsequence)C++14
40 / 100
6018 ms2424 KiB
//Nguyen Huu Hoang Minh #include <bits/stdc++.h> #define sz(x) int(x.size()) #define all(x) x.begin(),x.end() #define reset(x) memset(x, 0,sizeof(x)) #define bc(x) __builtin_popcount(x) #define pb push_back #define mp make_pair #define fi first #define se second #define N 100005 #define remain(x) if (x > MOD) x -= MOD #define ii pair<int, int> #define iiii pair< ii , ii > #define viiii vector< iiii > #define vi vector<int> #define vii vector< ii > #define bit(x, i) (((x) >> (i)) & 1) #define Task "test" using namespace std; typedef long double ld; const int inf = 1e10; const int minf = -1e10; int n; int a[N]; int k[N]; void readfile() { ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); if (fopen(Task".inp","r")) { freopen(Task".inp","r",stdin); //freopen(Task".out","w",stdout); } cin >> n; for(int i=1; i<=n; i++) cin >> a[i]; for(int i=1; i<=n; i++) cin >> k[i]; } int dp[N]; int Mx[N], ptr; int trc[N]; void proc() { for(int i=1; i<=n; i++) dp[i] = 1; int mx=1, ptr=1; for(int i=1; i<=n; i++){ Mx[i] = max(Mx[i-1],dp[i]); if (bc(a[i]) < k[i]) continue; for(int j=i-1; j>=1; j--){ if (bc(a[i] & a[j])==k[i]){ if (dp[j] >= dp[i]){ dp[i] = dp[j]+1; trc[i] =j; } if (dp[i] > mx){ mx = dp[i]; ptr = i; } } if (Mx[j] < dp[i]) break; } Mx[i] = max(Mx[i-1],dp[i]); } vector<int> ans; while (ptr){ ans.pb(ptr); ptr=trc[ptr]; } reverse(all(ans)); cout << ans.size() << '\n'; for(auto x : ans) cout << x << ' '; } signed main() { readfile(); proc(); return 0; }

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

subsequence.cpp:24:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+10' to '2147483647' [-Woverflow]
   24 | const int inf = 1e10;
      |                 ^~~~
subsequence.cpp:25:18: warning: overflow in conversion from 'double' to 'int' changes value from '-1.0e+10' to '-2147483648' [-Woverflow]
   25 | const int minf = -1e10;
      |                  ^~~~~
subsequence.cpp: In function 'void readfile()':
subsequence.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         freopen(Task".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...