Submission #628682

# Submission time Handle Problem Language Result Execution time Memory
628682 2022-08-13T15:22:00 Z a_aguilo Fancy Fence (CEOI20_fancyfence) C++14
0 / 100
2 ms 468 KB
#include<bits/stdc++.h>

using namespace std;

typedef vector<int> vi;

vi leftSpots, rightSpots;

struct contestant{
    int left, right, force;
    contestant(int l, int r, int f){
        left = l;
        right = r;
        force = f;
    }
};

vector<contestant*> people;

int n, k;
int sLeft, sRight;

bool possible(int pos){
    if(pos == 2*n) return (abs(sLeft-sRight)<= k);
    if(!leftSpots[people[pos]->left]){
        sLeft += people[pos]->force;
        leftSpots[people[pos]->left] = 1;
        if(possible(pos+1)) return true;
        sLeft -= people[pos]->force;
        leftSpots[people[pos]->left] = 0;
    }
    if(!rightSpots[people[pos]->right]){
        sRight += people[pos]->force;
        rightSpots[people[pos]->right] = 1;
        if(possible(pos+1)) return true;
        sRight -= people[pos]->force;
        rightSpots[people[pos]->right] = 0;
    }
    return false;
}

int main(){
    int l, r, s;
    cin >> n >> k;
    people = vector<contestant*> (2*n);
    for(int i = 0; i < 2*n; ++i){
        cin >> l >> r >> s; l--; r--;
        contestant* act = new contestant(l, r, s);
        people[i] = act;
    }
    sLeft = 0;
    sRight = 0;
    leftSpots = vi(n, 0); rightSpots = vi(n, 0);
    if(possible(0)) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -