Submission #1054614

# Submission time Handle Problem Language Result Execution time Memory
1054614 2024-08-12T11:05:53 Z otarius Olympiads (BOI19_olympiads) C++17
13 / 100
9 ms 992 KB
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()

// #define int long long
// #define int unsigned long long

// #define ordered_set(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
// #define ordered_multiset(T) tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>

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

// const ll mod = 1e9 + 7;
// const ll mod = 998244353;

const ll inf = 1e9;
const ll biginf = 1e18;
const int maxN = 3 * 1e5 + 25;

vector<int> vals;
int n, k, c, arr[505][10];
void one() {
    for (int i = 1; i <= n; i++)
        vals.pb(arr[i][1]);
}
void two() {
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            int x = max(arr[i][1], arr[j][1]);
            int y = max(arr[i][2], arr[j][2]);
            vals.pb(x + y);
        }
    }
}
void three() {
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            for (int k = j + 1; k <= n; k++) {
                int x = max({arr[i][1], arr[j][1], arr[k][1]});
                int y = max({arr[i][2], arr[j][2], arr[k][2]});
                int z = max({arr[i][3], arr[j][3], arr[k][3]});
                vals.pb(x + y + z);
            }
        }
    }
}
void four() {
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            for (int k = j + 1; k <= n; k++) {
                for (int l = k + 1; l <= n; l++) {
                    int x = max({arr[i][1], arr[j][1], arr[k][1], arr[l][1]});
                    int y = max({arr[i][2], arr[j][2], arr[k][2], arr[l][2]});
                    int z = max({arr[i][3], arr[j][3], arr[k][3], arr[l][3]});
                    int t = max({arr[i][4], arr[j][4], arr[k][4], arr[l][4]});
                    vals.pb(x + y + z + t);
                }
            }
        }
    }
}
void five() {
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            for (int k = j + 1; k <= n; k++) {
                for (int l = k + 1; l <= n; l++) {
                    for (int m = l + 1; m <= n; m++) {
                        int x = max({arr[i][1], arr[j][1], arr[k][1], arr[l][1], arr[m][1]});
                        int y = max({arr[i][2], arr[j][2], arr[k][2], arr[l][2], arr[m][2]});
                        int z = max({arr[i][3], arr[j][3], arr[k][3], arr[l][3], arr[m][3]});
                        int t = max({arr[i][4], arr[j][4], arr[k][4], arr[l][4], arr[m][4]});
                        int c = max({arr[i][5], arr[j][5], arr[k][5], arr[l][5], arr[m][5]});
                        vals.pb(x + y + z + t + c);
                    }
                }
            }
        }
    }
}
void six() {
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            for (int k = j + 1; k <= n; k++) {
                for (int l = k + 1; l <= n; l++) {
                    for (int m = l + 1; m <= n; m++) {
                        for (int o = m + 1; o <= n; o++) {
                            int x = max({arr[i][1], arr[j][1], arr[k][1], arr[l][1], arr[c][1], arr[o][1]});
                            int y = max({arr[i][2], arr[j][2], arr[k][2], arr[l][2], arr[c][2], arr[o][2]});
                            int z = max({arr[i][3], arr[j][3], arr[k][3], arr[l][3], arr[c][3], arr[o][3]});
                            int t = max({arr[i][4], arr[j][4], arr[k][4], arr[l][4], arr[c][4], arr[o][4]});
                            int c = max({arr[i][5], arr[j][5], arr[k][5], arr[l][5], arr[c][5], arr[o][5]});
                            int d = max({arr[i][6], arr[j][6], arr[k][6], arr[l][6], arr[c][6], arr[o][6]});
                            vals.pb(x + y + z + t + c + d);
                        }
                    }
                }
            }
        }
    }
}
void solve() {
    cin >> n >> k >> c;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= k; j++)
            cin >> arr[i][j];
    if (k == 1) one();
    if (k == 2) two();
    if (k == 3) three();
    if (k == 4) four();
    if (k == 5) five();
    if (k == 6) six();
    sort(vals.rbegin(), vals.rend());
    cout << vals[c - 1];
}
int32_t main() { 
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    }
    return 0;
}

Compilation message

olympiads.cpp: In function 'void open_file(std::string)':
olympiads.cpp:26:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     freopen((filename + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
olympiads.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen((filename + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
olympiads.cpp: In function 'void six()':
olympiads.cpp:108:94: warning: 'c' may be used uninitialized in this function [-Wmaybe-uninitialized]
  108 |                             int c = max({arr[i][5], arr[j][5], arr[k][5], arr[l][5], arr[c][5], arr[o][5]});
      |                                                                                      ~~~~~~~~^
# Verdict Execution time Memory Grader output
1 Correct 9 ms 992 KB Output is correct
2 Correct 5 ms 992 KB Output is correct
3 Correct 4 ms 992 KB Output is correct
4 Correct 1 ms 992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 992 KB Output is correct
2 Correct 5 ms 992 KB Output is correct
3 Correct 4 ms 992 KB Output is correct
4 Correct 1 ms 992 KB Output is correct
5 Runtime error 1 ms 348 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -