답안 #205363

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
205363 2020-02-28T17:13:31 Z oko Detecting Molecules (IOI16_molecules) C++14
0 / 100
1000 ms 256 KB
#include <cstdio>
#include <vector>
#include <cassert>
#include<bits/stdc++.h>
#include "molecules.h"

using namespace std;
long long a,b,lf,rt,mid;
vector<pair<int,int> >v;
bool ck(int x)
{
    long long cnt=0,sum=0;
    for(int i=0;i<v.size();i++)
    {
        cnt++;
        sum+=v[i].first;
        if(cnt==x)break;
    }
    if(sum>b)return 0;
    cnt=0,sum=0;
    for(int i=v.size()-1;i>=0;i--)
    {
        cnt++;
        sum+=v[i].first;
        if(cnt==x)break;
    }
    if(sum<a)return 0;
    return 1;
}
vector<int> find_subset(int l, int u, std::vector<int> w)
{
    a=l,b=u;
    for(int i=0;i<w.size();i++)v.push_back({w[i],i});
    sort(v.begin(),v.end());
    lf=0,rt=v.size();
    while(lf<rt)
    {
        mid=(lf+rt)/2;
        if(ck(mid))lf=mid+1;
        else rt=mid;
    }
    lf--;
    multiset<pair<long long,int> >ms,rm;
    long long sum=0;
    for(int i=0;i<lf;i++)
    {
        sum+=v[i].first;
        ms.insert(v[i]);
    }
    for(int i=lf;i<v.size();i++)rm.insert(v[i]);
    while(sum<a)
    {
        pair<int,int>z=*ms.begin();
        sum-=z.first;
        ms.erase(ms.begin());
        z=*--rm.end();
        sum+=z.first;
        rm.erase(--rm.end());
    }
    vector<int>ans;
    multiset<pair<long long,int> >::iterator it;
    for(it=ms.begin();it!=ms.end();it++)
    {
        pair<int,int>z=*it;
        ans.push_back(z.second);
    }
    return ans;
}

Compilation message

molecules.cpp: In function 'bool ck(int)':
molecules.cpp:13:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v.size();i++)
                 ~^~~~~~~~~
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:33:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<w.size();i++)v.push_back({w[i],i});
                 ~^~~~~~~~~
molecules.cpp:50:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=lf;i<v.size();i++)rm.insert(v[i]);
                  ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1064 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 256 KB sum of weights should be in [302..304] but it is 200
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1064 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1064 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1064 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1064 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -