답안 #1116730

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1116730 2024-11-22T09:06:08 Z SalihSahin Detecting Molecules (IOI16_molecules) C++14
0 / 100
1 ms 336 KB
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
#include "molecules.h"

vector<int> find_subset(int l, int u, vector<int> w) {
    int n = w.size();
    vector<pair<int, int> > a(n);
    for(int i = 0; i < n; i++){
        a[i] = {w[i], i};
    }
    sort(a.begin(), a.end());

    vector<int> pre(n+1);
    for(int i = 0; i < n; i++){
        pre[i+1] = pre[i] + a[i].first;
    }

    vector<int> ans;
    int r = 0;

    int st = -1, sz = -1, lst = -1;

    for(int i = 0; i < n; i++){
        while(r < n && a[r].first - a[i].first <= u - l) r++;
        bool ok = 0;
        int x = 0;

        int lp = 1, rp = r - i;
        while(lp < rp){
            int mid = (lp + rp)/2;

            if(pre[i + mid] - pre[i] >= u) rp = mid;
            else lp = mid + 1;
        }
        if(lp > 1 && pre[i + lp] - pre[i] > u) lp--;
        if(pre[i + lp] - pre[i] > u) continue;

        int cntlmax = lp; // cntlmax ya da daha az kisi olacak

        lp = 1, rp = r - i;
        while(lp < rp){
            int mid = (lp + rp)/2;

            if(pre[r] - pre[r - mid] < l) lp = mid + 1;
            else rp = mid;
        }

        if(pre[r] - pre[r - lp] < l) continue;
        int cntrmin = lp;

        if(cntrmin <= cntlmax){
            x = cntrmin;
            ok = 1;
        }

        if(ok){
            st = i;
            sz = x;
            lst = r-1;
            break;
        }
    }

    if(st == -1) return ans;
    else{
        //cout<<st<<" den baslayan "<<sz<<" sizelık array dondurcez"<<endl;
        // [st, lst] aralıgından sz sizelık secicez
        int sum = 0, rem = sz;
        for(int i = 0; i < sz; i++){
            sum += a[i + st].first;
        }
        for(int i = lst; i >= st; i--){
            int now = a[i].first;
            int added = a[st + rem - 1].first;

            if(sum + (now - added) <= u){
                ans.pb(a[i].second);
                rem--;
                sum += (now - added);
            }
        }
        
        return ans;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB OK (n = 1, answer = NO)
2 Correct 1 ms 336 KB OK (n = 1, answer = NO)
3 Correct 1 ms 336 KB OK (n = 1, answer = YES)
4 Correct 1 ms 336 KB OK (n = 2, answer = YES)
5 Correct 1 ms 336 KB OK (n = 2, answer = YES)
6 Incorrect 1 ms 336 KB sum of weights should be in [5..5] but it is 15
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB sum of weights should be in [302..304] but it is 504
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB OK (n = 1, answer = NO)
2 Correct 1 ms 336 KB OK (n = 1, answer = NO)
3 Correct 1 ms 336 KB OK (n = 1, answer = YES)
4 Correct 1 ms 336 KB OK (n = 2, answer = YES)
5 Correct 1 ms 336 KB OK (n = 2, answer = YES)
6 Incorrect 1 ms 336 KB sum of weights should be in [5..5] but it is 15
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB OK (n = 1, answer = NO)
2 Correct 1 ms 336 KB OK (n = 1, answer = NO)
3 Correct 1 ms 336 KB OK (n = 1, answer = YES)
4 Correct 1 ms 336 KB OK (n = 2, answer = YES)
5 Correct 1 ms 336 KB OK (n = 2, answer = YES)
6 Incorrect 1 ms 336 KB sum of weights should be in [5..5] but it is 15
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB OK (n = 1, answer = NO)
2 Correct 1 ms 336 KB OK (n = 1, answer = NO)
3 Correct 1 ms 336 KB OK (n = 1, answer = YES)
4 Correct 1 ms 336 KB OK (n = 2, answer = YES)
5 Correct 1 ms 336 KB OK (n = 2, answer = YES)
6 Incorrect 1 ms 336 KB sum of weights should be in [5..5] but it is 15
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB OK (n = 1, answer = NO)
2 Correct 1 ms 336 KB OK (n = 1, answer = NO)
3 Correct 1 ms 336 KB OK (n = 1, answer = YES)
4 Correct 1 ms 336 KB OK (n = 2, answer = YES)
5 Correct 1 ms 336 KB OK (n = 2, answer = YES)
6 Incorrect 1 ms 336 KB sum of weights should be in [5..5] but it is 15
7 Halted 0 ms 0 KB -