# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
684675 |
2023-01-22T10:10:29 Z |
peijar |
Naan (JOI19_naan) |
C++17 |
|
1623 ms |
58996 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 p * other.q < 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];
}
dbg(i);
for (auto [p, q] : cuts[i])
dbg(p, q);
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;
}
Compilation message
naan.cpp: In function 'int main()':
naan.cpp:94:15: warning: structured binding declaration set but not used [-Wunused-but-set-variable]
94 | for (auto [p, q] : cuts[i])
| ^~~~~~
# |
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 |
384 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 |
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 |
392 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 |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
428 KB |
Output is correct |
11 |
Correct |
2 ms |
400 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
336 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
3 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
3 ms |
460 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 |
340 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 |
384 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 |
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 |
392 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 |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
3 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
324 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
3 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
428 KB |
Output is correct |
26 |
Correct |
2 ms |
400 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
336 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
340 KB |
Output is correct |
34 |
Correct |
3 ms |
340 KB |
Output is correct |
35 |
Correct |
2 ms |
340 KB |
Output is correct |
36 |
Correct |
3 ms |
460 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 |
340 KB |
Output is correct |
43 |
Correct |
263 ms |
11208 KB |
Output is correct |
44 |
Incorrect |
1623 ms |
58996 KB |
X_i is not increasing |
45 |
Halted |
0 ms |
0 KB |
- |