Submission #699153

# Submission time Handle Problem Language Result Execution time Memory
699153 2023-02-15T20:42:06 Z doowey Naan (JOI19_naan) C++14
0 / 100
1 ms 340 KB
 #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = 2010;
const ll C = (ll)2e18;
ll V[N][N];

struct Frac{
    ll A;
    ll B;
    Frac operator+(Frac bi){
        return {A * bi.B + B * bi.A, B * bi.B};
    }
    Frac operator-(Frac bi){
        return {A * bi.B - B * bi.A, B * bi.B};
    }
    Frac operator*(Frac bi){
        return {A * bi.A, B * bi.B};
    }
};

Frac get_sum(int i, Frac en){
    Frac g = {0, 1};
    int id = (ll)(en.A / en.B);
    for(int j = 0 ; j < id; j ++ ){
        g = g + (Frac){V[i][j], 1};
    }
    g = g + (en - (Frac){id, 1}) * (Frac){V[i][id], 1};
    return g;
}

Frac need[N];
int go[N];

int main(){
    fastIO;
    //freopen("in.txt", "r", stdin);
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i ++ ){
        need[i] = {0, n};
        for(int j = 0 ;j < m ; j ++ ){
            cin >> V[i][j];
            need[i].A += V[i][j];
        }
        go[i] = -1;
    }
    Frac las = (Frac){0, 1};
    Frac cum;
    Frac nx;
    Frac sum;
    ll C, VV;
    ll X;
    Frac low;
    Frac fin;
    int id;
    vector<Frac> ff;
    for(int iter = 1; iter < n; iter ++ ){
        low = {m, 1};
        id = -1;
        for(int i = 1; i <= n; i ++ ){
            if(go[i] != -1) continue;
            cum = get_sum(i, las);
            nx = (Frac){0, 1};
            for(int j = 0; j < m ; j ++ ){
                nx = nx + (Frac) {V[i][j], 1};
                sum = nx - cum;
                sum = sum - need[i];
                if(sum.A >= 0){
                    VV = V[i][j];
                    C = n * 1ll * V[i][j];
                    sum = sum * (Frac) {C, VV};
                    X = sum.A / sum.B;
                    fin = (Frac){(j + 1), 1} - (Frac){X, C};
                    if((fin - low).A <= 0){
                        low = fin;
                        id = i;
                    }
                    break;
                }
            }
        }
        if(!ff.empty() && (low - ff.back()).A <= 0){
            cout << "no, no, no...\n";
            return 0;
        }
        ff.push_back(low);
        //cout << low.A << " " << low.B << "\n";
        go[id] = iter;
        las = low;
    }
    for(int i = 1; i <= n; i ++ ){
        if(go[i] == -1) go[i] = n;
        cout << go[i] << " ";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -