Submission #881447

# Submission time Handle Problem Language Result Execution time Memory
881447 2023-12-01T08:57:32 Z nima_aryan Naan (JOI19_naan) C++17
100 / 100
320 ms 111408 KB
/**
 *    author:  NimaAryan
 *    created: 2023-12-01 08:14:38  
**/
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#endif

using i64 = long long;
using i128 = __int128;

constexpr i64 inf = 1E14;

struct Z {
  i64 A = 0;
  i64 B = 1;

  Z() { }
  Z(i64 A, i64 B) : A(A), B(B) { }

  bool operator<(const Z& other) const {
    return (i128) A * other.B < (i128) other.A * B;
  }
};

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

  int N, L;
  cin >> N >> L;

  vector V(N, vector<i64>(L));
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < L; ++j) {
      cin >> V[i][j];
    }
  }

  vector C(N, vector<Z>(N));
  for (int i = 0; i < N; ++i) {
    i64 sum = accumulate(V[i].begin(), V[i].end(), 0LL);
    i64 pref = 0;
    Z res{};

    for (int j = 0, k = 0; j < N; ++j) {
      while (k < L && Z(pref, j + 1) < Z(sum, N)) {
        pref += V[i][k++];
      }

      if (Z(k, 1) < res) {
        res.A += sum;
      } else {
        res = Z(1LL * N * V[i][k - 1] * (k - 1) + sum * (j + 1) - N * (pref - V[i][k - 1]), N * V[i][k - 1]);
      }

      C[i][j] = res;
    }
  }

  vector<Z> H;
  vector<bool> used(N);
  vector<int> P;
  for (int j = 0; j < N; ++j) {
    Z best(inf, 1);
    int who = -1;

    for (int i = 0; i < N; ++i) {
      if (!used[i] && C[i][j] < best) {
        tie(best, who) = pair(C[i][j], i);
      }
    }

    H.push_back(best);
    P.push_back(who);
    used[who] = true;
  }

  for (int i = 0; i < N - 1; ++i) {
    cout << H[i].A << " " << H[i].B << "\n";
  }
  for (int i = 0; i < N; ++i) {
    cout << P[i] + 1 << " \n"[i + 1 == N];
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 524 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 576 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 476 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 472 KB Output is correct
20 Correct 1 ms 476 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 1 ms 356 KB Output is correct
23 Correct 0 ms 452 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 352 KB Output is correct
27 Correct 1 ms 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 524 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 576 KB Output is correct
25 Correct 1 ms 464 KB Output is correct
26 Correct 1 ms 476 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 472 KB Output is correct
35 Correct 1 ms 476 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 1 ms 356 KB Output is correct
38 Correct 0 ms 452 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 0 ms 352 KB Output is correct
42 Correct 1 ms 352 KB Output is correct
43 Correct 21 ms 8992 KB Output is correct
44 Correct 186 ms 50952 KB Output is correct
45 Correct 87 ms 23924 KB Output is correct
46 Correct 13 ms 3164 KB Output is correct
47 Correct 134 ms 33108 KB Output is correct
48 Correct 81 ms 64124 KB Output is correct
49 Correct 35 ms 17240 KB Output is correct
50 Correct 161 ms 86000 KB Output is correct
51 Correct 90 ms 34100 KB Output is correct
52 Correct 180 ms 77608 KB Output is correct
53 Correct 133 ms 66488 KB Output is correct
54 Correct 1 ms 344 KB Output is correct
55 Correct 30 ms 33112 KB Output is correct
56 Correct 113 ms 47292 KB Output is correct
57 Correct 94 ms 39248 KB Output is correct
58 Correct 134 ms 64560 KB Output is correct
59 Correct 111 ms 40128 KB Output is correct
60 Correct 306 ms 111408 KB Output is correct
61 Correct 320 ms 111268 KB Output is correct
62 Correct 295 ms 110764 KB Output is correct
63 Correct 303 ms 105684 KB Output is correct
64 Correct 316 ms 105932 KB Output is correct
65 Correct 223 ms 99156 KB Output is correct
66 Correct 226 ms 99156 KB Output is correct
67 Correct 237 ms 99368 KB Output is correct
68 Correct 107 ms 46676 KB Output is correct
69 Correct 130 ms 45472 KB Output is correct
70 Correct 120 ms 56664 KB Output is correct
71 Correct 186 ms 70020 KB Output is correct