# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
691731 |
2023-01-31T13:25:38 Z |
tolbi |
Money (IZhO17_money) |
C++17 |
|
1 ms |
212 KB |
#pragma optimize("Bismillahirrahmanirrahim")
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█■█
//█─█─█▄─█▄─█─█─█─█
//Allahuekber
//ahmet23 orz...
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//YavuzSultanSelimHan
//AbdulhamidHan
#define author tolbi
#include <bits/stdc++.h>
#ifdef LOCAL
#include "23.h"
#endif
#define int long long
#define endl '\n'
#define vint(x) vector<int> x
#define deci(x) int x;cin>>x;
#define decstr(x) string x;cin>>x;
#define cinarr(x) for (auto &it : x) cin>>it;
#define coutarr(x) for (auto &it : x) cout<<it<<" ";cout<<endl;
#define sortarr(x) sort(x.begin(),x.end())
#define sortrarr(x) sort(x.rbegin(),x.rend())
#define det(x) cout<<"NO\0YES"+x*3<<endl;
#define INF LONG_LONG_MAX
#define rev(x) reverse(x.begin(),x.end());
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define tol(bi) (1LL<<((int)(bi)))
const int MOD = 1e9+7;
using namespace std;
mt19937 ayahya(chrono::high_resolution_clock().now().time_since_epoch().count());
vector<int> compress(vector<int> arr){
vector<int> barr = arr;
map<int,int> mp;
sortarr(barr);
int ind = 1;
for (int i = 0; i < arr.size(); i++){
if (mp[barr[i]]) continue;
mp[barr[i]]=ind++;
}
for (int i = 0; i < arr.size(); ++i)
{
arr[i]=mp[arr[i]];
}
return arr;
}
int32_t main(){
ios;
int t=1;
int tno = 0;
if (!t) cin>>t;
while (t-(tno++)){
deci(n);
vint(arr(n));
cinarr(arr);
vector<pair<int,int>> segm;
arr=compress(arr);
n=arr.size();
for (int i = 1; i < n; i++){
if (arr[i]>=arr[i-1]){
segm.push_back({arr[i-1]-1,arr[i]-1});
}
}
vector<vector<vector<int>>> dp(n,vector<vector<int>>(n,vector<int>(segm.size(),-1)));
auto f = [&](int l, int r, int ind, auto rec)->int{
if (l>r) return 0ll;
if (ind>=segm.size()) return 0ll;
if (dp[l][r][ind]!=-1) return dp[l][r][ind];
if (segm[ind].first>r || segm[ind].second>r) return dp[l][r][ind]=rec(l,r,ind+1,rec);
if (segm[ind].first<l || segm[ind].second<l) return dp[l][r][ind]=rec(l,r,ind+1,rec);
return dp[l][r][ind]=max(rec(l,r,ind+1,rec),rec(l,segm[ind].first,ind+1,rec)+rec(segm[ind].second,r,ind+1,rec)+rec(segm[ind].first,segm[ind].second,ind+1,rec)+1);
};
cout<<n-f(0,n-1,0,f)<<endl;
}
}
Compilation message
money.cpp:1: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
1 | #pragma optimize("Bismillahirrahmanirrahim")
|
money.cpp: In function 'std::vector<long long int> compress(std::vector<long long int>)':
money.cpp:38:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for (int i = 0; i < arr.size(); i++){
| ~~^~~~~~~~~~~~
money.cpp:42:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int i = 0; i < arr.size(); ++i)
| ~~^~~~~~~~~~~~
money.cpp: In instantiation of 'main()::<lambda(long long int, long long int, long long int, auto:23)> [with auto:23 = main()::<lambda(long long int, long long int, long long int, auto:23)>]':
money.cpp:74:22: required from here
money.cpp:68:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | if (ind>=segm.size()) return 0ll;
| ~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |