Submission #817901

# Submission time Handle Problem Language Result Execution time Memory
817901 2023-08-09T19:29:25 Z LucaIlie Naan (JOI19_naan) C++17
100 / 100
1057 ms 63336 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 308 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 308 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 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 452 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 1 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 444 KB Output is correct
10 Correct 2 ms 444 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 2 ms 440 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 2 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 2 ms 448 KB Output is correct
21 Correct 2 ms 428 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 2 ms 444 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 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 308 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 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 452 KB Output is correct
19 Correct 3 ms 468 KB Output is correct
20 Correct 1 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 444 KB Output is correct
25 Correct 2 ms 444 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 440 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 2 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 2 ms 448 KB Output is correct
36 Correct 2 ms 428 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 2 ms 444 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 316 KB Output is correct
42 Correct 1 ms 444 KB Output is correct
43 Correct 74 ms 9164 KB Output is correct
44 Correct 453 ms 38416 KB Output is correct
45 Correct 294 ms 22292 KB Output is correct
46 Correct 42 ms 4188 KB Output is correct
47 Correct 353 ms 30576 KB Output is correct
48 Correct 323 ms 29120 KB Output is correct
49 Correct 106 ms 15448 KB Output is correct
50 Correct 598 ms 56236 KB Output is correct
51 Correct 289 ms 33224 KB Output is correct
52 Correct 646 ms 54240 KB Output is correct
53 Correct 497 ms 49588 KB Output is correct
54 Correct 1 ms 468 KB Output is correct
55 Correct 42 ms 14152 KB Output is correct
56 Correct 289 ms 41128 KB Output is correct
57 Correct 251 ms 36556 KB Output is correct
58 Correct 337 ms 45184 KB Output is correct
59 Correct 298 ms 35532 KB Output is correct
60 Correct 1004 ms 63276 KB Output is correct
61 Correct 1032 ms 63180 KB Output is correct
62 Correct 1006 ms 63056 KB Output is correct
63 Correct 1018 ms 63216 KB Output is correct
64 Correct 1057 ms 63212 KB Output is correct
65 Correct 532 ms 63336 KB Output is correct
66 Correct 541 ms 63228 KB Output is correct
67 Correct 665 ms 63304 KB Output is correct
68 Correct 337 ms 37464 KB Output is correct
69 Correct 431 ms 39356 KB Output is correct
70 Correct 368 ms 41216 KB Output is correct
71 Correct 620 ms 50488 KB Output is correct