#include <bits/extc++.h>
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
const double eps = 1e-11;
ll N, L, v[8][20], sum[8];
int abtodc(int a, int b, int c)
{
return (b * c + a - 1) / a;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> N >> L;
// why divide by N?
// how to solve using only fractions?
// is it guarnteed to always have a solution?
for (int i = 1; i <= N; i++)
{
for (int j = 1; j <= L; j++)
{
cin >> v[i][j];
// sum >= sum of v / N
// sum * N >= sum of v
sum[i] += v[i][j];
v[i][j] *= N;
}
}
vector<int> p;
for (int i = 1; i <= N; i++)
p.emplace_back(i);
do
{
pii last = {0, 1};
int nxt = 1;
vector<pii> sol;
for (auto i : p)
{
ll tmp = sum[i];
while (nxt <= L && tmp >= v[i][nxt] - abtodc(last.S, last.F, v[i][nxt]))
tmp -= v[i][nxt] - abtodc(last.S, last.F, v[i][nxt]), last = {0, 1}, nxt++;
last = {abtodc(last.S, last.F, v[i][nxt]), v[i][nxt]};
last.F += tmp;
if (last.F + (nxt - 1) * last.S > L * last.S)
goto ono;
sol.emplace_back(pii{last.F + last.S * (nxt - 1), last.S});
}
sol.pop_back();
for (auto [a, b] : sol)
cout << a << ' ' << b << '\n';
for (auto i : p)
cout << i << ' ';
cout << '\n';
return 0;
ono:
continue;
} while (next_permutation(p.begin(), p.end()));
}
Compilation message
naan.cpp: In function 'int main()':
naan.cpp:58:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
58 | for (auto [a, b] : sol)
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Unexpected end of file - int64 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |