# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
375437 |
2021-03-09T11:45:52 Z |
casperwang |
Naan (JOI19_naan) |
C++14 |
|
170 ms |
5868 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 = 1e5;
const double eps = 1e-9;
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(0, 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;
}
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];
}
}
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.ff / now.ss + 1;
if ((id - now) * v[j][id] + s >= k) {
pii tmp = now + ((k - s) / v[j][id]);
if (mmin.ff >= tmp)
mmin = ppi(tmp, j);
} else {
s = s + (id - now) * v[j][id];
id++;
while (id <= L) {
if (v[j][id] + s >= k) {
pii tmp = (id - 1) + ((k - s) / v[j][id]);
if (mmin.ff >= tmp)
mmin = ppi(tmp, j);
break;
} else {
s = v[j][id] + s;
id++;
}
}
}
}
p[i] = mmin.ss;
vis[mmin.ss] = true;
now = mmin.ff;
if (i < n)
ans[i] = now;
}
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 |
0 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 |
2 ms |
640 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 |
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 |
2 ms |
492 KB |
Output is correct |
22 |
Correct |
1 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 |
492 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 |
0 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 |
2 ms |
640 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 |
1 ms |
492 KB |
Output is correct |
34 |
Correct |
1 ms |
492 KB |
Output is correct |
35 |
Correct |
1 ms |
492 KB |
Output is correct |
36 |
Correct |
2 ms |
492 KB |
Output is correct |
37 |
Correct |
1 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 |
492 KB |
Output is correct |
41 |
Correct |
1 ms |
364 KB |
Output is correct |
42 |
Correct |
1 ms |
492 KB |
Output is correct |
43 |
Incorrect |
170 ms |
5868 KB |
Expected int32, but "828144992439" found |
44 |
Halted |
0 ms |
0 KB |
- |