제출 #616232

#제출 시각아이디문제언어결과실행 시간메모리
616232jairRSDetecting Molecules (IOI16_molecules)C++17
9 / 100
0 ms212 KiB
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using pii = pair<long long, long long>;
#ifndef LOCALDEBUG
#define LOCALDEBUG false
#endif

vi find_subset(int l, int u, vi w) {
    vector<pii> molecules;
    for (int i = 0; i < w.size(); i++)
        molecules.push_back({w[i], i});
    molecules.push_back({1e18, -1});
    sort(molecules.begin(), molecules.end());

    long long curSum = 0;
    for (int i = 0; i < molecules.size(); i++)
    {
        pii cur = molecules[i];
        curSum += cur.first;

        if(curSum > u){
            //find w_p
            int p = -1;
            for (int j = 0; j <= i; j++)
            {
                long long newSum = curSum - molecules[j].first;
                if(l <= newSum && newSum <= u){
                    p = j;
                    break;
                }
            }
            if(p == -1)
                continue;
            
            vi ans;
            for (int k = 0; k <= i; k++)
            {
                if(k == p)
                    continue;
                ans.push_back(molecules[k].second);
            }
            return ans;
        }
    }

    return vi();
}

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

molecules.cpp: In function 'vi find_subset(int, int, vi)':
molecules.cpp:12:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for (int i = 0; i < w.size(); i++)
      |                     ~~^~~~~~~~~~
molecules.cpp:18:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for (int i = 0; i < molecules.size(); i++)
      |                     ~~^~~~~~~~~~~~~~~~~~
#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...