Submission #566935

# Submission time Handle Problem Language Result Execution time Memory
566935 2022-05-23T06:34:22 Z 600Mihnea Naan (JOI19_naan) C++17
100 / 100
437 ms 78792 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

struct Fraction {
  ll a;
  ll b;

  Fraction(ll a, ll b) : a(a), b(b) {

  }
};

ld getld(Fraction fr) {
  return (ld)fr.a / (ld)fr.b;
}

bool operator < (Fraction First, Fraction Second) {
  return (ld)First.a / First.b < (ld)Second.a / Second.b;
}

Fraction operator + (Fraction First, ll Second) {
  return Fraction(First.a + Second * First.b, First.b);
}

Fraction operator + (ll Second, Fraction First) {
  return Fraction(First.a + Second * First.b, First.b);
}


Fraction operator - (Fraction First, ll Second) {
  return Fraction(First.a - Second * First.b, First.b);
}

Fraction operator - (ll Second, Fraction First) {
  return Fraction(-First.a + Second * First.b, First.b);
}

Fraction operator * (Fraction First, ll Second) {
  return Fraction(First.a * Second, First.b);
}

Fraction operator * (ll Second, Fraction First) {
  return Fraction(First.a * Second, First.b);
}


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

  int People, n;
  cin >> People >> n;
  vector<vector<int>> a(People, vector<int>(n));
  vector<vector<Fraction>> splitPoint(People, vector<Fraction>(People, Fraction(0, 1)));

  for (int i = 0; i < People; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }

  for (int Person = 0; Person < People; Person++) {
    ll totalSum = 0;
    for (auto& x : a[Person]) {
      totalSum += x;
    }
    int done = 0;
    ll currentSum = 0;
    Fraction fromLast(0, 1);
    for (int j = 0; j < People; j++) {
      Fraction want((j + 1) * totalSum, People);
      while (Fraction(currentSum + a[Person][done], 1) < want) {
        currentSum += a[Person][done++];
        fromLast = Fraction(0, 1);
      }
      Fraction dif = want - currentSum;
      Fraction x(dif.a, dif.b * a[Person][done]);
      splitPoint[Person][j] = done + x;
      fromLast = x;
    }
  }

  vector<bool> valid(People, 1);
  vector<int> guys;

  for (int ch = 0; ch < People; ch++) {
    int sol = -1;
    for (int i = 0; i < People; i++) {
      if (valid[i]) {
        if (sol == -1) {
          sol = i;
        }
        else {
          if (splitPoint[i][ch] < splitPoint[sol][ch]) {
            sol = i;
          }
        }
      }
    }
    valid[sol] = 0;
    if (ch != People - 1) {
      cout << splitPoint[sol][ch].a << " " << splitPoint[sol][ch].b << "\n";
    }
    guys.push_back(sol);
  }
  cout << "\n";
  for (auto& Guy : guys) {
    cout << Guy + 1 << " ";
  }
  cout << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 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 212 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 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 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 0 ms 212 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 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 340 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 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 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 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 340 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 340 KB Output is correct
43 Correct 29 ms 6356 KB Output is correct
44 Correct 172 ms 36360 KB Output is correct
45 Correct 115 ms 12884 KB Output is correct
46 Correct 15 ms 1324 KB Output is correct
47 Correct 127 ms 21052 KB Output is correct
48 Correct 112 ms 58772 KB Output is correct
49 Correct 42 ms 14072 KB Output is correct
50 Correct 204 ms 71324 KB Output is correct
51 Correct 120 ms 24148 KB Output is correct
52 Correct 224 ms 59124 KB Output is correct
53 Correct 210 ms 53772 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 47 ms 31884 KB Output is correct
56 Correct 149 ms 35192 KB Output is correct
57 Correct 136 ms 29780 KB Output is correct
58 Correct 152 ms 53484 KB Output is correct
59 Correct 134 ms 28256 KB Output is correct
60 Correct 404 ms 78708 KB Output is correct
61 Correct 437 ms 78640 KB Output is correct
62 Correct 416 ms 78280 KB Output is correct
63 Correct 425 ms 78696 KB Output is correct
64 Correct 389 ms 78792 KB Output is correct
65 Correct 293 ms 78720 KB Output is correct
66 Correct 346 ms 78768 KB Output is correct
67 Correct 309 ms 78788 KB Output is correct
68 Correct 158 ms 36784 KB Output is correct
69 Correct 166 ms 32892 KB Output is correct
70 Correct 179 ms 46344 KB Output is correct
71 Correct 257 ms 51988 KB Output is correct