답안 #961019

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
961019 2024-04-11T11:55:30 Z ankit_singh_programs Job Scheduling (CEOI12_jobs) C++14
0 / 100
1000 ms 2548 KB


#include <iostream>

using namespace std;


#define ll long long 




ll k;

#define str string




void io(str s){
  str s1=s+".in";
  str s2=s+".out";
 
  freopen(s1.c_str(),"r",stdin);
  freopen(s2.c_str(),"w",stdout);
 
 
}


#define de(x) cout<<#x<<" ";cout<<x<<endl;



#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);





int day,del,n;


#include <bits/stdc++.h>




#define ve vector 





ve<pair<int,int>> ar;





#define f first

#define s second




bool chk(int k){

  int a;

  int c;

    
a=1;

c=0;


  for(auto nxt:ar){


    int v=nxt.f;

    while(a<v){

      ++a;

      c=0;

    }



    if(a>day) return 0;


  int dt=fabs(a-v);



  if(dt>del) return 0;









  ++c;

  if(c==k){
    c=0;

    ++a;




  }







  }


  return 1;




}

const int inf=1e9;



#define pb push_back

#define all(x) (x).begin(),(x).end()







  void sol(){

    cin>>day>>del>>n;


    for(int i=0;i<n;++i){

      int a;

      cin>>a;

      ar.pb({a,i+1});

    }






    sort(all(ar));





    int l=1;

    int r=n;


    int ans=inf;



    while(l<=r){
      int m=(l+r)/2;

      if(chk(m)){


        ans=m;




        r=m-1;

      }


      else{


        l=m+1;


      }


    }


    // case t+ fasth



      cout<<ans;



    cout<<endl;





int k=ans;








int a,c;
    
a=1;

c=0;  


bool don=0;


  for(auto nxt:ar){


    int v=nxt.f;

    while(a<v){


      cout<<"0\n";



      ++a;

      c=0;

    }





  int dt=fabs(a-v);
















  ++c;


  cout<<nxt.second<<" ";


  if(c==k){


    don=1;

    cout<<"0"<<endl;

    c=0;

    ++a;




  }








  }




  if(don); 

  else{

    cout<<0<<endl;

    ++a;



  }





  a=day-a;

++a;


  while(a--) cout<<0<<endl;















}



int main(){ 

  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);

  freopen("output.txt","w",stdout);

  freopen("error.txt","w",stderr);
  #endif

  

  // io("cbarn2");

  


  sol();








  return 0;
} 

Compilation message

jobs.cpp: In function 'void sol()':
jobs.cpp:273:7: warning: unused variable 'dt' [-Wunused-variable]
  273 |   int dt=fabs(a-v);
      |       ^~
jobs.cpp: In function 'void io(std::string)':
jobs.cpp:25:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |   freopen(s1.c_str(),"r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:26:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |   freopen(s2.c_str(),"w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp: In function 'int main()':
jobs.cpp:368:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  368 |   freopen("input.txt","r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:370:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  370 |   freopen("output.txt","w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:372:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  372 |   freopen("error.txt","w",stderr);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1056 ms 2192 KB Time limit exceeded
2 Execution timed out 1040 ms 2236 KB Time limit exceeded
3 Execution timed out 1063 ms 2180 KB Time limit exceeded
4 Execution timed out 1014 ms 1988 KB Time limit exceeded
5 Execution timed out 1071 ms 2424 KB Time limit exceeded
6 Execution timed out 1056 ms 2132 KB Time limit exceeded
7 Execution timed out 1026 ms 2080 KB Time limit exceeded
8 Execution timed out 1026 ms 2104 KB Time limit exceeded
9 Execution timed out 1048 ms 2212 KB Time limit exceeded
10 Execution timed out 1070 ms 2548 KB Time limit exceeded
11 Execution timed out 1024 ms 2260 KB Time limit exceeded
12 Execution timed out 1077 ms 2228 KB Time limit exceeded
13 Execution timed out 1029 ms 2108 KB Time limit exceeded
14 Execution timed out 1049 ms 2068 KB Time limit exceeded
15 Execution timed out 1053 ms 2224 KB Time limit exceeded
16 Execution timed out 1018 ms 2152 KB Time limit exceeded
17 Execution timed out 1057 ms 2144 KB Time limit exceeded
18 Execution timed out 1049 ms 2128 KB Time limit exceeded
19 Execution timed out 1025 ms 2148 KB Time limit exceeded
20 Execution timed out 1065 ms 2120 KB Time limit exceeded