Submission #330553

# Submission time Handle Problem Language Result Execution time Memory
330553 2020-11-25T17:24:18 Z EndRay Naan (JOI19_naan) C++17
100 / 100
2262 ms 116728 KB
#include<bits/stdc++.h>
#define ll long long

using namespace std;

const int N = 2000+1;

struct fraction{
    ll num, den;
    fraction(ll num=0, ll den=1):num(num), den(den){}

    void normalize(){
        ll g = __gcd(num, den);
        num /= g;
        den /= g;
        if(den < 0){
            num = -num;
            den = -den;
        }
    }

    fraction operator-(){
        return fraction{-num, den};
    }

    fraction operator+=(const fraction& b){
        num = num*b.den + den*b.num;
        den = den*b.den;
        normalize();
        return *this;
    }
    fraction operator-=(const fraction& b){
        num = num*b.den - den*b.num;
        den = den*b.den;
        normalize();
        return *this;
    }
    fraction operator*=(const fraction& b){
        num = num*b.num;
        den = den*b.den;
        normalize();
        return *this;
    }
    fraction operator/=(const fraction& b){
        num = num*b.den;
        den = den*b.num;
        normalize();
        return *this;
    }

    bool operator==(const fraction& b){return 1.0*num*b.den == 1.0*den*b.num;}
    bool operator<(const fraction& b){return 1.0*num*b.den < 1.0*den*b.num;}
    bool operator>(const fraction& b){return 1.0*num*b.den > 1.0*den*b.num;}
    bool operator<=(const fraction& b){return 1.0*num*b.den <= 1.0*den*b.num;}
    bool operator>=(const fraction& b){return 1.0*num*b.den >= 1.0*den*b.num;}
};

fraction operator+(fraction a, const fraction& b){return (a += b);}
fraction operator-(fraction a, const fraction& b){return (a -= b);}
fraction operator*(fraction a, const fraction& b){return (a *= b);}
fraction operator/(fraction a, const fraction& b){return (a /= b);}

int n, l;
ll v[N][N];
ll sum[N];
fraction split[N][N];
bool used[N];
fraction ans[N];
int p[N];

