답안 #651189

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
651189 2022-10-17T22:25:20 Z tvladm2009 Naan (JOI19_naan) C++14
100 / 100
427 ms 100984 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 / (ld)First.b <= (ld)Second.a / (ld)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 {First.a * Second, First.b};
}

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

signed main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.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);
  }
  for (auto &Guy : guys) {
    cout << Guy + 1 << " ";
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 340 KB Output is correct
6 Correct 1 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 1 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
# 결과 실행 시간 메모리 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 364 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 2 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 212 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 340 KB Output is correct
6 Correct 1 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 1 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 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 364 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 2 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 212 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 29 ms 6364 KB Output is correct
44 Correct 202 ms 46332 KB Output is correct
45 Correct 117 ms 20284 KB Output is correct
46 Correct 16 ms 2332 KB Output is correct
47 Correct 139 ms 29108 KB Output is correct
48 Correct 107 ms 60584 KB Output is correct
49 Correct 45 ms 15156 KB Output is correct
50 Correct 207 ms 76768 KB Output is correct
51 Correct 112 ms 27836 KB Output is correct
52 Correct 218 ms 66136 KB Output is correct
53 Correct 179 ms 58600 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 42 ms 32204 KB Output is correct
56 Correct 159 ms 39408 KB Output is correct
57 Correct 110 ms 33088 KB Output is correct
58 Correct 158 ms 57368 KB Output is correct
59 Correct 129 ms 32332 KB Output is correct
60 Correct 395 ms 100720 KB Output is correct
61 Correct 414 ms 100536 KB Output is correct
62 Correct 392 ms 100252 KB Output is correct
63 Correct 381 ms 100984 KB Output is correct
64 Correct 427 ms 100748 KB Output is correct
65 Correct 311 ms 87260 KB Output is correct
66 Correct 283 ms 87476 KB Output is correct
67 Correct 293 ms 87472 KB Output is correct
68 Correct 141 ms 42656 KB Output is correct
69 Correct 166 ms 40576 KB Output is correct
70 Correct 174 ms 52604 KB Output is correct
71 Correct 252 ms 62992 KB Output is correct