제출 #1024170

#제출 시각아이디문제언어결과실행 시간메모리
1024170vaneaDetecting Molecules (IOI16_molecules)C++14
9 / 100
1 ms436 KiB
#include <bits/stdc++.h>
#include "molecules.h"
using namespace std;
using ll = long long;

vector<int> find_subset(int l, int u, vector<int> w) {
    deque<int> ans;
    vector<array<int, 2>> w1;
    int n = w.size();
    for(int i = 0; i < n; i++) {
        w1.push_back({w[i], i});
    }
    sort(w1.begin(), w1.end());
    int i = 0, j = 1;
    ans.push_back(w1[0][1]);
    ll curr = w1[0][0];
    bool fnd = false;
    while(i < n && j < n) {
        if(curr >= l && curr <= u) {
            fnd = true;
            break;
        }
        else if(curr < l) {
            curr += w1[j][0];
            ans.push_back(w1[j][1]);
            ++j;
        }
        else if(curr > u) {
            ans.pop_front();
            curr -= w1[i][0];
            ++i;
        }
    }
    if(fnd || curr >= l && curr <= u) {
        vector<int> res;
        while(!ans.empty()) {
            auto node = ans.front();
            ans.pop_front();
            res.push_back(node);
        }
        sort(res.begin(), res.end());
        return res;
    }
    return {};
}

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

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:34:25: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   34 |     if(fnd || curr >= l && curr <= u) {
      |               ~~~~~~~~~~^~~~~~~~~~~~
#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...