This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
using namespace std;
#define ll long long
bool isvalid(int i, int j, int n, int m){
if(i<0||i>m-1||j<0||j>n-1){
return false;}
else{
return true;}
}
void solve(){
int n, m;
cin>>n>>m;
vector<pair<int,int>>a(m);
for(int i = 0; i<m; i++){
cin >> a[i].first;}
for(int i = 0; i<m; i++){
cin >> a[i].second;}
sort(a.begin(),a.end());
int v[m] = {0};
int dp[m][m] = {};
for(int i = 0; i<m; i++){
dp[0][i] = 1;}
bool flag= true;
for(int i = 1; i<m; i++){
for(int j = 0; j<m; j++){
if(isvalid(i-1, j-1, m, m)){
if(dp[i-1][j-1]==1){
dp[i][j]=1;
continue;}}
if(isvalid(i-1, j, m, m)){
if(dp[i-1][j]==0){
continue;}}
flag = true;
for(int k = i; k>=0; k--){
if(!flag){
break;}
for(int r = j; r>=0; r--){
if(v[r]==0){
v[r]=k;
break;}
else if(abs(a[v[r]].first-a[k].first)>=abs(a[v[r]].second-a[k].second)){
v[r]=k;
break;}
else if(r==0){
flag = false;
break;}}}
fill(v, v+m, 0);
if(flag){
dp[i][j]=1;}
}
}
for(int j = 0; j<m; j++){
if(dp[m-1][j]==1){
cout<<j+1;
break;}}
}
int main(){
int t;
//cin>>t;
t = 1;
for(int i = 0; i<t; i++){
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |