제출 #969762

#제출 시각아이디문제언어결과실행 시간메모리
969762RequiemFinancial Report (JOI21_financial)C++17
40 / 100
100 ms21328 KiB
#include<bits/stdc++.h> #define int long long #define pb push_back #define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); #define MOD 1000000007 #define INF 1e18 #define fi first #define se second #define FOR(i,a,b) for(int i=a;i<=b;i++) #define FORD(i,a,b) for(int i=a;i>=b;i--) #define sz(a) ((int)(a).size()) #define endl '\n' #define pi 3.14159265359 #define TASKNAME "financialreport" template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; } template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; } using namespace std; typedef pair<int,int> ii; typedef pair<int,ii> iii; typedef vector<int> vi; const int MAXN = 3e5 + 9; int a[MAXN], n, d; namespace subtask1{ bool checkSubtask1(){ return n <= 20; } void solveSubtask1(){ int res = 0; for(int msk = 0; msk < (1 << (n - 1)); msk++){ int prv = -1, mx = -INF, valid = 1, cur = 0; for(int j = 0; j < n; j++){ if ((msk & (1 << j)) or j == n - 1) { if (prv != -1 and j - prv > d) valid = 0; if (maximize(mx, a[j + 1])){ cur++; } prv = j; } } if (valid) maximize(res, cur); } cout << res << endl; } } namespace subtask2{ bool checkSubtask2(){ return n <= 400; } int dp[406][406]; void solveSubtask2(){ memset(dp, -0x3f, sizeof(dp)); dp[0][0] = 0; for(int i = 1; i <= n; i++){ dp[i][i] = 1; } a[0] = -INF; for(int i = 0; i <= n; i++){ //regard i for(int j = 0; j <= n; j++){ if (dp[i][j] > -INF){ // cout << i << ' ' << j << ' ' << dp[i][j] << endl; for(int k = i + 1; k <= min(i + d, n); k++){ int mxId = (a[j] >= a[k]) ? j : k; if (mxId == k) maximize(dp[k][mxId], dp[i][j] + 1); else maximize(dp[k][mxId], dp[i][j]); } } } } // cout << endl; int res = 0; for(int i = 0; i <= n; i++){ maximize(res, dp[n][i]); } cout << res << endl; } } namespace subtask4{ bool checkSubtask4(){ return d == 1; } void solveSubtask4(){ stack<int> st; int res = 1; st.push(n); for(int i = n - 1; i >= 1; i--){ while(!st.empty() and a[i] >= a[st.top()]) st.pop(); st.push(i); maximize(res, (int) st.size()); } cout << res << endl; } } namespace subtask5{ bool checkSubtask5(){ return d == n; } int dp[MAXN]; void solveSubtask5(){ multiset<int> st; int res = 0; for(int i = 1; i <= n; i++){ auto it = st.upper_bound(a[i]); // cout << st.size() << ' ' << i << endl; if (it == st.end()) st.insert(a[i]); else { st.erase(it); st.insert(a[i]); } } cout << (int) st.size() << endl; } } main() { fast; if (fopen(TASKNAME".inp","r")){ freopen(TASKNAME".inp","r",stdin); freopen(TASKNAME".out","w",stdout); } cin >> n >> d; for(int i = 1; i <= n; i++){ cin >> a[i]; } if (subtask1::checkSubtask1()) return subtask1::solveSubtask1(), 0; if (subtask2::checkSubtask2()) return subtask2::solveSubtask2(), 0; if (subtask4::checkSubtask4()) return subtask4::solveSubtask4(), 0; if (subtask5::checkSubtask5()) return subtask5::solveSubtask5(), 0; } /** Warning: - MLE / TLE? - Gioi han mang? - Gia tri max phai luon gan cho -INF - long long co can thiet khong? - tran mang. - code can than hon - Nho sinh test de tranh RTE / TLE --> Coi lai truoc khi nop **/

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

Main.cpp: In function 'void subtask5::solveSubtask5()':
Main.cpp:112:13: warning: unused variable 'res' [-Wunused-variable]
  112 |         int res = 0;
      |             ^~~
Main.cpp: At global scope:
Main.cpp:126:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  126 | main()
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:130:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  130 |         freopen(TASKNAME".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:131:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  131 |         freopen(TASKNAME".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...