답안 #1021848

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1021848 2024-07-13T06:08:30 Z guagua0407 Tug of War (BOI15_tug) C++17
18 / 100
26 ms 860 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};

void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

int main() {_
    int n,k;
    cin>>n>>k;
    vector<int> l(2*n),r(2*n),S(2*n);
    int all=0;
    for(int i=0;i<2*n;i++){
        cin>>l[i]>>r[i]>>S[i];
        l[i]--;
        r[i]--;
        all+=S[i];
    }
    for(int i=0;i<(1<<(2*n));i++){
        if(__builtin_popcount(i)!=n) continue;
        vector<int> L(n),R(n);
        bool tf=true;
        int sum=0;
        for(int j=0;j<2*n;j++){
            if(i&(1<<j)){
                if(L[l[j]]) tf=false;
                L[l[j]]=1;
                sum+=S[j];
            }
            else{
                if(R[r[j]]) tf=false;
                R[r[j]]=1;
            }
        }
        if(!tf) continue;
        if(abs(sum-(all-sum))<=k){
            cout<<"YES"<<'\n';
            return 0;
        }
    }
    cout<<"NO"<<'\n';
    return 0;
}
//maybe its multiset not set
//yeeorz
//laborz

Compilation message

tug.cpp: In function 'void setIO(std::string)':
tug.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tug.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 21 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 21 ms 344 KB Output is correct
6 Correct 26 ms 452 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 6 ms 452 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 21 ms 456 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 21 ms 344 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 24 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 21 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 21 ms 456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 21 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 21 ms 344 KB Output is correct
6 Correct 26 ms 452 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 6 ms 452 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 21 ms 456 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 21 ms 344 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 24 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 21 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 21 ms 456 KB Output is correct
26 Incorrect 1 ms 348 KB Output isn't correct
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 21 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 21 ms 344 KB Output is correct
6 Correct 26 ms 452 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 6 ms 452 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 21 ms 456 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 21 ms 344 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 24 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 21 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 21 ms 456 KB Output is correct
26 Incorrect 1 ms 348 KB Output isn't correct
27 Halted 0 ms 0 KB -