Submission #817900

# Submission time Handle Problem Language Result Execution time Memory
817900 2023-08-09T19:28:09 Z LucaIlie Naan (JOI19_naan) C++17
100 / 100
1031 ms 85092 KB
#include <bits/stdc++.h>

using namespace std;

const int INF = 1e9;
const int MAX_B = 1e6;

const int MAX_N = 2000;
const int MAX_L = 2000;

bool active[MAX_N];
int permutation[MAX_N];
double happiness[MAX_N][MAX_L + 1], sumHappiness[MAX_N][MAX_L + 1];
double happy[MAX_N], timeFrac[MAX_N], timeFractions[MAX_N];

int main() {
    int n, l;

    cin >> n >> l;
    for ( int i = 0; i < n; i++ ) {
        happy[i] = 0;
        sumHappiness[i][0] = 0;
        for ( int j = 1; j <= l; j++ ) {
            int aux;
            cin >> aux;
            happiness[i][j] = aux;
            happy[i] += aux;
            sumHappiness[i][j] = sumHappiness[i][j - 1] + happiness[i][j];
        }
        happy[i] /= n;
    }

    for ( int i = 0; i < n; i++ )
        active[i] = true;

    timeFractions[0] = 0;
    permutation[0] = 0;
    for ( int pas = 1; pas <= n; pas++ ) {
        for ( int i = 0; i < n; i++ ) {
            if ( !active[i] ) {
                timeFrac[i] = INF + 1;
                continue;
            }

            int j = floor( timeFractions[pas - 1] );
            double crtHappiness = happiness[i][j + 1] * (j + 1 - timeFractions[pas - 1]);

            if ( crtHappiness > happy[i] ) {
                timeFrac[i] = timeFractions[pas - 1] + happy[i] / happiness[i][j + 1];
                continue;
            }

            int left = j + 1, right = l + 1;
            while ( right - left > 1 ) {
                int mid = (left + right) / 2;

                if ( crtHappiness + (sumHappiness[i][mid] - sumHappiness[i][j + 1]) < happy[i] )
                    left = mid;
                else
                    right = mid;
            }
            if ( left == l ) {
                timeFrac[i] = INF;
                continue;
            }
            crtHappiness = crtHappiness + (sumHappiness[i][left] - sumHappiness[i][j + 1]);
            timeFrac[i] = left + (happy[i] - crtHappiness) / happiness[i][left + 1];
        }
        int p = 0;
        for ( int i = 0; i < n; i++ ) {
            if ( active[i] && timeFrac[i] < timeFrac[p] )
                p = i;
        }

        timeFractions[pas] = timeFrac[p];
        permutation[pas] = p;
        active[p] = false;
    }

    for ( int i = 1; i < n; i++ )
        cout << (int)floor( timeFractions[i] * MAX_B ) << " " << MAX_B << "\n";
    for ( int i = 1; i <= n; i++ )
        cout << permutation[i] + 1 << " ";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 2 ms 480 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 2 ms 480 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 65 ms 8888 KB Output is correct
44 Correct 451 ms 48000 KB Output is correct
45 Correct 284 ms 29256 KB Output is correct
46 Correct 39 ms 5196 KB Output is correct
47 Correct 344 ms 38384 KB Output is correct
48 Correct 315 ms 30656 KB Output is correct
49 Correct 100 ms 16276 KB Output is correct
50 Correct 603 ms 61536 KB Output is correct
51 Correct 303 ms 36676 KB Output is correct
52 Correct 628 ms 60920 KB Output is correct
53 Correct 482 ms 54220 KB Output is correct
54 Correct 1 ms 468 KB Output is correct
55 Correct 42 ms 14312 KB Output is correct
56 Correct 281 ms 45148 KB Output is correct
57 Correct 268 ms 39616 KB Output is correct
58 Correct 338 ms 48760 KB Output is correct
59 Correct 298 ms 39568 KB Output is correct
60 Correct 978 ms 84812 KB Output is correct
61 Correct 984 ms 84892 KB Output is correct
62 Correct 1031 ms 84812 KB Output is correct
63 Correct 1002 ms 85092 KB Output is correct
64 Correct 991 ms 84968 KB Output is correct
65 Correct 535 ms 71668 KB Output is correct
66 Correct 536 ms 71684 KB Output is correct
67 Correct 652 ms 71628 KB Output is correct
68 Correct 332 ms 43340 KB Output is correct
69 Correct 441 ms 46908 KB Output is correct
70 Correct 359 ms 47336 KB Output is correct
71 Correct 608 ms 61248 KB Output is correct