int main(){
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    cin >> n >> l;
    for(int i = 0; i < n; ++i)
        for(int j = 1; j <= l; ++j){
            cin >> v[i][j];
            sum[i] += v[i][j];
        }
    for(int i = 0; i < n; ++i){
        split[i][0] = 0;
        split[i][n] = n;
        fraction need = fraction(sum[i], n);
        int k = 1;
        fraction cur_sum = 0;
        for(int j = 1; j < n; ++j){
            for(; cur_sum + v[i][k] <= need*j; ++k)
                cur_sum += v[i][k];
            split[i][j] = k-1 + (need*j-cur_sum)/v[i][k];
        }
    }
    for(int j = 1; j < n; ++j){
        fraction mn = l;
        int mn_i = -1;
        for(int i = 0; i < n; ++i)
            if(!used[i] && mn > split[i][j]){
                mn = split[i][j];
                mn_i = i;
            }
        ans[j] = mn;
        p[j] = mn_i;
        used[mn_i] = true;
    }
    for(int i = 0; i < n; ++i)
        if(!used[i])
            p[n] = i;
    for(int j = 1; j < n; ++j)
        cout << ans[j].num << " " << ans[j].den << "\n";
    for(int j = 1; j <= n; ++j)
        cout << p[j]+1 << " ";
    cout << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 34 ms 63084 KB Output is correct
2 Correct 34 ms 63084 KB Output is correct
3 Correct 35 ms 63084 KB Output is correct
4 Correct 35 ms 63084 KB Output is correct
5 Correct 36 ms 63084 KB Output is correct
6 Correct 35 ms 63084 KB Output is correct
7 Correct 35 ms 63084 KB Output is correct
8 Correct 36 ms 63212 KB Output is correct
9 Correct 35 ms 63084 KB Output is correct
10 Correct 36 ms 63084 KB Output is correct
11 Correct 36 ms 63084 KB Output is correct
12 Correct 40 ms 63084 KB Output is correct
13 Correct 34 ms 63084 KB Output is correct
14 Correct 35 ms 63084 KB Output is correct
15 Correct 35 ms 63084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 63084 KB Output is correct
2 Correct 36 ms 63084 KB Output is correct
3 Correct 35 ms 63084 KB Output is correct
4 Correct 43 ms 63212 KB Output is correct
5 Correct 35 ms 63084 KB Output is correct
6 Correct 35 ms 63084 KB Output is correct
7 Correct 35 ms 63084 KB Output is correct
8 Correct 37 ms 63084 KB Output is correct
9 Correct 38 ms 63212 KB Output is correct
10 Correct 35 ms 63188 KB Output is correct
11 Correct 36 ms 63084 KB Output is correct
12 Correct 34 ms 63084 KB Output is correct
13 Correct 35 ms 63084 KB Output is correct
14 Correct 36 ms 63212 KB Output is correct
15 Correct 36 ms 63212 KB Output is correct
16 Correct 35 ms 63212 KB Output is correct
17 Correct 35 ms 63212 KB Output is correct
18 Correct 35 ms 63212 KB Output is correct
19 Correct 38 ms 63212 KB Output is correct
20 Correct 35 ms 63084 KB Output is correct
21 Correct 35 ms 63212 KB Output is correct
22 Correct 36 ms 63212 KB Output is correct
23 Correct 36 ms 63084 KB Output is correct
24 Correct 35 ms 63104 KB Output is correct
25 Correct 36 ms 63084 KB Output is correct
26 Correct 36 ms 63084 KB Output is correct
27 Correct 35 ms 63084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 63084 KB Output is correct
2 Correct 34 ms 63084 KB Output is correct
3 Correct 35 ms 63084 KB Output is correct
4 Correct 35 ms 63084 KB Output is correct
5 Correct 36 ms 63084 KB Output is correct
6 Correct 35 ms 63084 KB Output is correct
7 Correct 35 ms 63084 KB Output is correct
8 Correct 36 ms 63212 KB Output is correct
9 Correct 35 ms 63084 KB Output is correct
10 Correct 36 ms 63084 KB Output is correct
11 Correct 36 ms 63084 KB Output is correct
12 Correct 40 ms 63084 KB Output is correct
13 Correct 34 ms 63084 KB Output is correct
14 Correct 35 ms 63084 KB Output is correct
15 Correct 35 ms 63084 KB Output is correct
16 Correct 36 ms 63084 KB Output is correct
17 Correct 36 ms 63084 KB Output is correct
18 Correct 35 ms 63084 KB Output is correct
19 Correct 43 ms 63212 KB Output is correct
20 Correct 35 ms 63084 KB Output is correct
21 Correct 35 ms 63084 KB Output is correct
22 Correct 35 ms 63084 KB Output is correct
23 Correct 37 ms 63084 KB Output is correct
24 Correct 38 ms 63212 KB Output is correct
25 Correct 35 ms 63188 KB Output is correct
26 Correct 36 ms 63084 KB Output is correct
27 Correct 34 ms 63084 KB Output is correct
28 Correct 35 ms 63084 KB Output is correct
29 Correct 36 ms 63212 KB Output is correct
30 Correct 36 ms 63212 KB Output is correct
31 Correct 35 ms 63212 KB Output is correct
32 Correct 35 ms 63212 KB Output is correct
33 Correct 35 ms 63212 KB Output is correct
34 Correct 38 ms 63212 KB Output is correct
35 Correct 35 ms 63084 KB Output is correct
36 Correct 35 ms 63212 KB Output is correct
37 Correct 36 ms 63212 KB Output is correct
38 Correct 36 ms 63084 KB Output is correct
39 Correct 35 ms 63104 KB Output is correct
40 Correct 36 ms 63084 KB Output is correct
41 Correct 36 ms 63084 KB Output is correct
42 Correct 35 ms 63084 KB Output is correct
43 Correct 207 ms 67564 KB Output is correct
44 Correct 1104 ms 82164 KB Output is correct
45 Correct 407 ms 81428 KB Output is correct
46 Correct 70 ms 66052 KB Output is correct
47 Correct 674 ms 86232 KB Output is correct
48 Correct 1652 ms 79296 KB Output is correct
49 Correct 364 ms 71820 KB Output is correct
50 Correct 1967 ms 96556 KB Output is correct
51 Correct 694 ms 83160 KB Output is correct
52 Correct 1627 ms 97132 KB Output is correct
53 Correct 1499 ms 92524 KB Output is correct
54 Correct 35 ms 63084 KB Output is correct
55 Correct 768 ms 70252 KB Output is correct
56 Correct 963 ms 87788 KB Output is correct
57 Correct 768 ms 84460 KB Output is correct
58 Correct 1372 ms 89452 KB Output is correct
59 Correct 807 ms 84716 KB Output is correct
60 Correct 1822 ms 116452 KB Output is correct
61 Correct 1892 ms 116460 KB Output is correct
62 Correct 2262 ms 116460 KB Output is correct
63 Correct 2201 ms 116728 KB Output is correct
64 Correct 1839 ms 116612 KB Output is correct
65 Correct 2220 ms 103276 KB Output is correct
66 Correct 2118 ms 103276 KB Output is correct
67 Correct 1851 ms 103148 KB Output is correct
68 Correct 885 ms 87532 KB Output is correct
69 Correct 813 ms 90220 KB Output is correct
70 Correct 1121 ms 89836 KB Output is correct
71 Correct 1314 ms 99180 KB Output is correct