답안 #305898

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
305898 2020-09-24T04:35:52 Z talant117408 Detecting Molecules (IOI16_molecules) C++17
0 / 100
1 ms 256 KB
#include "molecules.h"

#include <bits/stdc++.h>

using namespace std;
/*
vector <int> find_subset(int l, int u, vector <int> w);
int main() {
    int n, l, u;
    assert(3 == scanf("%d %d %d", &n, &l, &u));
    std::vector<int> w(n);
    for (int i = 0; i < n; i++)
        assert(1 == scanf("%d", &w[i]));
    std::vector<int> result = find_subset(l, u, w);
    
    printf("%d\n", (int)result.size());
    for (int i = 0; i < (int)result.size(); i++)
        printf("%d%c", result[i], " \n"[i == (int)result.size() - 1]);
}
*/

vector <int> find_subset(int l, int r, vector <int> w){
    int n = w.size();
    vector <pair<int, int>> pref(n);
    for(int i = 0; i < n; i++){
        pref[i] = {w[i], i};
    }
    sort(pref.begin(), pref.end());
    sort(w.begin(), w.end());
    for(int i = 1; i < n; i++){
        pref[i].first += pref[i-1].first;
    }
    int pl = 0, pr = 0;
    
    while(pl <= pr){
        int sum = pref[pr].first-(pl ? pref[pl-1].first : 0);
        vector <int> inds;
        if(l <= sum && sum <= r){
            for(int i = pl; i <= pr; i++){
                inds.push_back(pref[i].second+1);
            }
            return inds;
        }
        else if(sum > r){
            if(pl == pr){
                return vector <int> (0);
            }
            while(pl < pr && sum > r){
                sum -= w[pl];
                pl++;
            }
        }
        else if(sum < l){
            if(pr+1 == n){
                return vector <int> (0);
            }
            while(pr+1 < n && sum < l){
                sum += w[++pr];
            }
        }
    }
    
    return vector <int> (0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB OK (n = 1, answer = NO)
2 Correct 0 ms 256 KB OK (n = 1, answer = NO)
3 Incorrect 1 ms 256 KB Integer 1 violates the range [0, 0]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB OK (n = 12, answer = YES)
2 Correct 1 ms 256 KB OK (n = 12, answer = YES)
3 Correct 1 ms 256 KB OK (n = 12, answer = NO)
4 Correct 1 ms 256 KB OK (n = 12, answer = NO)
5 Incorrect 1 ms 256 KB sum of weights should be in [290..300] but it is 301
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB OK (n = 1, answer = NO)
2 Correct 0 ms 256 KB OK (n = 1, answer = NO)
3 Incorrect 1 ms 256 KB Integer 1 violates the range [0, 0]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB OK (n = 1, answer = NO)
2 Correct 0 ms 256 KB OK (n = 1, answer = NO)
3 Incorrect 1 ms 256 KB Integer 1 violates the range [0, 0]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB OK (n = 1, answer = NO)
2 Correct 0 ms 256 KB OK (n = 1, answer = NO)
3 Incorrect 1 ms 256 KB Integer 1 violates the range [0, 0]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB OK (n = 1, answer = NO)
2 Correct 0 ms 256 KB OK (n = 1, answer = NO)
3 Incorrect 1 ms 256 KB Integer 1 violates the range [0, 0]
4 Halted 0 ms 0 KB -