Submission #1349949

#TimeUsernameProblemLanguageResultExecution timeMemory
1349949rmielamudNaan (JOI19_naan)C++20
0 / 100
4093 ms536 KiB
#include <bits/stdc++.h>

using namespace std;

#define short int32_t
#define int int64_t
#define long __int128_t

const int inf{numeric_limits<int>::max() / 4};

short main() {
    #ifndef LOCAL
        ios_base::sync_with_stdio(false);
        cin.tie(nullptr);
    #endif

    int n, l;
    cin >> n >> l;

    vector v(n, vector<int>(l));

    for (auto& row : v) {
        for (int& val : row) {
            cin >> val;
        }
    }

    vector<int> sums(n);

    for (int i{0}; i < n; i++) {
        for (int j{0}; j < l; j++) {
            sums[i] += v[i][j];
        }
    }

    vector<int> order(n);
    iota(order.begin(), order.end(), 0);
    
    do {
        int pos{0};

        vector<int> as(n - 1);
        vector<int> bs(n - 1);
        bool found{true};

        for (int i{0}; i < n; i++) {
            int person{order[i]};
            int sum{0};
            bool ok{false};

            while (pos < l * n * l) {
                if (sum >= sums[person] * l) {
                    ok = true;
                    break;
                }

                sum += v[person][pos / n / l];
                pos++;
            }

            if (!ok) {
                found = false;
                break;
            }

            if (i < n - 1) {
                as[i] = pos;
                bs[i] = n * l;
            }
        }

        if (found) {
            for (int i{0}; i < n - 1; i++) {
                cout << as[i] << " " << bs[i] << "\n";
            }

            vector<int> iorder(n);

            for (int i{0}; i < n; i++) {
                iorder[order[i]] = i;
            }

            for (int i : iorder) {
                cout << i + 1 << " ";
            }

            cout << "\n";
            return 0;
        }
    } while (next_permutation(order.begin(), order.end()));

    cout << "-1\n";

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...