답안 #958943

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
958943 2024-04-07T08:37:23 Z Tuanlinh123 Naan (JOI19_naan) C++17
100 / 100
1160 ms 117044 KB
#include<bits/stdc++.h>
#define i128 __int128_t
#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 (i128)x*o.y>=(i128)y*o.x;}
    bool operator <= (const frac &o) const {return (i128)x*o.y<=(i128)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]) continue;
            if (f[i][z]<Min.fi) Min={f[i][z], i};
        }
        if (!Min.se) {cout << "-1"; exit(0);}
        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 << " ";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 63324 KB Output is correct
2 Correct 12 ms 63324 KB Output is correct
3 Correct 12 ms 63324 KB Output is correct
4 Correct 12 ms 63324 KB Output is correct
5 Correct 12 ms 63324 KB Output is correct
6 Correct 12 ms 63320 KB Output is correct
7 Correct 12 ms 63324 KB Output is correct
8 Correct 12 ms 63400 KB Output is correct
9 Correct 13 ms 63324 KB Output is correct
10 Correct 14 ms 63228 KB Output is correct
11 Correct 13 ms 63324 KB Output is correct
12 Correct 13 ms 63264 KB Output is correct
13 Correct 14 ms 63324 KB Output is correct
14 Correct 15 ms 63576 KB Output is correct
15 Correct 14 ms 63324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 63324 KB Output is correct
2 Correct 13 ms 63324 KB Output is correct
3 Correct 13 ms 63320 KB Output is correct
4 Correct 12 ms 63324 KB Output is correct
5 Correct 14 ms 63320 KB Output is correct
6 Correct 13 ms 63324 KB Output is correct
7 Correct 14 ms 63212 KB Output is correct
8 Correct 13 ms 63320 KB Output is correct
9 Correct 12 ms 63324 KB Output is correct
10 Correct 14 ms 63396 KB Output is correct
11 Correct 14 ms 63324 KB Output is correct
12 Correct 13 ms 63320 KB Output is correct
13 Correct 12 ms 63324 KB Output is correct
14 Correct 11 ms 63324 KB Output is correct
15 Correct 12 ms 63432 KB Output is correct
16 Correct 13 ms 63320 KB Output is correct
17 Correct 11 ms 63320 KB Output is correct
18 Correct 12 ms 63324 KB Output is correct
19 Correct 11 ms 63324 KB Output is correct
20 Correct 13 ms 63324 KB Output is correct
21 Correct 14 ms 63492 KB Output is correct
22 Correct 13 ms 63324 KB Output is correct
23 Correct 14 ms 63324 KB Output is correct
24 Correct 12 ms 63324 KB Output is correct
25 Correct 12 ms 63324 KB Output is correct
26 Correct 13 ms 63400 KB Output is correct
27 Correct 13 ms 63324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 63324 KB Output is correct
2 Correct 12 ms 63324 KB Output is correct
3 Correct 12 ms 63324 KB Output is correct
4 Correct 12 ms 63324 KB Output is correct
5 Correct 12 ms 63324 KB Output is correct
6 Correct 12 ms 63320 KB Output is correct
7 Correct 12 ms 63324 KB Output is correct
8 Correct 12 ms 63400 KB Output is correct
9 Correct 13 ms 63324 KB Output is correct
10 Correct 14 ms 63228 KB Output is correct
11 Correct 13 ms 63324 KB Output is correct
12 Correct 13 ms 63264 KB Output is correct
13 Correct 14 ms 63324 KB Output is correct
14 Correct 15 ms 63576 KB Output is correct
15 Correct 14 ms 63324 KB Output is correct
16 Correct 13 ms 63324 KB Output is correct
17 Correct 13 ms 63324 KB Output is correct
18 Correct 13 ms 63320 KB Output is correct
19 Correct 12 ms 63324 KB Output is correct
20 Correct 14 ms 63320 KB Output is correct
21 Correct 13 ms 63324 KB Output is correct
22 Correct 14 ms 63212 KB Output is correct
23 Correct 13 ms 63320 KB Output is correct
24 Correct 12 ms 63324 KB Output is correct
25 Correct 14 ms 63396 KB Output is correct
26 Correct 14 ms 63324 KB Output is correct
27 Correct 13 ms 63320 KB Output is correct
28 Correct 12 ms 63324 KB Output is correct
29 Correct 11 ms 63324 KB Output is correct
30 Correct 12 ms 63432 KB Output is correct
31 Correct 13 ms 63320 KB Output is correct
32 Correct 11 ms 63320 KB Output is correct
33 Correct 12 ms 63324 KB Output is correct
34 Correct 11 ms 63324 KB Output is correct
35 Correct 13 ms 63324 KB Output is correct
36 Correct 14 ms 63492 KB Output is correct
37 Correct 13 ms 63324 KB Output is correct
38 Correct 14 ms 63324 KB Output is correct
39 Correct 12 ms 63324 KB Output is correct
40 Correct 12 ms 63324 KB Output is correct
41 Correct 13 ms 63400 KB Output is correct
42 Correct 13 ms 63324 KB Output is correct
43 Correct 107 ms 67924 KB Output is correct
44 Correct 581 ms 87028 KB Output is correct
45 Correct 205 ms 81492 KB Output is correct
46 Correct 29 ms 66388 KB Output is correct
47 Correct 340 ms 86808 KB Output is correct
48 Correct 843 ms 79676 KB Output is correct
49 Correct 192 ms 71868 KB Output is correct
50 Correct 1000 ms 96716 KB Output is correct
51 Correct 337 ms 83392 KB Output is correct
52 Correct 815 ms 97448 KB Output is correct
53 Correct 761 ms 92664 KB Output is correct
54 Correct 11 ms 63320 KB Output is correct
55 Correct 416 ms 70556 KB Output is correct
56 Correct 447 ms 87892 KB Output is correct
57 Correct 381 ms 84672 KB Output is correct
58 Correct 691 ms 89396 KB Output is correct
59 Correct 381 ms 84972 KB Output is correct
60 Correct 962 ms 116920 KB Output is correct
61 Correct 1020 ms 116608 KB Output is correct
62 Correct 1160 ms 117044 KB Output is correct
63 Correct 1086 ms 116540 KB Output is correct
64 Correct 1027 ms 116820 KB Output is correct
65 Correct 1084 ms 103296 KB Output is correct
66 Correct 1065 ms 103464 KB Output is correct
67 Correct 975 ms 103324 KB Output is correct
68 Correct 418 ms 88080 KB Output is correct
69 Correct 383 ms 90548 KB Output is correct
70 Correct 527 ms 89972 KB Output is correct
71 Correct 621 ms 99428 KB Output is correct