Submission #1097909

# Submission time Handle Problem Language Result Execution time Memory
1097909 2024-10-08T15:23:44 Z dzhoz0 Detecting Molecules (IOI16_molecules) C++17
0 / 100
0 ms 348 KB
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

vector<int> sub1(int l, int u, vector<int> w) {
    int n = w.size();
    int cur = 0;
    vector<int> res;
    for(int i = 0; i < n; i++) {
        cur += w[i];
        res.push_back(i);
        if(cur >= l && cur <= u) {
            return res;
        }
    }
    return vector<int>(0);
}




vector<int> sub123(int l, int u, vector<int> w) {
    int n = w.size();
    vector<pair<bool, int>> dp(u + 5, {false, -1});
    dp[0] = {true, -1};
    for(int i = 0; i < n; i++) {
        for(int x = u; x >= 0; x--) {
            if(dp[x].first == true) {
                if(x + w[i] <= u) {
                    dp[x + w[i]] = {true, i};
                }
            }
        }
    }

    // for(int x = 0; x <= u; x++) {
    //     cout << x << ' ' << dp[x].first << '\n';
    // }

    for(int val = l; val <= u; val++) {
        if(dp[val].first == true) {
            int x = val;
            // cout << x << ' ' << dp[x].second << '\n';
            vector<int> res;
            int id = dp[x].second;
            
            while(id != -1) {
                res.push_back(id);
                // cout << id << '\n';
                x -= w[id];
                id = dp[x].second;
            }
            // cout << res.size() << '\n';
            return res;
        }
    }
    return vector<int>(0);
}


vector<int> find_subset(int l, int u, vector<int> w) {
    int n = w.size();
    // sort(w.begin(), w.end());
    int mx = *max_element(w.begin(), w.end()), mi = *min_element(w.begin(), w.end());
    if(u <= 1000) return sub123(l, u, w);
    return vector<int>(0);
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:64:9: warning: unused variable 'n' [-Wunused-variable]
   64 |     int n = w.size();
      |         ^
molecules.cpp:66:9: warning: unused variable 'mx' [-Wunused-variable]
   66 |     int mx = *max_element(w.begin(), w.end()), mi = *min_element(w.begin(), w.end());
      |         ^~
molecules.cpp:66:48: warning: unused variable 'mi' [-Wunused-variable]
   66 |     int mx = *max_element(w.begin(), w.end()), mi = *min_element(w.begin(), w.end());
      |                                                ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB OK (n = 1, answer = NO)
2 Correct 0 ms 348 KB OK (n = 1, answer = NO)
3 Correct 0 ms 348 KB OK (n = 1, answer = YES)
4 Incorrect 0 ms 348 KB item #1 is taken twice
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB item #11 is taken twice
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB OK (n = 1, answer = NO)
2 Correct 0 ms 348 KB OK (n = 1, answer = NO)
3 Correct 0 ms 348 KB OK (n = 1, answer = YES)
4 Incorrect 0 ms 348 KB item #1 is taken twice
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB OK (n = 1, answer = NO)
2 Correct 0 ms 348 KB OK (n = 1, answer = NO)
3 Correct 0 ms 348 KB OK (n = 1, answer = YES)
4 Incorrect 0 ms 348 KB item #1 is taken twice
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB OK (n = 1, answer = NO)
2 Correct 0 ms 348 KB OK (n = 1, answer = NO)
3 Correct 0 ms 348 KB OK (n = 1, answer = YES)
4 Incorrect 0 ms 348 KB item #1 is taken twice
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB OK (n = 1, answer = NO)
2 Correct 0 ms 348 KB OK (n = 1, answer = NO)
3 Correct 0 ms 348 KB OK (n = 1, answer = YES)
4 Incorrect 0 ms 348 KB item #1 is taken twice
5 Halted 0 ms 0 KB -