#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l) == r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
const int MAX_N = 2005;
int n, L;
int v[MAX_N][MAX_N];
struct frac {
ll up, dn;
void ref() { ll g = gcd(up, dn); up/=g, dn/=g; }
frac(ll a, ll b) :
up(a), dn(b) {}
frac(ll v) :
up(v), dn(1) {}
void sca(ll v) { up *= v, dn *= v; }
};
frac operator * (frac a, frac b) { a.up *= b.up, a.dn *= b.dn, a.ref(); return a; }
frac operator * (frac a, ll v) { a.up *= v; return a; }
frac operator / (frac a, ll v) { a.dn *= v; return a; }
frac operator + (frac a, frac b) {
ll da = a.dn, db = b.dn, nd = da / gcd(da, db) * db;
a.sca(nd/da), b.sca(nd/db);
a.up += b.up;
return a;
}
frac operator - (frac a, frac b) {
ll da = a.dn, db = b.dn, nd = da / gcd(da, db) * db;
a.sca(nd/da), b.sca(nd/db);
a.up -= b.up;
return a;
}
frac& operator += (frac &a, frac b) { return a = a + b; }
frac& operator -= (frac &a, frac b) { return a = a - b; }
bool operator < (frac a, frac b) { return a.up * b.dn < b.up * a.dn; }
bool operator > (frac a, frac b) { return a.up * b.dn > b.up * a.dn; }
ostream& operator << (ostream& out, frac a) { return out << a.up << ' ' << a.dn; }
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> L;
for (int i = 0;i < n;++i)
for (int j = 0;j < L;++j)
cin >> v[i][j];
if (n > 6) return -1;
vector<int> od(n); iota(AI(od), 0);
do {
// gen
bool ok = true;
vector<frac> sep {{0, 1}};
debug(AI(od));
for (int x : od) {
int sum = 0;
for (int j = 0;j < L;++j)
sum += v[x][j];
auto [up, dn] = sep.back();
int atid = up / dn, lft = dn - up % dn;
DE(x, atid, lft, dn);
frac need{sum, n};
if (frac(lft, dn) * v[x][atid] > need) {
frac len = need / v[x][atid];
sep.pb(len + sep.back());
continue;
}
need -= frac(lft, dn) * v[x][atid];
++atid;
while (atid < L) {
if (need < v[x][atid]) break;
need -= v[x][atid++];
}
if (atid == L && need > frac(0)) {
ok = false;
break;
}
sep.pb( frac(atid) + need / v[x][atid] );
DE(sep.back());
}
if (!ok) continue;
for (auto s : sep)
cout << s << '\n';
for (int i = 0;i < n;++i)
cout << od[i]+1 << " \n"[i+1==n];
return 0;
} while (next_permutation(AI(od)));
cout << -1 << '\n';
}
Compilation message
naan.cpp: In function 'int32_t main()':
naan.cpp:15:20: warning: statement has no effect [-Wunused-value]
15 | #define debug(...) 0
| ^
naan.cpp:70:3: note: in expansion of macro 'debug'
70 | debug(AI(od));
| ^~~~~
naan.cpp:14:17: warning: statement has no effect [-Wunused-value]
14 | #define DE(...) 0
| ^
naan.cpp:79:4: note: in expansion of macro 'DE'
79 | DE(x, atid, lft, dn);
| ^~
naan.cpp:14:17: warning: statement has no effect [-Wunused-value]
14 | #define DE(...) 0
| ^
naan.cpp:99:4: note: in expansion of macro 'DE'
99 | DE(sep.back());
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Integer parameter [name=A_i] equals to 0, violates the range [1, 2000000000000] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Integer parameter [name=A_i] equals to 0, violates the range [1, 2000000000000] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Integer parameter [name=A_i] equals to 0, violates the range [1, 2000000000000] |
2 |
Halted |
0 ms |
0 KB |
- |