제출 #600455

#제출 시각아이디문제언어결과실행 시간메모리
600455PlurmFinancial Report (JOI21_financial)C++11
5 / 100
46 ms3648 KiB
#include <bits/stdc++.h> using namespace std; int a[300005]; int dp[7005][7005]; // dp[last][max] class comp{ public: bool operator()(int x, int y){ return a[x] < a[y]; } }; int main(){ int n, d; scanf("%d%d",&n,&d); for(int i = 1; i <= n; i++){ scanf("%d", a+i); } if(n > 7000){ vector<int> lis; for(int i = 1; i <= n; i++){ auto it = lower_bound(lis.begin(), lis.end(), a[i]); if(it == lis.end()) lis.push_back(a[i]); else *it = a[i]; } printf("%d\n", lis.size()); return 0; } map<int,int,comp> mp; for(int i = 1; i <= n; i++){ for(int j = 1; j < i; j++){ if(a[j] < a[i]) continue; // dp[i][j] <- dp[k][j] for(int k = i-1; k >= i-d && k > 0; k--){ dp[i][j] = max(dp[i][j], dp[k][j]); } } // dp[i][i] dp[i][i] = 1; auto it = mp.lower_bound(i); if(it != mp.begin()){ --it; bool ok = true; while(it->second < i-d){ it = mp.erase(it); if(it == mp.begin()){ ok = false; break; } --it; } if(ok) dp[i][i] = dp[it->second][it->first] + 1; } for(int j = 0; j <= i; j++){ it = mp.lower_bound(j); while(it != mp.end() && dp[it->second][it->first] <= dp[i][j]){ it = mp.erase(it); } if(it == mp.begin()){ mp[j] = i; }else{ --it; if(dp[it->second][it->first] < dp[i][j]) mp[j] = i; } } } int ans = 0; for(int j = 0; j <= n; j++) ans = max(ans, dp[n][j]); printf("%d\n", ans); return 0; }

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

Main.cpp: In function 'int main()':
Main.cpp:27:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
   27 |     printf("%d\n", lis.size());
      |             ~^     ~~~~~~~~~~
      |              |             |
      |              int           std::vector<int>::size_type {aka long unsigned int}
      |             %ld
Main.cpp:16:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |   scanf("%d%d",&n,&d);
      |   ~~~~~^~~~~~~~~~~~~~
Main.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     scanf("%d", a+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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...