Submission #566933

# Submission time Handle Problem Language Result Execution time Memory
566933 2022-05-23T06:33:50 Z 600Mihnea Naan (JOI19_naan) C++17
100 / 100
398 ms 78908 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 din(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++];
        din = Fraction(0, 1);
      }
      Fraction dif = want - currentSum;
      Fraction x(dif.a, dif.b * a[Person][done]);
      splitPoint[Person][j] = done + x;
      din = 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 1 ms 212 KB Output is correct
2 Correct 1 ms 212 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 212 KB Output is correct
6 Correct 0 ms 212 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 212 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 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 340 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 1 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 2 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 2 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 212 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 212 KB Output is correct
6 Correct 0 ms 212 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 212 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 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 340 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 1 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 2 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 2 ms 340 KB Output is correct
43 Correct 44 ms 6356 KB Output is correct
44 Correct 189 ms 36360 KB Output is correct
45 Correct 118 ms 12860 KB Output is correct
46 Correct 22 ms 1236 KB Output is correct
47 Correct 136 ms 20948 KB Output is correct
48 Correct 157 ms 58808 KB Output is correct
49 Correct 46 ms 14064 KB Output is correct
50 Correct 201 ms 71276 KB Output is correct
51 Correct 115 ms 24148 KB Output is correct
52 Correct 216 ms 59044 KB Output is correct
53 Correct 165 ms 53716 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 47 ms 31896 KB Output is correct
56 Correct 145 ms 35192 KB Output is correct
57 Correct 114 ms 29792 KB Output is correct
58 Correct 168 ms 53488 KB Output is correct
59 Correct 137 ms 28256 KB Output is correct
60 Correct 385 ms 78796 KB Output is correct
61 Correct 394 ms 78668 KB Output is correct
62 Correct 398 ms 78280 KB Output is correct
63 Correct 376 ms 78668 KB Output is correct
64 Correct 371 ms 78796 KB Output is correct
65 Correct 269 ms 78696 KB Output is correct
66 Correct 269 ms 78908 KB Output is correct
67 Correct 289 ms 78724 KB Output is correct
68 Correct 189 ms 36788 KB Output is correct
69 Correct 171 ms 32900 KB Output is correct
70 Correct 165 ms 46152 KB Output is correct
71 Correct 230 ms 51976 KB Output is correct