# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
958942 |
2024-04-07T08:32:08 Z |
Tuanlinh123 |
Naan (JOI19_naan) |
C++17 |
|
108 ms |
130896 KB |
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
#define sz(a) ((ll)(a).size())
using namespace std;
struct frac
{
ll x=0, y=1;
frac(){}
frac(ll x): x(x), y(1) {}
frac(ll x, ll y): x(x), y(y){}
frac operator + (const frac &o) const
{
frac ans={x*o.y+y*o.x, y*o.y};
ll g=__gcd(ans.x, ans.y);
ans.x/=g, ans.y/=g;
return ans;
}
frac operator - (const frac &o) const
{
frac ans={x*o.y-y*o.x, y*o.y};
ll g=__gcd(ans.x, ans.y);
ans.x/=g, ans.y/=g;
return ans;
}
frac operator / (const ll &v) const
{
ll g=__gcd(x, v);
frac ans={x/g, v/g*y};
return ans;
}
frac operator * (const frac& o) const
{
frac ans={x*o.x, y*o.y};
ll g=__gcd(ans.x, ans.y);
ans.x/=g, ans.y/=g;
return ans;
}
bool operator >= (const frac &o) const {return x*o.y>=y*o.x;}
bool operator <= (const frac &o) const {return x*o.y<=y*o.x;}
bool operator < (const frac &o) const {return !(*this>=o);}
bool operator > (const frac &o) const {return !(*this<=o);}
};
const ll maxn=2005, inf=1e9;
ll v[maxn][maxn];
frac f[maxn][maxn];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll n, m; cin >> n >> m;
for (ll i=1; i<=n; i++)
{
for (ll j=1; j<=m; j++)
cin >> v[i][j], v[i][j]+=v[i][j-1];
for (ll j=1; j<=n; j++)
{
frac t(v[i][m]*j, n);
ll lo=1, hi=m;
while (hi>lo)
{
ll mid=(lo+hi)/2;
if (frac(v[i][mid])>=t)
hi=mid;
else lo=mid+1;
}
t=t-frac(v[i][lo-1]);
f[i][j]=frac(lo-1)+t/(v[i][lo]-v[i][lo-1]);
assert(f[i][j]>f[i][j-1]);
}
}
vector <bool> used(n+1, 0);
frac crr;
vector <pll> res;
vector <ll> ans;
for (ll z=1; z<=n; z++)
{
pair<frac, ll> Min;
Min.fi=frac(inf), Min.se=0;
for (ll i=1; i<=n; i++)
{
if (used[i] || f[i][z]<crr) continue;
if (f[i][z]<Min.fi) Min={f[i][z], i};
}
if (!Min.se) {cout << "-1"; exit(0);}
assert(crr<Min.fi);
crr=Min.fi, used[Min.se]=1;
res.pb({crr.x, crr.y});
ans.pb(Min.se);
}
res.resize(n-1);
for (pll i:res) cout << i.fi << " " << i.se << "\n";
for (ll i:ans) cout << i << " ";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
63536 KB |
Output is correct |
2 |
Correct |
16 ms |
63324 KB |
Output is correct |
3 |
Correct |
15 ms |
63324 KB |
Output is correct |
4 |
Correct |
15 ms |
63324 KB |
Output is correct |
5 |
Correct |
16 ms |
63252 KB |
Output is correct |
6 |
Correct |
15 ms |
63320 KB |
Output is correct |
7 |
Correct |
16 ms |
63320 KB |
Output is correct |
8 |
Correct |
17 ms |
63324 KB |
Output is correct |
9 |
Correct |
18 ms |
63324 KB |
Output is correct |
10 |
Correct |
18 ms |
63324 KB |
Output is correct |
11 |
Correct |
22 ms |
63576 KB |
Output is correct |
12 |
Correct |
17 ms |
63324 KB |
Output is correct |
13 |
Correct |
17 ms |
63324 KB |
Output is correct |
14 |
Correct |
17 ms |
63324 KB |
Output is correct |
15 |
Correct |
18 ms |
63324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
63576 KB |
Output is correct |
2 |
Correct |
17 ms |
63320 KB |
Output is correct |
3 |
Correct |
17 ms |
63324 KB |
Output is correct |
4 |
Correct |
18 ms |
63320 KB |
Output is correct |
5 |
Correct |
19 ms |
63428 KB |
Output is correct |
6 |
Correct |
16 ms |
63404 KB |
Output is correct |
7 |
Correct |
16 ms |
63324 KB |
Output is correct |
8 |
Correct |
17 ms |
63324 KB |
Output is correct |
9 |
Correct |
17 ms |
63524 KB |
Output is correct |
10 |
Correct |
18 ms |
63324 KB |
Output is correct |
11 |
Correct |
17 ms |
63324 KB |
Output is correct |
12 |
Correct |
16 ms |
63324 KB |
Output is correct |
13 |
Correct |
16 ms |
63324 KB |
Output is correct |
14 |
Correct |
16 ms |
63324 KB |
Output is correct |
15 |
Correct |
16 ms |
63412 KB |
Output is correct |
16 |
Correct |
15 ms |
63324 KB |
Output is correct |
17 |
Correct |
15 ms |
63324 KB |
Output is correct |
18 |
Correct |
16 ms |
63484 KB |
Output is correct |
19 |
Correct |
16 ms |
63324 KB |
Output is correct |
20 |
Correct |
16 ms |
63312 KB |
Output is correct |
21 |
Correct |
18 ms |
63320 KB |
Output is correct |
22 |
Correct |
16 ms |
63324 KB |
Output is correct |
23 |
Correct |
16 ms |
63324 KB |
Output is correct |
24 |
Correct |
18 ms |
63324 KB |
Output is correct |
25 |
Correct |
17 ms |
63324 KB |
Output is correct |
26 |
Correct |
17 ms |
63404 KB |
Output is correct |
27 |
Correct |
17 ms |
63324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
63536 KB |
Output is correct |
2 |
Correct |
16 ms |
63324 KB |
Output is correct |
3 |
Correct |
15 ms |
63324 KB |
Output is correct |
4 |
Correct |
15 ms |
63324 KB |
Output is correct |
5 |
Correct |
16 ms |
63252 KB |
Output is correct |
6 |
Correct |
15 ms |
63320 KB |
Output is correct |
7 |
Correct |
16 ms |
63320 KB |
Output is correct |
8 |
Correct |
17 ms |
63324 KB |
Output is correct |
9 |
Correct |
18 ms |
63324 KB |
Output is correct |
10 |
Correct |
18 ms |
63324 KB |
Output is correct |
11 |
Correct |
22 ms |
63576 KB |
Output is correct |
12 |
Correct |
17 ms |
63324 KB |
Output is correct |
13 |
Correct |
17 ms |
63324 KB |
Output is correct |
14 |
Correct |
17 ms |
63324 KB |
Output is correct |
15 |
Correct |
18 ms |
63324 KB |
Output is correct |
16 |
Correct |
17 ms |
63576 KB |
Output is correct |
17 |
Correct |
17 ms |
63320 KB |
Output is correct |
18 |
Correct |
17 ms |
63324 KB |
Output is correct |
19 |
Correct |
18 ms |
63320 KB |
Output is correct |
20 |
Correct |
19 ms |
63428 KB |
Output is correct |
21 |
Correct |
16 ms |
63404 KB |
Output is correct |
22 |
Correct |
16 ms |
63324 KB |
Output is correct |
23 |
Correct |
17 ms |
63324 KB |
Output is correct |
24 |
Correct |
17 ms |
63524 KB |
Output is correct |
25 |
Correct |
18 ms |
63324 KB |
Output is correct |
26 |
Correct |
17 ms |
63324 KB |
Output is correct |
27 |
Correct |
16 ms |
63324 KB |
Output is correct |
28 |
Correct |
16 ms |
63324 KB |
Output is correct |
29 |
Correct |
16 ms |
63324 KB |
Output is correct |
30 |
Correct |
16 ms |
63412 KB |
Output is correct |
31 |
Correct |
15 ms |
63324 KB |
Output is correct |
32 |
Correct |
15 ms |
63324 KB |
Output is correct |
33 |
Correct |
16 ms |
63484 KB |
Output is correct |
34 |
Correct |
16 ms |
63324 KB |
Output is correct |
35 |
Correct |
16 ms |
63312 KB |
Output is correct |
36 |
Correct |
18 ms |
63320 KB |
Output is correct |
37 |
Correct |
16 ms |
63324 KB |
Output is correct |
38 |
Correct |
16 ms |
63324 KB |
Output is correct |
39 |
Correct |
18 ms |
63324 KB |
Output is correct |
40 |
Correct |
17 ms |
63324 KB |
Output is correct |
41 |
Correct |
17 ms |
63404 KB |
Output is correct |
42 |
Correct |
17 ms |
63324 KB |
Output is correct |
43 |
Correct |
108 ms |
68744 KB |
Output is correct |
44 |
Runtime error |
106 ms |
130896 KB |
Execution killed with signal 6 |
45 |
Halted |
0 ms |
0 KB |
- |