Submission #205366

# Submission time Handle Problem Language Result Execution time Memory
205366 2020-02-28T17:23:30 Z oko Detecting Molecules (IOI16_molecules) C++14
0 / 100
5 ms 376 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();
    int f=0;
    for(int i=1;i<v.size();i++)
    {
        lf=i;
        if(ck(i))
        {
            f=1;
            break;
        }
    }
    if(f==0)
    {
        vector<int>ans;
        return ans;
    }
    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;
        ms.insert(z);
        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:37:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1;i<v.size();i++)
                 ~^~~~~~~~~
molecules.cpp:58:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=lf;i<v.size();i++)rm.insert(v[i]);
                  ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB OK (n = 1, answer = NO)
2 Correct 5 ms 376 KB OK (n = 1, answer = NO)
3 Incorrect 4 ms 256 KB Contestant can not find answer, jury can
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB OK (n = 12, answer = YES)
2 Correct 5 ms 256 KB OK (n = 12, answer = YES)
3 Correct 5 ms 256 KB OK (n = 12, answer = NO)
4 Correct 5 ms 376 KB OK (n = 12, answer = NO)
5 Correct 5 ms 256 KB OK (n = 12, answer = YES)
6 Correct 4 ms 256 KB OK (n = 12, answer = YES)
7 Correct 5 ms 376 KB OK (n = 12, answer = YES)
8 Correct 5 ms 256 KB OK (n = 12, answer = YES)
9 Incorrect 5 ms 256 KB Contestant can not find answer, jury can
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB OK (n = 1, answer = NO)
2 Correct 5 ms 376 KB OK (n = 1, answer = NO)
3 Incorrect 4 ms 256 KB Contestant can not find answer, jury can
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB OK (n = 1, answer = NO)
2 Correct 5 ms 376 KB OK (n = 1, answer = NO)
3 Incorrect 4 ms 256 KB Contestant can not find answer, jury can
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB OK (n = 1, answer = NO)
2 Correct 5 ms 376 KB OK (n = 1, answer = NO)
3 Incorrect 4 ms 256 KB Contestant can not find answer, jury can
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB OK (n = 1, answer = NO)
2 Correct 5 ms 376 KB OK (n = 1, answer = NO)
3 Incorrect 4 ms 256 KB Contestant can not find answer, jury can
4 Halted 0 ms 0 KB -