Submission #515737

#TimeUsernameProblemLanguageResultExecution timeMemory
515737goodluck2020Financial Report (JOI21_financial)C++14
40 / 100
301 ms20004 KiB
#include <bits/stdc++.h> #define task "JOI21_FINANCIAL" using namespace std; const int N = 3e5 + 5; int n, A[N], D; set < int > Set; int CP[N], cnt; void compress() { for(int i = 1; i <= n; i++) Set.insert(A[i]); for(int j : Set) CP[++cnt] = j; for(int i = 1; i <= n; i++) A[i] = lower_bound(CP + 1, CP + cnt + 1, A[i]) - CP; } namespace sub2 { int dp[405][405], ans; void solve() { for(int i = 0; i <= n; i++) for(int j = 0; j <= n; j++) dp[i][j] = -1e9; dp[0][0] = 0; for(int i = 0; i < n; i++) { if(i) dp[i][A[i]] = max(dp[i][A[i]], 1); for(int j = 0; j <= n; j++) for(int t = i + 1; t <= i + D; t++) if(t <= n) dp[t][max(A[t], j)] = max(dp[t][max(A[t], j)], dp[i][j] + (A[t] > j)); } for(int j = 0; j <= n; j++) ans = max(ans, dp[n][j]); cout << ans; } } namespace sub4 { int L[N], St[N], top, ans; priority_queue < int > pq; void solve() { for(int i = 1; i <= n; i++) { while(top && A[i] > A[St[top]]) top--; L[i] = St[top] + 1; St[++top] = i; } for(int i = n; i >= 1; i--) { pq.push(L[i]); while(pq.top() > i) pq.pop(); ans = max(ans, (int)pq.size()); } cout << ans; } } int main() { if(fopen(task ".inp","r")) { freopen(task ".inp","r",stdin); freopen(task ".out","w",stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> D; for(int i = 1; i <= n; i++) cin >> A[i]; compress(); if(n <= 400) sub2::solve(); else if(D == 1) sub4::solve(); }

Compilation message (stderr)

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