답안 #717435

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
717435 2023-04-01T22:59:27 Z vjudge1 Table Tennis (info1cup20_tabletennis) C++17
0 / 100
1694 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define all(x) x.begin(),x.end()
const int MOD = 1e9 + 7, SZ = 1e5 + 10, MX = 1e9;
vector<int> vec;
int ans = 0;
void solve(int n, int m, int a, int b, int i){
    if(n == 0){
        if(a == b)
        ans = m;
        return;
    }
    if(i == vec.size())
        return;
    solve(n-1, m, a + vec[i], b, i+1);
    solve(n-1, m, a, b + vec[i], i+1);
    solve(n, m - (1 << i), a, b, i+1);
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, k;
    cin >> n >> k;
    int arr[n + k];
    for(int &i : arr)
        cin >> i;
    map<int, int> mp;
    for(int i=0;i<=k;i++){
        if(mp[arr[i]])
            continue;
        vec.push_back(arr[i]);
    }
    for(int i=n+k-1;i=max(n-2, 0ll);i--){
        if(mp[arr[i]])
            continue;
        vec.push_back(arr[i]);
    }
    sort(all(vec));
    solve(n, (1ll << 31) - 1, 0, 0, 0);
    for(int i=0;i<n;i++){
        if((1 << i) & ans)
            cout << arr[i] << ' ';
    }
    return 0;
}
// https://www.youtube.com/watch?v=zL32whN6p0A&ab_channel=HeidiAdel-CartoonWorld

Compilation message

tabletennis.cpp: In function 'void solve(long long int, long long int, long long int, long long int, long long int)':
tabletennis.cpp:15:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     if(i == vec.size())
      |        ~~^~~~~~~~~~~~~
tabletennis.cpp: In function 'int main()':
tabletennis.cpp:34:22: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   34 |     for(int i=n+k-1;i=max(n-2, 0ll);i--){
      |                     ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 889 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1012 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 929 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1151 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 979 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1124 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1211 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1694 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -