답안 #866529

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
866529 2023-10-26T10:30:31 Z mychecksedad Olympiads (BOI19_olympiads) C++17
13 / 100
793 ms 262144 KB
/* Author : Mychecksdead  */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30;

int n, k, c;
vector<vector<int>> v;
vector<int> check(vector<int> &x, vector<int> &y){
  vector<int> aa;
  merge(all(x), all(y), back_inserter(aa));
  aa.erase(unique(all(aa)), aa.end());
  return aa;
}
void solve(){
  cin >> n >> k >> c;
  v.resize(n, vector<int> (k));
  for(int i = 0; i < n; ++i) for(auto &x: v[i]) cin >> x;
  if(k == 1){
    int ans = 0;
    vector<int> cc;
    for(int i = 0; i < n; ++i) cc.pb(v[i][0]);
    sort(all(cc), greater<int>());
    cout << cc[c-1];
  }else if(k == 2){
    int ans = 0;
    vector<int> cc;
    for(int i = 0; i < n; ++i){
      for(int j = i+1; j < n; ++j){
        cc.pb(max(v[i][0], v[j][0])+max(v[i][1], v[j][1]));
      }
    }
    sort(all(cc), greater<int>());
    cout << cc[c-1];
  }else{
    vector<pair<int, vector<int>>> A;
    for(int i = 0; i < n; ++i){
      for(int j = i + 1; j < n; ++j){
        for(int l = j + 1; l < n; ++l){
          vector<int> mx(k), tt;
          for(int kk = 0; kk < k; ++kk){
            mx[kk] = max({v[i][kk], v[j][kk], v[l][kk]});
          }
          for(int u = 0; u < k; ++u) tt.pb(mx[u]);
          sort(all(tt), greater<int>());
          A.pb({tt[0] + tt[1] + tt[2], {i, j, l}});
        }
      }
    }
    sort(all(A), [&](const pair<int, vector<int>> &x, const pair<int, vector<int>> &y){
      return x.first < y.first;
    });
    if(k == 3){
      cout << A[0].first;
      return;
    }
    set<pair<int, vector<int>>> S;
    for(int i = 0; S.size() < 4*c && i < A.size(); ++i){
      for(int j = i + 1; j < A.size(); ++j){
        auto x = check(A[i].second, A[j].second);
        if(int(x.size()) == k){
          int res = 0;
          for(int kk = 0; kk < k; ++kk){
            int mx = 0;
            for(int l: A[i].second) mx = max(mx, v[l][kk]);
            for(int l: A[j].second) mx = max(mx, v[l][kk]);
            res += mx;
          }
          S.insert({res, x});
        }
      }
    }
    int cc = 1;
    auto it = prev(S.end());
    while(cc < c){
      --it;
      cc++;
    }
    cout << (*it).first;
  }
}

int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tt = 1, aa;
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  while(tt--){
    solve();
  }
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
  return 0;
} 

Compilation message

olympiads.cpp: In function 'void solve()':
olympiads.cpp:25:9: warning: unused variable 'ans' [-Wunused-variable]
   25 |     int ans = 0;
      |         ^~~
olympiads.cpp:31:9: warning: unused variable 'ans' [-Wunused-variable]
   31 |     int ans = 0;
      |         ^~~
olympiads.cpp:63:29: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<int, std::vector<int> > >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   63 |     for(int i = 0; S.size() < 4*c && i < A.size(); ++i){
      |                    ~~~~~~~~~^~~~~
olympiads.cpp:63:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::vector<int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |     for(int i = 0; S.size() < 4*c && i < A.size(); ++i){
      |                                      ~~^~~~~~~~~~
olympiads.cpp:64:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::vector<int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |       for(int j = i + 1; j < A.size(); ++j){
      |                          ~~^~~~~~~~~~
olympiads.cpp: In function 'int main()':
olympiads.cpp:90:15: warning: unused variable 'aa' [-Wunused-variable]
   90 |   int tt = 1, aa;
      |               ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 988 KB Output is correct
2 Correct 6 ms 988 KB Output is correct
3 Correct 5 ms 1068 KB Output is correct
4 Correct 2 ms 988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 793 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 988 KB Output is correct
2 Correct 6 ms 988 KB Output is correct
3 Correct 5 ms 1068 KB Output is correct
4 Correct 2 ms 988 KB Output is correct
5 Incorrect 9 ms 2648 KB Output isn't correct
6 Halted 0 ms 0 KB -