# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
375629 |
2021-03-09T15:44:38 Z |
casperwang |
Naan (JOI19_naan) |
C++14 |
|
1 ms |
492 KB |
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define ppi pair<pii,int>
#define ff first
#define ss second
using namespace std;
#define debug(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 pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }
const int MAXN = 2000;
const int INF = 1e9;
int n, L;
int v[MAXN+1][MAXN+1];
int pre[MAXN+1][MAXN+1];
int sum[MAXN+1];
pii arr[MAXN+1][MAXN+1];
bool vis[MAXN+1];
pii ans[MAXN];
int p[MAXN+1];
pii operator - (pii a, pii b) {
int k = a.ss / __gcd(a.ss, b.ss) * b.ss;
int c = __gcd(a.ff * (k / a.ss) - b.ff * (k / b.ss), k);
return pii((a.ff * (k / a.ss) - b.ff * (k / b.ss)) / c, k / c);
}
pii operator + (pii a, pii b) {
int k = a.ss / __gcd(a.ss, b.ss) * b.ss;
int c = __gcd(a.ff * (k / a.ss) + b.ff * (k / b.ss), k);
return pii((a.ff * (k / a.ss) + b.ff * (k / b.ss)) / c, k / c);
}
pii operator * (pii a, int b) {
int k = __gcd(a.ss, b);
return pii(a.ff * b / k, a.ss / k);
}
pii operator / (pii a, int b) {
int k = __gcd(a.ff, b);
return pii(a.ff / k, a.ss * b / k);
}
bool operator >= (pii a, pii b) {
return a.ff * b.ss >= b.ff * a.ss;
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> L;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= L; j++) {
cin >> v[i][j];
pre[i][j] = pre[i][j-1] + v[i][j];
sum[i] += v[i][j];
}
}
for (int i = 1; i <= n; i++) {
int id = 1;
for (int j = 1; j <= n; j++) {
pii k(sum[i] * j, n);
while (true) {
if (pii(pre[i][id], 1) >= k) {
arr[i][j] = (k - pii(pre[i][id-1], 1)) / v[i][id];
break;
} else {
id++;
}
}
}
}
for (int i = 1; i <= n; i++) {
ppi mmin(pii(INF, 0), 0);
for (int j = 1; j <= n; j++) {
if (vis[j]) continue;
mmin = min(mmin, ppi(arr[j][i], j));
}
vis[mmin.ss] = true;
p[i] = mmin.ss;
if (i < n)
ans[i] = mmin.ff;
}
for (int i = 1; i < n; i++)
cout << ans[i].ff << ' ' << ans[i].ss << '\n';
for (int i = 1; i <= n; i++)
cout << p[i] << " \n"[i==n];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Not a fair distribution. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
492 KB |
Not a fair distribution. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Not a fair distribution. |
2 |
Halted |
0 ms |
0 KB |
- |