Submission #170143

# Submission time Handle Problem Language Result Execution time Memory
170143 2019-12-24T05:30:05 Z gs18103 Naan (JOI19_naan) C++14
0 / 100
60 ms 632 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define em emplace
#define all(v) v.begin(), v.end()

using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int MAX = 2020;
const int INF = (1 << 30) - 1;
const ll LINF = 1LL << 60;

int n, k, p[MAX], cur[MAX];
ll v[MAX][MAX], sum[MAX][MAX];
pll X[MAX], dv[MAX][MAX];
bool chk[MAX];

int main() {
    ios::sync_with_stdio(false); cin.tie(0);

    cin >> n >> k;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= k; j++) {
            cin >> v[i][j];
            sum[i][j] = sum[i][j-1] + v[i][j];
        }
        int mul = 1;
        for(int j = 1; j <= k; j++) {
            while(sum[i][j] * n > mul * sum[i][k]) {
                dv[i][mul] = make_pair(sum[i][k] * mul - sum[i][j-1] * n, n * v[i][j]);
                dv[i][mul].fi += dv[i][mul].se * (j - 1);
                mul++;
            }
            if(sum[i][j] * n == mul * sum[i][k]) {
                dv[i][mul] = make_pair(j, 1);
                mul++;
            }
        }
        cur[i] = 1;
    }
    pll st = make_pair(0, 1);
    for(int i = 1; i <= n; i++) {
        pll mi = make_pair(1000000001*k, 1000000000);
        int idx = 0;
        for(int j = 1; j <= n; j++) {
            if(chk[j]) continue;
            while(dv[j][cur[j]].fi * st.se <= st.fi * dv[j][cur[j]].se) {
                cur[j]++;
            }
            if(mi.fi * dv[j][cur[j]].se > dv[j][cur[j]].fi * mi.se) {
                mi = dv[j][cur[j]];
                idx = j;
            }
        }
        chk[idx] = true;
        ll g = __gcd(mi.fi, mi.se);
        mi.fi /= g, mi.se /= g;
        p[i] = idx;
        X[i] = mi;
        st = mi;
    }

    for(int i = 1; i < n; i++) {
        cout << X[i].fi << ' ' << X[i].se << '\n';
    }
    for(int i = 1; i <= n; i++) {
        cout << p[i] << ' ';
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Integer parameter [name=P_i] equals to 0, violates the range [1, 2]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 60 ms 632 KB Integer parameter [name=B_i] equals to -62500000, violates the range [1, 1000000000]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Integer parameter [name=P_i] equals to 0, violates the range [1, 2]
2 Halted 0 ms 0 KB -