Submission #551160

# Submission time Handle Problem Language Result Execution time Memory
551160 2022-04-20T00:19:32 Z DanerZein Let's Win the Election (JOI22_ho_t3) C++14
11 / 100
567 ms 2380 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<double,double> dd;
const int MAX=1e9;
bool orden(dd a,dd b){
  if(a.second==b.second) return a.first<b.first;
  return a.second<b.second;
}
int n;
vector<dd> st;
double ka;
double dp[510][510];
double knap(int id,int k){
  if(dp[id][k]!=-1) return dp[id][k];
  if(id==n) {
    if(k!=ka) return MAX;
    return 0;
  }
  double ans=knap(id+1,k)+st[id].first/(ka+1);
  if(k!=ka){
    ans=min(ans,knap(id+1,k+1)+st[id].second/(double)(k+1));
  }
  return dp[id][k]=ans;
}
int main(){
  int k; scanf("%d%d",&n,&k);
  for(int i=0;i<n;i++){
     int a,b; scanf("%d%d",&a,&b);
    if(b==-1) b=MAX;
    st.push_back(dd(a,b));
  }
  sort(st.begin(),st.end(),orden);
  double res=MAX;
  for(int i=0;i<=k;i++){
    ka=i;
    for(int j=0;j<=n;j++) for(int l=0;l<=n;l++) dp[j][l]=-1;
    double rp=knap(0,0);
    //cout<<i<<": "<<rp<<endl;
    res=min(res,rp);
  }
  printf("%.15f\n",res);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:27:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |   int k; scanf("%d%d",&n,&k);
      |          ~~~~~^~~~~~~~~~~~~~
Main.cpp:29:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |      int a,b; scanf("%d%d",&a,&b);
      |               ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 546 ms 2332 KB Output is correct
2 Correct 545 ms 2260 KB Output is correct
3 Correct 539 ms 2332 KB Output is correct
4 Correct 567 ms 2336 KB Output is correct
5 Correct 537 ms 2332 KB Output is correct
6 Correct 535 ms 2380 KB Output is correct
7 Correct 538 ms 2348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -