# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
375639 |
2021-03-09T15:54:58 Z |
casperwang |
Naan (JOI19_naan) |
C++14 |
|
859 ms |
148972 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];
arr[i][j] = arr[i][j] + pii(id-1, 1);
break;
} else {
id++;
}
}
}
}
ans[0] = pii(0, 1);
for (int i = 1; i <= n; i++) {
ppi mmin(pii(INF, 0), 0);
for (int j = 1; j <= n; j++) {
if (vis[j]) continue;
assert(arr[j][i] >= ans[i-1]);
if (mmin.ff >= arr[j][i])
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 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
408 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
14 |
Correct |
1 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
2 ms |
492 KB |
Output is correct |
3 |
Correct |
2 ms |
620 KB |
Output is correct |
4 |
Correct |
1 ms |
620 KB |
Output is correct |
5 |
Correct |
1 ms |
620 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
620 KB |
Output is correct |
10 |
Correct |
1 ms |
620 KB |
Output is correct |
11 |
Correct |
1 ms |
620 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
14 |
Correct |
2 ms |
620 KB |
Output is correct |
15 |
Correct |
1 ms |
640 KB |
Output is correct |
16 |
Correct |
1 ms |
620 KB |
Output is correct |
17 |
Correct |
1 ms |
620 KB |
Output is correct |
18 |
Correct |
1 ms |
620 KB |
Output is correct |
19 |
Correct |
2 ms |
620 KB |
Output is correct |
20 |
Correct |
1 ms |
620 KB |
Output is correct |
21 |
Correct |
1 ms |
620 KB |
Output is correct |
22 |
Correct |
2 ms |
620 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
620 KB |
Output is correct |
25 |
Correct |
1 ms |
492 KB |
Output is correct |
26 |
Correct |
1 ms |
492 KB |
Output is correct |
27 |
Correct |
2 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
408 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
14 |
Correct |
1 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
2 ms |
492 KB |
Output is correct |
18 |
Correct |
2 ms |
620 KB |
Output is correct |
19 |
Correct |
1 ms |
620 KB |
Output is correct |
20 |
Correct |
1 ms |
620 KB |
Output is correct |
21 |
Correct |
1 ms |
492 KB |
Output is correct |
22 |
Correct |
1 ms |
492 KB |
Output is correct |
23 |
Correct |
1 ms |
492 KB |
Output is correct |
24 |
Correct |
1 ms |
620 KB |
Output is correct |
25 |
Correct |
1 ms |
620 KB |
Output is correct |
26 |
Correct |
1 ms |
620 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
2 ms |
620 KB |
Output is correct |
30 |
Correct |
1 ms |
640 KB |
Output is correct |
31 |
Correct |
1 ms |
620 KB |
Output is correct |
32 |
Correct |
1 ms |
620 KB |
Output is correct |
33 |
Correct |
1 ms |
620 KB |
Output is correct |
34 |
Correct |
2 ms |
620 KB |
Output is correct |
35 |
Correct |
1 ms |
620 KB |
Output is correct |
36 |
Correct |
1 ms |
620 KB |
Output is correct |
37 |
Correct |
2 ms |
620 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
620 KB |
Output is correct |
40 |
Correct |
1 ms |
492 KB |
Output is correct |
41 |
Correct |
1 ms |
492 KB |
Output is correct |
42 |
Correct |
2 ms |
620 KB |
Output is correct |
43 |
Correct |
117 ms |
17004 KB |
Output is correct |
44 |
Runtime error |
859 ms |
148972 KB |
Execution killed with signal 6 |
45 |
Halted |
0 ms |
0 KB |
- |