Submission #886665

#TimeUsernameProblemLanguageResultExecution timeMemory
886665fanwenFinancial Report (JOI21_financial)C++17
48 / 100
4049 ms7224 KiB
/* author : bo may can 5 */

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define ll long long
#define file(name)                  \
    if(fopen(name".inp", "r"))      \
        freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout); 

const int MAX = 3e5 + 5;

int n, D, A[MAX], dp[MAX];

void you_make_it(void) {
    cin >> n >> D;
    for (int i = 1; i <= n; ++i) cin >> A[i];
    vector <int> comp(A + 1, A + n + 1);
	sort(comp.begin(), comp.end());
	comp.erase(unique(comp.begin(), comp.end()), comp.end());

	for (int i = 1; i <= n; ++i) {
		A[i] = upper_bound(comp.begin(), comp.end(), A[i]) - comp.begin() + 1;
	}

	for (int i = 1; i <= n; ++i) {
		dp[i] = 1;
		int d = 0;
		for (int j = i - 1; j >= 1; --j) {
			if(A[j] >= A[i]) d++;
			else d = 0;
			if(d >= D) break;
			if(A[j] < A[i]) dp[i] = max(dp[i], dp[j] + 1);
		}
	}
	cout << *max_element(dp + 1, dp + n + 1);
}

signed main() {

#ifdef LOCAL
    freopen("TASK.inp", "r", stdin);
    freopen("TASK.out", "w", stdout);
#endif
    file("financial");
    auto start_time = chrono::steady_clock::now();

    cin.tie(0), cout.tie(0) -> sync_with_stdio(0);

    you_make_it();

    auto end_time = chrono::steady_clock::now();

    cerr << "\nExecution time : " << chrono::duration_cast <chrono::milliseconds> (end_time - start_time).count() << "[ms]" << endl;

    return (0 ^ 0);
}

// Dream it. Wish it. Do it.

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:12:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:48:5: note: in expansion of macro 'file'
   48 |     file("financial");
      |     ^~~~
Main.cpp:12:49: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout);
      |                                          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:48:5: note: in expansion of macro 'file'
   48 |     file("financial");
      |     ^~~~
#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...