# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
684678 |
2023-01-22T10:17:11 Z |
peijar |
Naan (JOI19_naan) |
C++17 |
|
3437 ms |
118012 KB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
string to_string(string s) { return s; }
template <typename T> string to_string(T v) {
bool first = true;
string res = "[";
for (const auto &x : v) {
if (!first)
res += ", ";
first = false;
res += to_string(x);
}
res += "]";
return res;
}
void dbg_out() { cout << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
cout << ' ' << to_string(H);
dbg_out(T...);
}
#ifdef DEBUG
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
struct Rational {
int p, q;
Rational() : p(0), q(1) {}
Rational(int _p, int _q) : p(_p), q(_q) {
int d = gcd(p, q);
p /= d, q /= d;
}
Rational(int x) : p(x), q(1) {}
Rational operator+(Rational other) const {
return Rational(p * other.q + other.p * q, other.q * q);
}
Rational operator-(Rational other) const {
return Rational(p * other.q - q * other.p, other.q * q);
}
Rational operator*(Rational other) const {
return Rational(p * other.p, q * other.q);
}
Rational operator/(Rational other) const {
return Rational(p * other.q, q * other.p);
}
bool operator<(Rational other) const {
return (__int128)p * other.q < (__int128)q * other.p;
}
bool operator<=(Rational other) const { return !(other < *this); }
};
signed main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
int nbPersonnes, tailleGateau;
cin >> nbPersonnes >> tailleGateau;
vector<vector<int>> gain(nbPersonnes, vector<int>(tailleGateau));
for (int i = 0; i < nbPersonnes; ++i)
for (int j = 0; j < tailleGateau; ++j)
cin >> gain[i][j];
vector<Rational> need(nbPersonnes);
for (int i = 0; i < nbPersonnes; ++i) {
for (int j = 0; j < tailleGateau; ++j)
need[i] = need[i] + gain[i][j];
need[i] = need[i] / nbPersonnes;
}
vector<vector<Rational>> cuts(nbPersonnes);
for (int i = 0; i < nbPersonnes; ++i) {
Rational rat;
for (int j = 0; j < tailleGateau; ++j) {
Rational taken(0);
while (need[i] <= Rational(gain[i][j]) * (Rational(1) - taken) + rat) {
Rational x = (need[i] - rat + taken * gain[i][j]) / gain[i][j];
cuts[i].push_back(Rational(j) + x);
taken = x;
rat = 0;
}
rat = rat + (Rational(1) - taken) * gain[i][j];
}
assert((int)cuts[i].size() == nbPersonnes);
}
vector<int> perm;
vector<bool> used(nbPersonnes);
for (int i = 0; i < nbPersonnes; ++i) {
int first = -1;
for (int j = 0; j < nbPersonnes; ++j)
if (!used[j] and (first == -1 or cuts[j][i] < cuts[first][i]))
first = j;
perm.push_back(first);
used[first] = true;
}
for (int i = 0; i < nbPersonnes - 1; ++i) {
auto [p, q] = cuts[perm[i]][i];
cout << p << ' ' << q << '\n';
}
for (int x : perm)
cout << x + 1 << ' ';
cout << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
224 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 |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
2 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 |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
292 KB |
Output is correct |
13 |
Correct |
1 ms |
368 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
400 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
3 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
428 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
3 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 |
2 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 |
408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
224 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 |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
2 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 |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
292 KB |
Output is correct |
28 |
Correct |
1 ms |
368 KB |
Output is correct |
29 |
Correct |
2 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
400 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
340 KB |
Output is correct |
33 |
Correct |
2 ms |
340 KB |
Output is correct |
34 |
Correct |
2 ms |
428 KB |
Output is correct |
35 |
Correct |
2 ms |
340 KB |
Output is correct |
36 |
Correct |
3 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 |
2 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 |
408 KB |
Output is correct |
43 |
Correct |
264 ms |
9560 KB |
Output is correct |
44 |
Correct |
1621 ms |
48872 KB |
Output is correct |
45 |
Correct |
599 ms |
28108 KB |
Output is correct |
46 |
Correct |
52 ms |
3160 KB |
Output is correct |
47 |
Correct |
1012 ms |
35364 KB |
Output is correct |
48 |
Correct |
2245 ms |
69244 KB |
Output is correct |
49 |
Correct |
475 ms |
19236 KB |
Output is correct |
50 |
Correct |
2781 ms |
89208 KB |
Output is correct |
51 |
Correct |
1014 ms |
38876 KB |
Output is correct |
52 |
Correct |
2353 ms |
85952 KB |
Output is correct |
53 |
Correct |
2110 ms |
74212 KB |
Output is correct |
54 |
Correct |
2 ms |
340 KB |
Output is correct |
55 |
Correct |
1002 ms |
38592 KB |
Output is correct |
56 |
Correct |
1361 ms |
53380 KB |
Output is correct |
57 |
Correct |
1095 ms |
44636 KB |
Output is correct |
58 |
Correct |
1901 ms |
72056 KB |
Output is correct |
59 |
Correct |
1165 ms |
45016 KB |
Output is correct |
60 |
Correct |
2659 ms |
117772 KB |
Output is correct |
61 |
Correct |
2813 ms |
117864 KB |
Output is correct |
62 |
Correct |
3437 ms |
117508 KB |
Output is correct |
63 |
Correct |
3269 ms |
118012 KB |
Output is correct |
64 |
Correct |
2714 ms |
117940 KB |
Output is correct |
65 |
Correct |
3211 ms |
104628 KB |
Output is correct |
66 |
Correct |
3043 ms |
104688 KB |
Output is correct |
67 |
Correct |
2678 ms |
104620 KB |
Output is correct |
68 |
Correct |
1271 ms |
54532 KB |
Output is correct |
69 |
Correct |
1203 ms |
54040 KB |
Output is correct |
70 |
Correct |
1589 ms |
65824 KB |
Output is correct |
71 |
Correct |
1976 ms |
81396 KB |
Output is correct |