제출 #108209

#제출 시각아이디문제언어결과실행 시간메모리
108209tictaccatDetecting Molecules (IOI16_molecules)C++14
69 / 100
66 ms8056 KiB
#include "molecules.h"

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

std::vector<int> find_subset(int l, int u, std::vector<int> w) {

    int n = w.size();

    vector<int> indices(n);
    iota(indices.begin(),indices.end(),0);
    sort(indices.begin(),indices.end(),[&w](int i, int j) {return w[i] < w[j];});
    sort(w.begin(),w.end());

    vector<ll> pre(n+1), suf(n+1);
    int preOut, sufIn;

    int k;

    for (k = 1; k <= n; k++) {
        pre[k] = pre[k-1] + w[k-1] - w[0];
        suf[k] = suf[k-1] + w[n-k] - w[0];
        if (pre[k] + k*w[0] <= u && suf[k] + k*w[0] >= l) break;
    }

    if (k <= n) {
        for (int i = 0; i <= k; i++) {
            ll val = pre[i] + suf[k-i] + k*w[0];
            if (val >= l && val <= u) {
                vector<int> res;
                for (int j = 0; j < i; j++) res.push_back(indices[j]);
                for (int j = n-1; j >= n-k+i; j--) res.push_back(indices[j]);
                return res;
            }
        }
    }
    

    return std::vector<int>();
}

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

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:17:9: warning: unused variable 'preOut' [-Wunused-variable]
     int preOut, sufIn;
         ^~~~~~
molecules.cpp:17:17: warning: unused variable 'sufIn' [-Wunused-variable]
     int preOut, sufIn;
                 ^~~~~
#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...