답안 #244776

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
244776 2020-07-05T00:25:46 Z thecodingwizard Naan (JOI19_naan) C++11
29 / 100
4000 ms 116000 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long

// returns true if fraction a < fraction b
bool better(pair<ll, ll> a, pair<ll, ll> b) {
    return __int128(a.first)*b.second<__int128(a.second)*b.first;
}

pair<ll,ll> reduce(pair<ll, ll>a) {
    ll g = __gcd(a.first, a.second);
    return make_pair(a.first/g,a.second/g);
}

int main() {
    int n, l; cin >> n >> l;
    ll V[n][l];
    ll sum[n];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) cin >> V[i][j];
        sum[i] = 0; for (int j = 0; j < l; j++) sum[i] += V[i][j];
    }
    pair<ll, ll> split[n][n];
    for (int i = 0; i < n; i++) {
        for (int j = 1; j < n; j++) {
            ll want = sum[i]*j;
            int cur = 0;
            while (cur < l && V[i][cur]*n <= want) {
                want -= V[i][cur]*n;
                cur++;
            }
            split[i][j] = reduce(make_pair((ll)cur*V[i][cur]*n+want, V[i][cur]*n));
            //cout << "split[" << i << "][" << j << "] = " << split[i][j].first << "/" << split[i][j].second << endl;
        }
    }
    bool taken[n]; for (int i = 0; i < n; i++) taken[i] = false;
    vector<int> permutation;
    for (int i = 1; i < n; i++) {
        int best = -1;
        for (int j = 0; j < n; j++) {
            if (taken[j]) continue;
            if (best == -1) {
                best = j;
            } else {
                if (better(split[j][i], split[best][i])) best = j;
            }
        }
        taken[best] = true;
        cout << split[best][i].first << " " << split[best][i].second << endl;
        permutation.push_back(best+1);
    }
    for (int j = 0; j < n; j++) if (!taken[j]) permutation.push_back(j+1);
    for (int x : permutation) cout << x << " ";
    cout << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 7 ms 384 KB Output is correct
10 Correct 7 ms 384 KB Output is correct
11 Correct 7 ms 384 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 7 ms 384 KB Output is correct
17 Correct 7 ms 384 KB Output is correct
18 Correct 7 ms 384 KB Output is correct
19 Correct 7 ms 384 KB Output is correct
20 Correct 6 ms 384 KB Output is correct
21 Correct 7 ms 384 KB Output is correct
22 Correct 7 ms 384 KB Output is correct
23 Correct 5 ms 256 KB Output is correct
24 Correct 6 ms 384 KB Output is correct
25 Correct 6 ms 384 KB Output is correct
26 Correct 6 ms 384 KB Output is correct
27 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 7 ms 384 KB Output is correct
20 Correct 6 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 7 ms 384 KB Output is correct
25 Correct 7 ms 384 KB Output is correct
26 Correct 7 ms 384 KB Output is correct
27 Correct 5 ms 256 KB Output is correct
28 Correct 6 ms 384 KB Output is correct
29 Correct 6 ms 384 KB Output is correct
30 Correct 6 ms 384 KB Output is correct
31 Correct 7 ms 384 KB Output is correct
32 Correct 7 ms 384 KB Output is correct
33 Correct 7 ms 384 KB Output is correct
34 Correct 7 ms 384 KB Output is correct
35 Correct 6 ms 384 KB Output is correct
36 Correct 7 ms 384 KB Output is correct
37 Correct 7 ms 384 KB Output is correct
38 Correct 5 ms 256 KB Output is correct
39 Correct 6 ms 384 KB Output is correct
40 Correct 6 ms 384 KB Output is correct
41 Correct 6 ms 384 KB Output is correct
42 Correct 6 ms 384 KB Output is correct
43 Correct 213 ms 7468 KB Output is correct
44 Correct 1937 ms 43128 KB Output is correct
45 Correct 938 ms 25464 KB Output is correct
46 Correct 94 ms 3192 KB Output is correct
47 Correct 1287 ms 34680 KB Output is correct
48 Correct 1364 ms 63888 KB Output is correct
49 Correct 385 ms 17144 KB Output is correct
50 Correct 3211 ms 86648 KB Output is correct
51 Correct 1273 ms 34660 KB Output is correct
52 Correct 3380 ms 78752 KB Output is correct
53 Correct 2485 ms 67548 KB Output is correct
54 Correct 6 ms 384 KB Output is correct
55 Correct 417 ms 32720 KB Output is correct
56 Correct 1093 ms 48104 KB Output is correct
57 Correct 1851 ms 39672 KB Output is correct
58 Correct 3001 ms 65112 KB Output is correct
59 Correct 2375 ms 40872 KB Output is correct
60 Execution timed out 4019 ms 116000 KB Time limit exceeded
61 Halted 0 ms 0 KB -