답안 #405877

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
405877 2021-05-17T02:09:06 Z ignaciocanta Global Warming (CEOI18_glo) C++14
100 / 100
68 ms 4240 KB
#include <bits/stdc++.h>

using namespace std;

//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template<class T> using Tree = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
 
using tint = long long;
using ld = long double;
 
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)	
 
using pi = pair<int,int>;
using pl = pair<tint,tint>;
using vi = vector<int>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vvi = vector<vi>;
using vl = vector<tint>;
using vb = vector<bool>;
 
#define pb push_back
#define pf push_front
#define rsz resize
#define all(x) begin(x), end(x)
#define rall(x) x.rbegin(), x.rend() 
#define sz(x) (int)(x).size()
#define ins insert
 
#define f first
#define s second
#define mp make_pair
 
#define DBG(x) cerr << #x << " = " << x << endl;
 
const int MOD = 1e9+7; 
const int mod = 998244353;
const int MX = 2e5+5;
const tint INF = 1e18; 
const int inf = 2e9;
const ld PI = acos(ld(-1)); 
const ld eps = 1e-5;
 
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
 
template<class T> void remDup(vector<T> &v){ 
    sort(all(v)); v.erase(unique(all(v)),end(v));
}
 
template<class T> bool ckmin(T& a, const T& b) {
    return b < a ? a = b, 1 : 0; 
} 
template<class T> bool ckmax(T& a, const T& b) {
    return a < b ? a = b, 1 : 0; 
}
 
bool valid(int x, int y, int n, int m){
    return (0<=x && x<n && 0<=y && y<m);
}
 
int cdiv(int a, int b) { return a/b+((a^b)>0&&a%b); } //redondea p arriba
int fdiv(int a, int b) { return a/b-((a^b)<0&&a%b); } //redondea p abajo
 
void NACHO(string name = ""){
    ios_base::sync_with_stdio(0); cin.tie(0);
    if(sz(name)){
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

vi dp;
int L[MX], a[MX];

int main(){
	NACHO();
	// primero, vemos que siempre te conviene restarle a un prefijo.
	// Luego, sea L_i la LIS que termina en i, y R_i la LIS que comienza en i
	// si le reste al prefijo [1;i]. La respuesta es max(L_i+R_i-1)
	// Calcular L_i es trivial.
	// Para calcular R_i, voy de atrás para adelante.
	// Si x = 5
	// 10 8 9 10 2
	// 5 8 9 10 2
	// para poder correr el algoritmo de LIS, en vez de meter a[i] meto -a[i].
	// -2 
	// -10
	// -10 -9 -8
	int n, d; cin >> n >> d;
	F0R(i, n){
		int x; cin >> x;
		a[i] = x;
		auto ind = lower_bound(all(dp), x)-dp.begin();
		if(ind == sz(dp)) dp.pb(x);
		else dp[ind] = x;
		L[i] = ind+1;
	}
	int ret = sz(dp);
	dp.clear();
	R0F(i, n){
		int R = lower_bound(all(dp), -a[i]+d)-dp.begin();
		ckmax(ret, L[i]+R);
		int ind = lower_bound(all(dp), -a[i])-dp.begin();
		if(ind == sz(dp)) dp.pb(-a[i]);
		else dp[ind] = -a[i];
	}
	cout << ret << "\n";
}

Compilation message

glo.cpp: In function 'void NACHO(std::string)':
glo.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         freopen((name+".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         freopen((name+".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 2 ms 324 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 3780 KB Output is correct
2 Correct 68 ms 3800 KB Output is correct
3 Correct 60 ms 3788 KB Output is correct
4 Correct 60 ms 3684 KB Output is correct
5 Correct 36 ms 3552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 1100 KB Output is correct
2 Correct 14 ms 1116 KB Output is correct
3 Correct 15 ms 1108 KB Output is correct
4 Correct 9 ms 1136 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 9 ms 1132 KB Output is correct
7 Correct 12 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 2112 KB Output is correct
2 Correct 27 ms 1996 KB Output is correct
3 Correct 52 ms 3720 KB Output is correct
4 Correct 37 ms 3464 KB Output is correct
5 Correct 19 ms 2000 KB Output is correct
6 Correct 30 ms 3468 KB Output is correct
7 Correct 39 ms 4056 KB Output is correct
8 Correct 22 ms 1988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 2 ms 324 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 57 ms 3780 KB Output is correct
28 Correct 68 ms 3800 KB Output is correct
29 Correct 60 ms 3788 KB Output is correct
30 Correct 60 ms 3684 KB Output is correct
31 Correct 36 ms 3552 KB Output is correct
32 Correct 14 ms 1100 KB Output is correct
33 Correct 14 ms 1116 KB Output is correct
34 Correct 15 ms 1108 KB Output is correct
35 Correct 9 ms 1136 KB Output is correct
36 Correct 1 ms 328 KB Output is correct
37 Correct 9 ms 1132 KB Output is correct
38 Correct 12 ms 1100 KB Output is correct
39 Correct 29 ms 2112 KB Output is correct
40 Correct 27 ms 1996 KB Output is correct
41 Correct 52 ms 3720 KB Output is correct
42 Correct 37 ms 3464 KB Output is correct
43 Correct 19 ms 2000 KB Output is correct
44 Correct 30 ms 3468 KB Output is correct
45 Correct 39 ms 4056 KB Output is correct
46 Correct 22 ms 1988 KB Output is correct
47 Correct 29 ms 1996 KB Output is correct
48 Correct 28 ms 2028 KB Output is correct
49 Correct 60 ms 3832 KB Output is correct
50 Correct 35 ms 3456 KB Output is correct
51 Correct 33 ms 2752 KB Output is correct
52 Correct 37 ms 3592 KB Output is correct
53 Correct 36 ms 3648 KB Output is correct
54 Correct 38 ms 4240 KB Output is correct
55 Correct 48 ms 3828 KB Output is correct