Submission #1200566

#TimeUsernameProblemLanguageResultExecution timeMemory
1200566nguynFinancial Report (JOI21_financial)C++20
48 / 100
4094 ms1604 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long 
#define F first
#define S second
#define pb push_back 
#define pii pair<int,int>

const int N = 3e5 + 5;

int f[N], a[N], n, d;
int last[N]; 

signed main(){
    ios_base::sync_with_stdio(false) ; 
    cin.tie(0) ; cout.tie(0) ; 
    if (fopen("INP.INP" ,"r")) {
        freopen("INP.INP" ,"r" , stdin) ;
        freopen("OUT.OUT" , "w" , stdout) ;
    }
    cin >> n >> d; 
    for (int i = 1; i <= n; i++) {
    	cin >> a[i]; 
    }
    for (int i = 1; i <= n; i++) {
    	int pre = i;
    	for (int j = i - 1; j >= 1; j--) {
    		if (pre - j > d) {
    			last[i] = j + 1; 
    			break; 
    		}
    		if (a[j] <= a[i]) {
    			pre = j;		
    		}	
    	}
    }
    int res = 0;
    for (int i = 1; i <= n; i++) {
    	f[i] = 1;
    	for (int j = 1; j < i; j++) {
    		if (last[i] <= j && a[i] > a[j]) {
    			f[i] = max(f[j] + 1, f[i]); 
    		}
    	}	
    	res = max(res, f[i]); 
    }
    cout << res;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen("INP.INP" ,"r" , stdin) ;
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen("OUT.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...