Submission #330552

# Submission time Handle Problem Language Result Execution time Memory
330552 2020-11-25T17:23:38 Z EndRay Naan (JOI19_naan) C++17
29 / 100
1090 ms 83564 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 num*b.den == den*b.num;}
    bool operator<(const fraction& b){return num*b.den < den*b.num;}
    bool operator>(const fraction& b){return num*b.den > den*b.num;}
    bool operator<=(const fraction& b){return num*b.den <= den*b.num;}
    bool operator>=(const fraction& b){return num*b.den >= 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 37 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 34 ms 63084 KB Output is correct
7 Correct 34 ms 63084 KB Output is correct
8 Correct 35 ms 63084 KB Output is correct
9 Correct 35 ms 63084 KB Output is correct
10 Correct 35 ms 63084 KB Output is correct
11 Correct 35 ms 63212 KB Output is correct
12 Correct 35 ms 63084 KB Output is correct
13 Correct 35 ms 63084 KB Output is correct
14 Correct 35 ms 63084 KB Output is correct
15 Correct 36 ms 63212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 63084 KB Output is correct
2 Correct 37 ms 63084 KB Output is correct
3 Correct 36 ms 63212 KB Output is correct
4 Correct 35 ms 63212 KB Output is correct
5 Correct 35 ms 63212 KB Output is correct
6 Correct 35 ms 63084 KB Output is correct
7 Correct 36 ms 63084 KB Output is correct
8 Correct 36 ms 63084 KB Output is correct
9 Correct 36 ms 63212 KB Output is correct
10 Correct 36 ms 63212 KB Output is correct
11 Correct 36 ms 63212 KB Output is correct
12 Correct 36 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 37 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 38 ms 63212 KB Output is correct
19 Correct 38 ms 63212 KB Output is correct
20 Correct 35 ms 63212 KB Output is correct
21 Correct 36 ms 63212 KB Output is correct
22 Correct 36 ms 63212 KB Output is correct
23 Correct 35 ms 63084 KB Output is correct
24 Correct 35 ms 63212 KB Output is correct
25 Correct 36 ms 63084 KB Output is correct
26 Correct 36 ms 63084 KB Output is correct
27 Correct 36 ms 63212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 63084 KB Output is correct
2 Correct 37 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 34 ms 63084 KB Output is correct
7 Correct 34 ms 63084 KB Output is correct
8 Correct 35 ms 63084 KB Output is correct
9 Correct 35 ms 63084 KB Output is correct
10 Correct 35 ms 63084 KB Output is correct
11 Correct 35 ms 63212 KB Output is correct
12 Correct 35 ms 63084 KB Output is correct
13 Correct 35 ms 63084 KB Output is correct
14 Correct 35 ms 63084 KB Output is correct
15 Correct 36 ms 63212 KB Output is correct
16 Correct 35 ms 63084 KB Output is correct
17 Correct 37 ms 63084 KB Output is correct
18 Correct 36 ms 63212 KB Output is correct
19 Correct 35 ms 63212 KB Output is correct
20 Correct 35 ms 63212 KB Output is correct
21 Correct 35 ms 63084 KB Output is correct
22 Correct 36 ms 63084 KB Output is correct
23 Correct 36 ms 63084 KB Output is correct
24 Correct 36 ms 63212 KB Output is correct
25 Correct 36 ms 63212 KB Output is correct
26 Correct 36 ms 63212 KB Output is correct
27 Correct 36 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 37 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 38 ms 63212 KB Output is correct
34 Correct 38 ms 63212 KB Output is correct
35 Correct 35 ms 63212 KB Output is correct
36 Correct 36 ms 63212 KB Output is correct
37 Correct 36 ms 63212 KB Output is correct
38 Correct 35 ms 63084 KB Output is correct
39 Correct 35 ms 63212 KB Output is correct
40 Correct 36 ms 63084 KB Output is correct
41 Correct 36 ms 63084 KB Output is correct
42 Correct 36 ms 63212 KB Output is correct
43 Correct 210 ms 68972 KB Output is correct
44 Incorrect 1090 ms 83564 KB X_i is not increasing
45 Halted 0 ms 0 KB -