Submission #628794

# Submission time Handle Problem Language Result Execution time Memory
628794 2022-08-13T17:11:15 Z Iwanttobreakfree Tug of War (BOI15_tug) C++17
18 / 100
3000 ms 262144 KB
#include <iostream>
#include <vector>
using namespace std;
bool bt(int i,vector<pair<int,int>> pos,int l,int r,int k,vector<int>& posl,vector<int>& posr,vector<int>& s){
    if(i==pos.size()&&abs(l-r)<=k)return true;
    else if(i==pos.size())return false;
    if(posl[pos[i].first]){
        posl[pos[i].first]=0;
        l+=s[i];
        if(bt(i+1,pos,l,r,k,posl,posr,s))return true;
        posl[pos[i].first]=1;
        l-=s[i];
    }
    if(posr[pos[i].second]){
        posr[pos[i].second]=0;
        r+=s[i];
        if(bt(i+1,pos,l,r,k,posl,posr,s))return true;
        posr[pos[i].second]=1;
        r-=s[i];
    }
    return false;
}
int main(){
    int n,k;
    cin>>n>>k;
    vector<pair<int,int>> pos(2*n);
    vector<int> posl(n,1),posr(n,1),s(2*n);
    for(int i=0;i<2*n;i++)cin>>pos[i].first>>pos[i].second>>s[i];
    for(int i=0;i<2*n;i++){
        pos[i].first--;pos[i].second--;
    }
    if(bt(0,pos,0,0,k,posl,posr,s))cout<<"YES\n";
    else cout<<"NO\n";
}

Compilation message

tug.cpp: In function 'bool bt(int, std::vector<std::pair<int, int> >, int, int, int, std::vector<int>&, std::vector<int>&, std::vector<int>&)':
tug.cpp:5:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 |     if(i==pos.size()&&abs(l-r)<=k)return true;
      |        ~^~~~~~~~~~~~
tug.cpp:6:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 |     else if(i==pos.size())return false;
      |             ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 292 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 304 KB Output is correct
15 Correct 1 ms 280 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 304 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 232 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 292 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 304 KB Output is correct
15 Correct 1 ms 280 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 304 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 232 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 173 ms 126588 KB Output is correct
27 Execution timed out 3081 ms 29560 KB Time limit exceeded
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 128 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 292 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 304 KB Output is correct
15 Correct 1 ms 280 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 304 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 232 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 173 ms 126588 KB Output is correct
27 Execution timed out 3081 ms 29560 KB Time limit exceeded
28 Halted 0 ms 0 KB -