답안 #888240

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
888240 2023-12-16T15:36:37 Z pcc Money (IZhO17_money) C++14
0 / 100
8 ms 31368 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
#define tiii tuple<int,int,int>


const int mxn = 1e6+10;

struct node{
	int l,r,cover;
	node(){l = r = cover = 0;}
	node(int s,int e,int vv){
		l = s,r = e,cover = vv;
	}
};


vector<node> v;
int arr[mxn];
int n;
int bit[mxn];
int dp[mxn];
vector<pii> op[mxn];

void modify(int p,int val){
	for(;p<mxn;p+=p&-p)bit[p] += val;
	return;
}
int getval(int p){
	int re = 0;
	for(;p>0;p-= p&-p)re += bit[p];
	return re;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i = 1;i<=n;i++){
		cin>>arr[i];
	}
	for(int i = 2;i<=n;i++){
		if(arr[i]>arr[i-1])v.push_back(node(arr[i-1],arr[i],0));
	}
	sort(v.begin(),v.end(),[](node& a,node& b){return a.r == b.r?a.l<b.l:a.r<b.r;});
	for(int i = 0;i<v.size();i++){
		v[i].cover = i-getval(v[i].l-1);
		modify(v[i].l,1);
	}
	for(auto &i:v)op[i.r].push_back({i.l,i.cover});
	//for(auto &i:v)cout<<i.l<<' '<<i.r<<":"<<i.cover<<endl;
	for(int i = 1;i<=n;i++){
		dp[i] = max(dp[i],dp[i-1]);
		for(auto &j:op[i]){
			dp[i] = max(dp[i],dp[j.fs-1]+j.sc+1);
		}
	}
	cout<<n-dp[n];
}

Compilation message

money.cpp: In function 'int main()':
money.cpp:51:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |  for(int i = 0;i<v.size();i++){
      |                ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 31320 KB Output is correct
2 Correct 6 ms 31324 KB Output is correct
3 Correct 6 ms 31368 KB Output is correct
4 Correct 7 ms 29276 KB Output is correct
5 Incorrect 6 ms 31324 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 31320 KB Output is correct
2 Correct 6 ms 31324 KB Output is correct
3 Correct 6 ms 31368 KB Output is correct
4 Correct 7 ms 29276 KB Output is correct
5 Incorrect 6 ms 31324 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 31320 KB Output is correct
2 Correct 6 ms 31324 KB Output is correct
3 Correct 6 ms 31368 KB Output is correct
4 Correct 7 ms 29276 KB Output is correct
5 Incorrect 6 ms 31324 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 31320 KB Output is correct
2 Correct 6 ms 31324 KB Output is correct
3 Correct 6 ms 31368 KB Output is correct
4 Correct 7 ms 29276 KB Output is correct
5 Incorrect 6 ms 31324 KB Output isn't correct
6 Halted 0 ms 0 KB -