제출 #574072

#제출 시각아이디문제언어결과실행 시간메모리
574072EliasDetecting Molecules (IOI16_molecules)C++17
46 / 100
213 ms65536 KiB
#include <bits/stdc++.h>

#ifndef _DEBUG
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include "molecules.h"
#endif

using namespace std;

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

    vector<int> a;

    for (int i = 0; i < w.size(); i++)
    {
        if (w[i] > u)
            continue;
        if (w[i] >= l)
            return {i};
        a.push_back(w[i]);
    }

    int n = a.size();

    vector<vector<bool>> dp(n + 1, vector<bool>(u + 1));

    for (int i = 0; i <= n; i++)
        dp[i][0] = 1;

    int i, j;

    for (i = 1; i <= n; i++)
        for (j = 1; j <= u; j++)
        {
            dp[i][j] = dp[i - 1][j];

            if (a[i - 1] <= j)
                dp[i][j] = dp[i][j] | dp[i - 1][j - a[i - 1]];

            if (j >= l && j <= u && dp[i][j])
                goto out;
        }

    return {};

out:

    vector<int> o;

    while (i)
    {
        if (!dp[i - 1][j])
        {
            o.push_back(i - 1);
            j -= a[i - 1];
        }
        i--;
    }

    return o;
}

#ifdef _DEBUG

signed main()
{
    int n, l, u;
    cin >> n >> l >> u;

    vector<int> a(n);

    for (int &x : a)
        cin >> x;

    for (int x : find_subset(l, u, a))
        cout << x << " ";
}

#endif

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

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