답안 #991975

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
991975 2024-06-03T13:23:16 Z browntoad Naan (JOI19_naan) C++14
0 / 100
0 ms 348 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 num*b.dem < 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);
    return A.f < B.f;
}
signed main(){
    IOS();

    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);
    vector<pair<frac, int>> ans;
    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;

    }
    sort(ALL(ans), cmp);
    REP(i, n-1) cout<<ans[i].f.num<<' '<<ans[i].f.dem<<endl;
    REP(i, n-1) cout<<ans[i].s+1<<' ';
    cout<<endl;
    


}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -