# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
375472 |
2021-03-09T12:57:24 Z |
casperwang |
Naan (JOI19_naan) |
C++14 |
|
452 ms |
39048 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 = 1e4;
const double eps = 1e-4;
int n, L;
int v[MAXN+1][MAXN+1];
int sum[MAXN+1];
bool vis[MAXN+1];
int p[MAXN+1];
pii ans[MAXN];
pii now[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 - (int a, pii b) {
return pii(a * b.ss - b.ff, b.ss);
}
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 + (int a, pii b) {
return pii(b.ff + a * b.ss, b.ss);
}
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;
}
pii ceil(pii a) {
int k = (a.ff + a.ss - 1) / a.ss;
return pii(k, 1);
}
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];
sum[i] += v[i][j];
}
now[i] = pii(0, 1);
}
for (int i = 1; i <= n; i++) {
ppi mmin(pii(INF, 1), 0);
for (int j = 1; j <= n; j++) {
if (vis[j]) continue;
pii s(0, 1), k(sum[j] / __gcd(sum[j], n), n / __gcd(sum[j], n));
int id = now[j].ff / now[j].ss + 1;
if ((id - now[j]) * v[j][id] >= k) {
pii tmp = now[j] + (k / v[j][id]);
now[j] = tmp;
if (mmin.ff >= tmp)
mmin = ppi(tmp, j);
} else {
s = s + (id - now[j]) * v[j][id];
id++;
while (id <= L) {
if (v[j][id] + s >= k) {
pii tmp = (id - 1) + ((k - s) / v[j][id]);
now[j] = tmp;
if (mmin.ff >= tmp)
mmin = ppi(tmp, j);
break;
} else {
s = v[j][id] + s;
id++;
}
}
}
}
p[i] = mmin.ss;
vis[mmin.ss] = true;
if (i < n) {
assert(mmin.ff >= ans[i-1]);
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 |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 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 |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 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 |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
2 ms |
492 KB |
Output is correct |
19 |
Correct |
2 ms |
492 KB |
Output is correct |
20 |
Correct |
2 ms |
492 KB |
Output is correct |
21 |
Correct |
1 ms |
492 KB |
Output is correct |
22 |
Correct |
2 ms |
492 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
492 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
492 KB |
Output is correct |
20 |
Correct |
1 ms |
492 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
492 KB |
Output is correct |
25 |
Correct |
1 ms |
492 KB |
Output is correct |
26 |
Correct |
1 ms |
492 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
492 KB |
Output is correct |
30 |
Correct |
1 ms |
492 KB |
Output is correct |
31 |
Correct |
1 ms |
492 KB |
Output is correct |
32 |
Correct |
1 ms |
492 KB |
Output is correct |
33 |
Correct |
2 ms |
492 KB |
Output is correct |
34 |
Correct |
2 ms |
492 KB |
Output is correct |
35 |
Correct |
2 ms |
492 KB |
Output is correct |
36 |
Correct |
1 ms |
492 KB |
Output is correct |
37 |
Correct |
2 ms |
492 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
492 KB |
Output is correct |
40 |
Correct |
1 ms |
364 KB |
Output is correct |
41 |
Correct |
1 ms |
364 KB |
Output is correct |
42 |
Correct |
1 ms |
492 KB |
Output is correct |
43 |
Correct |
91 ms |
4752 KB |
Output is correct |
44 |
Runtime error |
452 ms |
39048 KB |
Execution killed with signal 6 |
45 |
Halted |
0 ms |
0 KB |
- |