제출 #288791

#제출 시각아이디문제언어결과실행 시간메모리
288791Ruba_KDetecting Molecules (IOI16_molecules)C++14
9 / 100
1 ms384 KiB
#include "molecules.h"

#include<bits/stdc++.h>

using namespace std ;

vector<int> find_subset(int l, int u, vector<int> w) {
    int n = w.size();
    deque<int>pos (n);

    iota(pos.begin() , pos.end() , 0);


    sort(pos.begin() , pos.end() , [w](int a , int b){
        return w[a] < w[b] ;

         });

    pos.push_back(0);
    sort(w.begin() , w.end());
    if(w[0] > u)return {};
    w.push_back((2 << 31) + 1);

    long long sum = 0 ;

    int idx = 0 ;

    deque<int> ret ;
    while(idx <= n && sum <= u){
        sum += w[idx];
        ret.push_back(pos[idx++]);
    }

    idx -- ;

    sum -= w[idx--];

    w.pop_back();
    ret.pop_back();


    int p1 = 0 , p2 = idx ;

    while(p2 < n && !(sum >= l && sum <= u)){
        ret.pop_front();
        sum -= w[p1++];
        sum += w[p2];
        ret.push_back(pos[p2++]);
    }

    vector<int>ret2 ;

    for(auto f : ret)
        ret2.push_back(f);

    if(sum >= l && sum <= u)
        return ret2 ;
    else return vector<int>();

}

컴파일 시 표준 에러 (stderr) 메시지

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:22:20: warning: result of '(2 << 31)' requires 34 bits to represent, but 'int' only has 32 bits [-Wshift-overflow=]
   22 |     w.push_back((2 << 31) + 1);
      |                  ~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...