답안 #727444

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
727444 2023-04-20T16:59:20 Z josiftepe Detecting Molecules (IOI16_molecules) C++14
0 / 100
54 ms 65536 KB
#include <bits/stdc++.h>
#include "molecules.h"
using namespace std;


int dp[10005][1005];
pair<int, int> backtrac[10005][1005];
vector<int> v;
int rec(int at, int weight) {
    if(weight == 0) {
        backtrac[at][weight] = make_pair(-1, -1);
        return 1;
    }
    if(at == -1) {
        return 0;
    }
    if(dp[at][weight] != -1) {
        return dp[at][weight];
    }
    int result = 0;
    int r1 = 0, r2 = 0;
    if(weight - v[at] >= 0) {
        r1 = rec(at - 1, weight - v[at]);
    }
    r2 =  rec(at - 1, weight);
    
    if(r1 > r2) {
        backtrac[at][weight] = make_pair(at - 1, weight - v[at]);
    }
    else {
        backtrac[at][weight] = make_pair(at - 1, weight);
    }
    return dp[at][weight] = max(r1, r2);
}
vector<int> find_subset(int l, int u, vector<int> w) {
    v  =w;
    int n = w.size();
    int W = -1;
    memset(dp, -1, sizeof dp);
    for(int i = l; i <= u; i++) {
        if(rec(n - 1, i) == 1) {
            W = i;
            break;
        }
    }
    if(W == -1) {
        return {};
    }
    pair<int, int> at;
    vector<pair<int, int> > res;
    int tmp = 0;
    for(at = make_pair(n - 1, W); at != make_pair(-1, -1); at = backtrac[backtrac[at.first][at.second].first][backtrac[at.first][at.second].second]) {
        res.push_back(make_pair(at.first, at.second));
    }
    vector<int> R;
    for(int i = 0; i< (int) res.size(); i++) {
        if(i + 1 < (int) res.size() and res[i].second != res[i + 1].second) {
            R.push_back(res[i].first + 1);
//            cout << res[i].first + 1 << endl;
        }
    }
    return R;
}

Compilation message

molecules.cpp: In function 'int rec(int, int)':
molecules.cpp:20:9: warning: unused variable 'result' [-Wunused-variable]
   20 |     int result = 0;
      |         ^~~~~~
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:51:9: warning: unused variable 'tmp' [-Wunused-variable]
   51 |     int tmp = 0;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 39636 KB OK (n = 1, answer = NO)
2 Correct 16 ms 39636 KB OK (n = 1, answer = NO)
3 Incorrect 17 ms 39564 KB Contestant can not find answer, jury can
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 54 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 39636 KB OK (n = 1, answer = NO)
2 Correct 16 ms 39636 KB OK (n = 1, answer = NO)
3 Incorrect 17 ms 39564 KB Contestant can not find answer, jury can
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 39636 KB OK (n = 1, answer = NO)
2 Correct 16 ms 39636 KB OK (n = 1, answer = NO)
3 Incorrect 17 ms 39564 KB Contestant can not find answer, jury can
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 39636 KB OK (n = 1, answer = NO)
2 Correct 16 ms 39636 KB OK (n = 1, answer = NO)
3 Incorrect 17 ms 39564 KB Contestant can not find answer, jury can
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 39636 KB OK (n = 1, answer = NO)
2 Correct 16 ms 39636 KB OK (n = 1, answer = NO)
3 Incorrect 17 ms 39564 KB Contestant can not find answer, jury can
4 Halted 0 ms 0 KB -