# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
201333 | BThero | Naan (JOI19_naan) | C++17 | 7 ms | 504 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Why am I so dumb? :c
// chrono::system_clock::now().time_since_epoch().count()
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pii;
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int MAXN = (int)2e3 + 5;
ll curS[MAXN], limS[MAXN];
ll A[MAXN], B[MAXN];
ll arr[MAXN][MAXN];
int perm[MAXN];
int n, m;
void solve() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
scanf("%lld", &arr[i][j]);
limS[i] += arr[i][j];
arr[i][j] *= n;
}
}
for (int i = 1; i <= n; ++i) {
perm[i] = i;
}
do {
int ptr = 1;
fill(curS + 1, curS + n + 1, 0ll);
bool ok = 1;
for (int i = 1; i <= n; ++i) {
int id = perm[i];
while (ptr <= m && curS[id] < limS[id]) {
curS[id] += arr[id][ptr];
++ptr;
}
if (curS[id] < limS[id] && ptr > m) {
ok = 0;
break;
}
int nx = perm[id + 1];
curS[nx] += arr[nx][ptr - 1] * (curS[id] - limS[id]) / arr[id][ptr - 1];
A[i] = ptr - 1;
B[i] = 1;
}
if (ok) {
for (int i = 1; i < n; ++i) {
printf("%lld %lld\n", A[i], B[i]);
}
for (int i = 1; i <= n; ++i) {
printf("%d ", perm[i]);
}
printf("\n");
return;
}
}
while (next_permutation(perm + 1, perm + n + 1));
printf("-1\n");
}
int main() {
int tt = 1;
while (tt--) {
solve();
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |