Submission #958939

# Submission time Handle Problem Language Result Execution time Memory
958939 2024-04-07T08:18:25 Z Tuanlinh123 Naan (JOI19_naan) C++17
29 / 100
563 ms 96664 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;
    }
};

const ll maxn=2005;
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]);
        }
    }
    vector <bool> used(n+1, 0);
    frac crr;
    vector <pll> res;
    vector <ll> ans;
    for (ll z=1; z<=n; z++)
    {
        pair<frac, ll> Max; Max.se=0;
        for (ll i=1; i<=n; i++)
        {
            if (used[i]) continue;
            if (f[i][z]<=frac(m))
                if (!Max.se || !(f[i][z]>=Max.fi)) 
                    Max={f[i][z], i};
        }
        if (!Max.se) {cout << "-1"; exit(0);}
        crr=Max.fi, used[Max.se]=1;
        res.pb({crr.x, crr.y});
        ans.pb(Max.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 25 ms 64084 KB Output is correct
2 Correct 11 ms 64088 KB Output is correct
3 Correct 11 ms 64092 KB Output is correct
4 Correct 13 ms 64344 KB Output is correct
5 Correct 12 ms 64208 KB Output is correct
6 Correct 11 ms 64088 KB Output is correct
7 Correct 11 ms 64092 KB Output is correct
8 Correct 11 ms 64092 KB Output is correct
9 Correct 10 ms 64116 KB Output is correct
10 Correct 10 ms 64092 KB Output is correct
11 Correct 10 ms 64104 KB Output is correct
12 Correct 10 ms 64092 KB Output is correct
13 Correct 12 ms 64092 KB Output is correct
14 Correct 10 ms 64088 KB Output is correct
15 Correct 12 ms 64092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 64092 KB Output is correct
2 Correct 11 ms 64092 KB Output is correct
3 Correct 10 ms 64128 KB Output is correct
4 Correct 10 ms 64176 KB Output is correct
5 Correct 10 ms 64092 KB Output is correct
6 Correct 10 ms 64108 KB Output is correct
7 Correct 11 ms 64092 KB Output is correct
8 Correct 10 ms 64148 KB Output is correct
9 Correct 11 ms 64092 KB Output is correct
10 Correct 11 ms 64092 KB Output is correct
11 Correct 10 ms 64088 KB Output is correct
12 Correct 10 ms 64092 KB Output is correct
13 Correct 10 ms 64088 KB Output is correct
14 Correct 11 ms 64288 KB Output is correct
15 Correct 10 ms 64092 KB Output is correct
16 Correct 11 ms 64092 KB Output is correct
17 Correct 11 ms 64088 KB Output is correct
18 Correct 11 ms 64280 KB Output is correct
19 Correct 11 ms 64092 KB Output is correct
20 Correct 11 ms 64092 KB Output is correct
21 Correct 10 ms 64260 KB Output is correct
22 Correct 10 ms 64144 KB Output is correct
23 Correct 10 ms 64092 KB Output is correct
24 Correct 10 ms 64184 KB Output is correct
25 Correct 10 ms 64092 KB Output is correct
26 Correct 10 ms 64092 KB Output is correct
27 Correct 10 ms 64088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 64084 KB Output is correct
2 Correct 11 ms 64088 KB Output is correct
3 Correct 11 ms 64092 KB Output is correct
4 Correct 13 ms 64344 KB Output is correct
5 Correct 12 ms 64208 KB Output is correct
6 Correct 11 ms 64088 KB Output is correct
7 Correct 11 ms 64092 KB Output is correct
8 Correct 11 ms 64092 KB Output is correct
9 Correct 10 ms 64116 KB Output is correct
10 Correct 10 ms 64092 KB Output is correct
11 Correct 10 ms 64104 KB Output is correct
12 Correct 10 ms 64092 KB Output is correct
13 Correct 12 ms 64092 KB Output is correct
14 Correct 10 ms 64088 KB Output is correct
15 Correct 12 ms 64092 KB Output is correct
16 Correct 10 ms 64092 KB Output is correct
17 Correct 11 ms 64092 KB Output is correct
18 Correct 10 ms 64128 KB Output is correct
19 Correct 10 ms 64176 KB Output is correct
20 Correct 10 ms 64092 KB Output is correct
21 Correct 10 ms 64108 KB Output is correct
22 Correct 11 ms 64092 KB Output is correct
23 Correct 10 ms 64148 KB Output is correct
24 Correct 11 ms 64092 KB Output is correct
25 Correct 11 ms 64092 KB Output is correct
26 Correct 10 ms 64088 KB Output is correct
27 Correct 10 ms 64092 KB Output is correct
28 Correct 10 ms 64088 KB Output is correct
29 Correct 11 ms 64288 KB Output is correct
30 Correct 10 ms 64092 KB Output is correct
31 Correct 11 ms 64092 KB Output is correct
32 Correct 11 ms 64088 KB Output is correct
33 Correct 11 ms 64280 KB Output is correct
34 Correct 11 ms 64092 KB Output is correct
35 Correct 11 ms 64092 KB Output is correct
36 Correct 10 ms 64260 KB Output is correct
37 Correct 10 ms 64144 KB Output is correct
38 Correct 10 ms 64092 KB Output is correct
39 Correct 10 ms 64184 KB Output is correct
40 Correct 10 ms 64092 KB Output is correct
41 Correct 10 ms 64092 KB Output is correct
42 Correct 10 ms 64088 KB Output is correct
43 Correct 101 ms 73960 KB Output is correct
44 Incorrect 563 ms 96664 KB X_i is not increasing
45 Halted 0 ms 0 KB -