Submission #945527

# Submission time Handle Problem Language Result Execution time Memory
945527 2024-03-14T03:33:35 Z yeediot Olympiads (BOI19_olympiads) C++14
100 / 100
187 ms 31916 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pb push_back
#define sz(x) (int)(x.size())
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define vi vector<int>
#define vp vector<pii>
#define vvi vector<vi>
#define ykh mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count())
#define __lg(x) 63-__builtin_clzll(x)
#define pow2(x) (1LL<<x)
void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef local
void setio(){freopen("/Users/iantsai/Library/Mobile Documents/com~apple~CloudDocs/cpp/Empty.md","r",stdin);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
void setio(){}
#define debug(x...)
#endif
void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
struct line{
    int a,b;
    int operator()(const int x)const{
        return a*x+b;
    }
};
bool check(line l1,line l2,line l3){
    return (l3.b-l2.b)*(l1.a-l2.a)<=(l2.b-l1.b)*(l2.a-l3.a);
}
const int mxn=505;
int v[mxn][7];
int conv[7][mxn];
vector<int>ord[7];
int _,n,k;
bool cmp(int a,int b){
    return v[a][_]>v[b][_];
}
int get_val(set<int>st){
    vector<int>mx(k,-8e18);
    for(auto i:st){
        for(int j=0;j<k;j++){
            mx[j]=max(mx[j],v[i][j]);
        }
    }
    int res=0;
    for(int i=0;i<k;i++){
        res+=mx[i];
    }
    return res;
}
vector<int>get_id(set<int>st){
    vector<int>res;
    for(auto i:st)res.pb(i);
    return res;
}
signed main(){
    setio();
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int c;
    cin>>n>>k>>c;
    for(int i=0;i<n;i++){
        for(int j=0;j<k;j++){
            ord[j].pb(i);
            cin>>v[i][j];
        }
    }
    for(int i=0;i<k;i++){
        _=i;
        sort(all(ord[i]),cmp);
        for(int j=0;j<n;j++){
            conv[i][ord[i][j]]=j;
        }
    }
    set<int>st;
    for(int i=0;i<k;i++){
        st.insert(ord[i][0]);
    }
    for(int i=0;i<n;i++){
        if(sz(st)==k)break;
        st.insert(i);
    }
    map<set<int>,bool>mp;
    priority_queue<tuple<int,vector<int>>>pq;
    pq.push({get_val(st),get_id(st)});
    c--;
    mp[st]=1;
    while(c--){
        auto [sum,num]=pq.top();
        pq.pop();
        for(int i=0;i<k;i++){
            set<int>c;
            for(int j=0;j<k;j++){
                if(j==i)continue;
                c.insert(num[j]);
            }
            for(int j=0;j<k;j++){
                //if(j==i)continue;
                int pos=conv[j][num[i]]+1;
                if(pos==n)continue;
                c.insert(ord[j][pos]);
                if(sz(c)==k and !mp[c]){
                    pq.push({get_val(c),get_id(c)});
                    mp[c]=1;
                }
                if(sz(c)==k)c.erase(ord[j][pos]);
            }
        }
    }
    cout<<get<0>(pq.top())<<'\n';
}
 /*
 input:
 
 */















 

Compilation message

olympiads.cpp: In function 'int main()':
olympiads.cpp:113:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  113 |         auto [sum,num]=pq.top();
      |              ^
olympiads.cpp: In function 'void setIO(std::string)':
olympiads.cpp:42:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
olympiads.cpp:43:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1628 KB Output is correct
2 Correct 6 ms 1648 KB Output is correct
3 Correct 8 ms 1884 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 18108 KB Output is correct
2 Correct 79 ms 14580 KB Output is correct
3 Correct 48 ms 6600 KB Output is correct
4 Correct 58 ms 7644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 158 ms 31916 KB Output is correct
2 Correct 40 ms 3280 KB Output is correct
3 Correct 143 ms 27552 KB Output is correct
4 Correct 148 ms 29052 KB Output is correct
5 Correct 75 ms 10740 KB Output is correct
6 Correct 43 ms 5836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1628 KB Output is correct
2 Correct 6 ms 1648 KB Output is correct
3 Correct 8 ms 1884 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 96 ms 18108 KB Output is correct
6 Correct 79 ms 14580 KB Output is correct
7 Correct 48 ms 6600 KB Output is correct
8 Correct 58 ms 7644 KB Output is correct
9 Correct 158 ms 31916 KB Output is correct
10 Correct 40 ms 3280 KB Output is correct
11 Correct 143 ms 27552 KB Output is correct
12 Correct 148 ms 29052 KB Output is correct
13 Correct 75 ms 10740 KB Output is correct
14 Correct 43 ms 5836 KB Output is correct
15 Correct 187 ms 30912 KB Output is correct
16 Correct 154 ms 30008 KB Output is correct
17 Correct 43 ms 6580 KB Output is correct
18 Correct 74 ms 12232 KB Output is correct
19 Correct 39 ms 3324 KB Output is correct