답안 #699147

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
699147 2023-02-15T20:27:45 Z doowey Naan (JOI19_naan) C++14
29 / 100
79 ms 6172 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;

    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((low - fin).A > 0){
                        low = fin;
                        id = i;
                    }
                    break;
                }
            }
        }
        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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 360 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 404 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 360 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 404 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Incorrect 79 ms 6172 KB X_i is not increasing
44 Halted 0 ms 0 KB -