Submission #962703

# Submission time Handle Problem Language Result Execution time Memory
962703 2024-04-14T07:19:03 Z hirayuu_oj Detecting Molecules (IOI16_molecules) C++17
0 / 100
1 ms 348 KB
#include "molecules.h"
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) x.begin(),x.end()
using ll=long long;
void out(int x){
    cerr<<x;
}
void out(ll x){
    cerr<<x;
}
template<typename F,typename S>
void out(pair<F,S> x){
    cerr<<"(";
    out(x.first);
    cerr<<", ";
    out(x.second);
    cerr<<")";
}
template<typename S>
void out(S x){
    cerr<<"[";
    for(auto i:x){
        out(i);
        cerr<<", ";
    }
    cerr<<"]";
}
template<typename H>
void DBG(H x){
    cerr<<"DBG:";
    out(x);
    cerr<<"\n";
}

std::vector<int> find_subset(int l, int u, std::vector<int> w) {
    int n=w.size();
    vector<ll> cum(w.size()+1,0);
    vector<pair<ll,ll>> wi(w.size());
    rep(i,w.size()){
        wi[i]={w[i],i};
    }
    sort(all(wi));
    rep(i,n){
        cum[i+1]=cum[i]+wi[i].first;
    }
    rep(i,n+1){
        if(cum[i]>u)continue;
        if(cum[n]-cum[n-i]<l)continue;
        rep(j,i+1){
            if(l<=cum[j]+cum[n]-cum[n-(i-j)]&&cum[j]+cum[n]-cum[n-(i-j)]<=u){
                vector<int> ans(0);
                rep(k,j){
                    ans.push_back(wi[k].second+1);
                }
                rep(k,i-j){
                    ans.push_back(wi[n-k-1].second+1);
                }
                ll wei=0;
                for(int i:ans){
                    wei+=w[i-1];
                }
                assert(l<=wei&&wei<u);
                return ans;
            }
        }
    }
    return std::vector<int>(0);
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:4:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep(i,n) for(int i=0; i<n; i++)
......
   41 |     rep(i,w.size()){
      |         ~~~~~~~~~~              
molecules.cpp:41:5: note: in expansion of macro 'rep'
   41 |     rep(i,w.size()){
      |     ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB OK (n = 1, answer = NO)
2 Correct 0 ms 344 KB OK (n = 1, answer = NO)
3 Runtime error 1 ms 344 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB OK (n = 1, answer = NO)
2 Correct 0 ms 344 KB OK (n = 1, answer = NO)
3 Runtime error 1 ms 344 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB OK (n = 1, answer = NO)
2 Correct 0 ms 344 KB OK (n = 1, answer = NO)
3 Runtime error 1 ms 344 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB OK (n = 1, answer = NO)
2 Correct 0 ms 344 KB OK (n = 1, answer = NO)
3 Runtime error 1 ms 344 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB OK (n = 1, answer = NO)
2 Correct 0 ms 344 KB OK (n = 1, answer = NO)
3 Runtime error 1 ms 344 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -