답안 #1105012

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1105012 2024-10-25T07:40:31 Z m5588ohammed 학생 (COCI14_studentsko) C++17
10 / 100
446 ms 1096 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
int n,k;
int arr[5002],ARR[5002],taken[5002],mn;
vector <array<int,2>> v;
vector <int> curr;
map <int,int> indx;
bool check(){
    for(int i=0;i<curr.size()-1;i++) if(arr[curr[i]]>arr[curr[i+1]]) return 0;
    return 1;
}
void build2(int mid,bool b){
    if(b==0) for(int i=v.size()-1;i>=v.size()-mid;i--) taken[v[i][1]]=0;
    else for(int i=v.size()-1;i>=v.size()-mid;i--) taken[v[i][1]]=1;
}
void build1(){
    cin>>n>>k;
    mn=n;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
        ARR[i]=arr[i];
        indx[arr[i]]=i;
        taken[i]=1;
    }
    sort(ARR+1,ARR+n+1);
    for(int i=1;i<=n;i++){
        v.push_back({(int)ceil((double)i/k),indx[ARR[i]]*-1});
        arr[indx[ARR[i]]]=(int)ceil((double)i/k);
    }
    sort(v.begin(),v.end());
    for(int i=0;i<v.size();i++) v[i][1]*=-1;
    return;
}
signed main()
{

    build1();
    for(int i=0;i<=n;i++){
        int l=0,r=n-i,ans=1e9;
        while(l<=r){
            curr.clear();
            int mid=(l+r)/2;
            build2(mid,0);
            for(int j=1;j<=n;j++) if(taken[j]==1) curr.push_back(j);
            bool flag=check();
            build2(mid,1);
            if(flag==1){
                ans=mid;
                r=mid-1;
            }
            else l=mid+1;
        }
        mn=min(mn,i+ans);
        taken[v[i][1]]=0;
    }
    cout<<mn<<endl;
    return 0;
}

Compilation message

studentsko.cpp: In function 'bool check()':
studentsko.cpp:11:18: 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]
   11 |     for(int i=0;i<curr.size()-1;i++) if(arr[curr[i]]>arr[curr[i+1]]) return 0;
      |                 ~^~~~~~~~~~~~~~
studentsko.cpp: In function 'void build2(long long int, bool)':
studentsko.cpp:15:36: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
   15 |     if(b==0) for(int i=v.size()-1;i>=v.size()-mid;i--) taken[v[i][1]]=0;
      |                                   ~^~~~~~~~~~~~~~
studentsko.cpp:16:32: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
   16 |     else for(int i=v.size()-1;i>=v.size()-mid;i--) taken[v[i][1]]=1;
      |                               ~^~~~~~~~~~~~~~
studentsko.cpp: In function 'void build1()':
studentsko.cpp:33:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for(int i=0;i<v.size();i++) v[i][1]*=-1;
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 403 ms 848 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 412 ms 1064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 315 ms 848 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 369 ms 1096 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 416 ms 1068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 446 ms 848 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 392 ms 848 KB Output isn't correct
2 Halted 0 ms 0 KB -