답안 #699320

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
699320 2023-02-16T14:55:46 Z doowey Naan (JOI19_naan) C++14
29 / 100
4000 ms 148608 KB
#include <bits/stdc++.h>

using namespace std;

typedef __int128 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)1e18;

struct frac{
    ll A;
    ll B;
    frac operator+ (frac y){
        return {A * y.B + B * y.A, B * y.B};
    }
    frac operator- (frac y){
        return {A * y.B - B * y.A, B * y.B};
    }
    bool operator< (frac y){
        if(A/B == y.A/y.B){
            return (A * y.B - B * y.A < 0);
        }
        else{
            return A/B < y.A/y.B;
        }
    }
};

ll V[N][N];
ll S[N][N];
int m;

frac calc(int id, frac P){
    int las = P.A / P.B;
    frac Y = {S[id][las], 1};
    frac add = (P - (frac){las, 1});
    add.A *= V[id][las + 1];
    Y = Y + add;
    return Y;
}

frac need[N];
bool use[N];
int pi[N];

int main(){
    fastIO;
    //freopen("in.txt", "r", stdin);
    int n;
    cin >> n >> m;
    int vv;
    for(int i = 1; i <= n; i ++ ){
        need[i] = {0, n};
        for(int j = 1; j <= m ; j ++ ){
            cin >> vv;
            V[i][j] = vv;
            need[i].A += V[i][j];
            S[i][j] = V[i][j] + S[i][j - 1];
        }
        pi[i] = -1;
    }
    frac las = {0, 1};
    frac tis;
    frac nx;
    frac cur;
    frac low;
    int idx;
    frac S;
    ll X;

    for(int it = 1; it < n; it ++ ){
        low = {m, 1};
        idx = -1;
        for(int i = 1; i <= n; i ++ ){
            if(!use[i]){
                tis = calc(i, las);
                for(int j = 1; j <= m; j ++ ){
                    nx = calc(i, {j, 1});
                    if(tis < nx){
                        if(need[i] < nx - tis){
                            S = nx - tis;
                            S = S - need[i];
                            S.A *= (ll)n;
                            X = S.A / S.B;
                            tis = (frac){j, 1} - (frac){X, n * 1ll * V[i][j]};
                            if(tis < low){
                                low = tis;
                                idx = i;
                            }
                            break;
                        }
                    }
                }
            }
        }
        pi[it] = idx;
        use[idx]=true;
        las = low;
        cout << (long long)low.A << " " << (long long)low.B << "\n";
    }
    for(int i = 1; i <= n; i ++ ){
        if(!use[i]){
            pi[n]=i;
        }
    }
    for(int i = 1; i <= n; i ++ ){
        cout << pi[i] << " ";
    }
    cout << "\n";
    return 0;
}

Compilation message

naan.cpp: In function 'int main()':
naan.cpp:71:10: warning: unused variable 'cur' [-Wunused-variable]
   71 |     frac cur;
      |          ^~~
# 결과 실행 시간 메모리 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 468 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 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 484 KB Output is correct
14 Correct 2 ms 472 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 472 KB Output is correct
9 Correct 2 ms 636 KB Output is correct
10 Correct 1 ms 608 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 1 ms 724 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 736 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 596 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 468 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 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 484 KB Output is correct
14 Correct 2 ms 472 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 472 KB Output is correct
24 Correct 2 ms 636 KB Output is correct
25 Correct 1 ms 608 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 596 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 1 ms 724 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 724 KB Output is correct
34 Correct 1 ms 724 KB Output is correct
35 Correct 1 ms 596 KB Output is correct
36 Correct 1 ms 736 KB Output is correct
37 Correct 1 ms 724 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 596 KB Output is correct
40 Correct 1 ms 596 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 596 KB Output is correct
43 Correct 53 ms 13112 KB Output is correct
44 Correct 506 ms 65196 KB Output is correct
45 Correct 273 ms 43860 KB Output is correct
46 Correct 21 ms 7380 KB Output is correct
47 Correct 331 ms 52528 KB Output is correct
48 Correct 681 ms 42460 KB Output is correct
49 Correct 166 ms 24396 KB Output is correct
50 Correct 848 ms 101716 KB Output is correct
51 Correct 303 ms 66452 KB Output is correct
52 Correct 765 ms 115156 KB Output is correct
53 Correct 667 ms 89796 KB Output is correct
54 Correct 1 ms 596 KB Output is correct
55 Correct 250 ms 16852 KB Output is correct
56 Correct 483 ms 83444 KB Output is correct
57 Correct 1211 ms 66188 KB Output is correct
58 Correct 2126 ms 79744 KB Output is correct
59 Correct 1429 ms 74848 KB Output is correct
60 Correct 2736 ms 148092 KB Output is correct
61 Correct 2752 ms 148168 KB Output is correct
62 Correct 2800 ms 147808 KB Output is correct
63 Correct 2880 ms 148608 KB Output is correct
64 Correct 2829 ms 148392 KB Output is correct
65 Correct 2864 ms 135020 KB Output is correct
66 Correct 3105 ms 134960 KB Output is correct
67 Execution timed out 4096 ms 134908 KB Time limit exceeded
68 Halted 0 ms 0 KB -