Submission #992002

# Submission time Handle Problem Language Result Execution time Memory
992002 2024-06-03T14:20:32 Z browntoad Naan (JOI19_naan) C++14
100 / 100
997 ms 179284 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define FOR(i,a,b) for (int i = (a); i<(b); i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define RREP(i,n) for (int i=(n)-1; i>=0; i--)
#define RREP1(i,n) for (int i=(n); i>=1; i--)
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define SQ(x) (x)*(x)
#define pii pair<int, int>
#define pip pair<int, pii>
#define ppi pair<pii, int>
#define pdd pair<double ,double>
#define pcc pair<char, char>
#define endl '\n'
//#define TOAD
#ifdef TOAD
#define bug(x) cerr<<__LINE__<<": "<<#x<<" is "<<x<<endl
#define IOS()
#else
#define bug(...)
#define IOS() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#endif

const double PI=acos(-1);
const ll maxn = 4e5+5;
const ll maxm = 3e3+5;
const ll inf = 1ll<<60;
const ll mod = 998244353;

ll pw(ll a, ll p){
    ll ret = 1;
    while(p > 0){
        if (p&1){
            ret *= a;
            ret %= mod;
        }
        a *= a;
        a %= mod;
        p >>= 1;
    }
    return ret;
}
ll inv(ll a){
    return pw(a, mod-2);
}

int n, L;
struct frac{
    int num, dem;
    bool operator <(frac &b){
        return (__int128)num*b.dem < (__int128)dem*b.num;
    }
};
frac simp(frac a){
    if (a.num == 0) return {0, 1};
    int g = __gcd(a.num, a.dem);
    return {a.num/g, a.dem/g};
}
frac operator +(frac a, frac b){
    frac tmp = {a.num*b.dem + a.dem*b.num, a.dem*b.dem};
    return simp(tmp);
}
frac operator -(frac a, frac b){
    frac tmp = {a.num*b.dem - a.dem*b.num, a.dem*b.dem};
    return simp(tmp);
}
frac operator *(frac a, frac b){
    frac tmp = {a.num*b.num, a.dem*b.dem};
    return simp(tmp);
}
bool operator ==(frac a, frac b){
    frac ta = simp(a), tb = simp(b);
    //a = simp(a); b = simp(b);
    return ta.num == tb.num && ta.dem == tb.dem;
}

bool cmp(pair<frac, int> A, pair<frac, int> B){
    //assert(!(A.f == B.f));
    if (A.f == B.f) assert(0);
    assert(A.f.num > 0 && A.f.dem > 0 && B.f.num > 0 && B.f.dem > 0);
    return (A.f < B.f);
}

vector<pair<frac, int>> ans;
void blackbox(){
    cin>>n>>L;
    vector<vector<frac>> vc(n);
    vector<vector<int>> in(n);
    vector<vector<frac>> pls(n);

    REP(i, n){
        vc[i].resize(L);
        in[i].resize(L);
        pls[i].resize(n);

        int tot = 0;
        REP(j, L) {
            cin>>vc[i][j].num;
            in[i][j] = vc[i][j].num;
            tot += vc[i][j].num;
            vc[i][j].dem = 1;
        }
        frac def = {tot, n};
        def = simp(def);

        int tt = 0;
        REP(j, n){
            frac gl = def;
            while(vc[i][tt] < gl){
                gl = (gl-vc[i][tt]);
                vc[i][tt] = {0, 1};
                tt++;
            }
            //cout<<gl.num<<"///"<<gl.dem<<endl;
            //cout<<vc[i][tt].num<<"///"<<vc[i][tt].dem<<' '<<tt<<endl;

            frac tmp = {tt+1, 1};
            vc[i][tt] = (vc[i][tt] - gl);
            frac tmp2 = {vc[i][tt].num, vc[i][tt].dem*in[i][tt]};
            tmp2 = simp(tmp2);
            pls[i][j] = (tmp - tmp2);
            //cout<<pls[i][j].num<<'/'<<pls[i][j].dem<<' ';
            if (vc[i][tt].num == 0){ // 0
                //cout<<tt<<endl;
                tt++;
            }
        }
    }

    vector<bool> occ(n);
    REP(i, n){
        pair<frac, int> mn = {{L+1, 1}, -1};
        REP(j, n){
            if (!occ[j] && pls[j][i] < mn.f) {
                mn.f = pls[j][i];
                mn.s = j;
            }
        }
        ans.pb(mn);
        occ[mn.s] = 1;

    }
}
signed main(){
    IOS();

    blackbox();

    sort(ALL(ans), cmp);
    assert(SZ(ans) >= 1);
    REP(i, n-1) assert(ans[i].f < ans[i+1].f);
    assert(ans[n-1].f.num == L && ans[n-1].f.dem == 1);

    REP(i, n-1) cout<<ans[i].f.num<<' '<<ans[i].f.dem<<endl;

    REP(i, n) cout<<ans[i].s+1<<' ';
    cout<<endl;



}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 600 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 77 ms 11492 KB Output is correct
44 Correct 463 ms 70144 KB Output is correct
45 Correct 181 ms 45652 KB Output is correct
46 Correct 19 ms 6232 KB Output is correct
47 Correct 299 ms 56828 KB Output is correct
48 Correct 643 ms 77496 KB Output is correct
49 Correct 146 ms 25260 KB Output is correct
50 Correct 854 ms 126808 KB Output is correct
51 Correct 308 ms 61780 KB Output is correct
52 Correct 733 ms 130132 KB Output is correct
53 Correct 672 ms 103252 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
55 Correct 283 ms 35328 KB Output is correct
56 Correct 407 ms 82484 KB Output is correct
57 Correct 323 ms 66132 KB Output is correct
58 Correct 564 ms 96152 KB Output is correct
59 Correct 347 ms 74068 KB Output is correct
60 Correct 777 ms 178772 KB Output is correct
61 Correct 811 ms 179032 KB Output is correct
62 Correct 997 ms 178236 KB Output is correct
63 Correct 932 ms 179284 KB Output is correct
64 Correct 816 ms 179096 KB Output is correct
65 Correct 947 ms 165716 KB Output is correct
66 Correct 934 ms 165804 KB Output is correct
67 Correct 796 ms 165768 KB Output is correct
68 Correct 368 ms 75092 KB Output is correct
69 Correct 369 ms 83028 KB Output is correct
70 Correct 440 ms 87692 KB Output is correct
71 Correct 560 ms 123212 KB Output is correct