Submission #124444

# Submission time Handle Problem Language Result Execution time Memory
124444 2019-07-03T10:50:03 Z songc Naan (JOI19_naan) C++14
29 / 100
138 ms 130676 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

int N, K=1, L;
bool chk[2020];

struct Rat{
    LL p=1, q=0;

    Rat(){}
    Rat(LL x, LL y){p = y, q = x;}

    Rat operator+(const Rat &r)const{
        LL g = __gcd(q*r.p + r.q*p, p*r.p);
        return Rat((q*r.p + r.q*p)/g, p*r.p / g);
    }
    Rat operator-(const Rat &r)const{
        LL g = __gcd(q*r.p - r.q*p, p*r.p);
        return Rat((q*r.p - r.q*p)/g, (p*r.p)/g);
    }
    Rat operator*(const Rat &r)const{
        LL g = __gcd(q*r.q, p*r.p);
        return Rat(q*r.q/g, p*r.p/g);
    }
    Rat operator/(const Rat &r)const{
        LL g = __gcd(q*r.p, p*r.q);
        return Rat(q*r.p/g, p*r.q/g);
    }
    bool operator<(const Rat &r)const{
        return q*r.p < r.q*p;
    }
} A[10][2020], C[2020][2020];

int main(){
    scanf("%d %d", &N, &L);
    for (int i=1; i<=N; i++) {
        for (int j=1; j<=L; j++) {
            scanf("%lld", &A[i][j].q);
            A[i][0] = A[i][0] + A[i][j];
        }
        A[i][0].p = N;
    }
    for (int i=1; i<=N; i++){
        Rat R = Rat(0, 1);
        for (int j=1; j<=N; j++){
            Rat S = A[i][0];
            while (1){
                Rat x = A[i][R.q/R.p+1] * (Rat(R.q/R.p+1, 1) - R);
                if (x < S){
                    S = S - x;
                    R = Rat(R.q/R.p+1, 1);
                }
                else{
                    R = R + (S / A[i][R.q/R.p+1]);
                    break;
                }
            }
            C[i][j] = R;
        }
    }
    vector<int> V;
    for (int i=1; i<=N; i++){
        Rat Min=Rat(L+1, 1);
        int id;
        for (int j=1; j<=N; j++){
            if (chk[j]) continue;
            if (C[j][i] < Min){
                Min = C[j][i];
                id = j;
            }
        }
        if (i<N) printf("%lld %lld\n", Min.q, Min.p);
        V.push_back(id);
        chk[id] = true;
    }
    for (int x : V) printf("%d ", x);
    return 0;
}

Compilation message

naan.cpp: In function 'int main()':
naan.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &N, &L);
     ~~~~~^~~~~~~~~~~~~~~~~
naan.cpp:40:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%lld", &A[i][j].q);
             ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 52 ms 64504 KB Output is correct
2 Correct 53 ms 64476 KB Output is correct
3 Correct 53 ms 64504 KB Output is correct
4 Correct 53 ms 64632 KB Output is correct
5 Correct 52 ms 64604 KB Output is correct
6 Correct 52 ms 64504 KB Output is correct
7 Correct 60 ms 64504 KB Output is correct
8 Correct 53 ms 64504 KB Output is correct
9 Correct 52 ms 64524 KB Output is correct
10 Correct 53 ms 64504 KB Output is correct
11 Correct 52 ms 64380 KB Output is correct
12 Correct 53 ms 64540 KB Output is correct
13 Correct 52 ms 64504 KB Output is correct
14 Correct 57 ms 64504 KB Output is correct
15 Correct 53 ms 64632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 64504 KB Output is correct
2 Correct 53 ms 64564 KB Output is correct
3 Correct 53 ms 64480 KB Output is correct
4 Correct 54 ms 64608 KB Output is correct
5 Correct 54 ms 64504 KB Output is correct
6 Correct 54 ms 64568 KB Output is correct
7 Correct 52 ms 64504 KB Output is correct
8 Correct 53 ms 64504 KB Output is correct
9 Correct 55 ms 64504 KB Output is correct
10 Correct 54 ms 64508 KB Output is correct
11 Correct 54 ms 64504 KB Output is correct
12 Correct 58 ms 64616 KB Output is correct
13 Correct 54 ms 64636 KB Output is correct
14 Correct 64 ms 64632 KB Output is correct
15 Correct 54 ms 64504 KB Output is correct
16 Correct 67 ms 64632 KB Output is correct
17 Correct 58 ms 64504 KB Output is correct
18 Correct 55 ms 64504 KB Output is correct
19 Correct 55 ms 64632 KB Output is correct
20 Correct 54 ms 64548 KB Output is correct
21 Correct 55 ms 64632 KB Output is correct
22 Correct 55 ms 64484 KB Output is correct
23 Correct 52 ms 64504 KB Output is correct
24 Correct 55 ms 64632 KB Output is correct
25 Correct 54 ms 64504 KB Output is correct
26 Correct 53 ms 64504 KB Output is correct
27 Correct 55 ms 64376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 64504 KB Output is correct
2 Correct 53 ms 64476 KB Output is correct
3 Correct 53 ms 64504 KB Output is correct
4 Correct 53 ms 64632 KB Output is correct
5 Correct 52 ms 64604 KB Output is correct
6 Correct 52 ms 64504 KB Output is correct
7 Correct 60 ms 64504 KB Output is correct
8 Correct 53 ms 64504 KB Output is correct
9 Correct 52 ms 64524 KB Output is correct
10 Correct 53 ms 64504 KB Output is correct
11 Correct 52 ms 64380 KB Output is correct
12 Correct 53 ms 64540 KB Output is correct
13 Correct 52 ms 64504 KB Output is correct
14 Correct 57 ms 64504 KB Output is correct
15 Correct 53 ms 64632 KB Output is correct
16 Correct 52 ms 64504 KB Output is correct
17 Correct 53 ms 64564 KB Output is correct
18 Correct 53 ms 64480 KB Output is correct
19 Correct 54 ms 64608 KB Output is correct
20 Correct 54 ms 64504 KB Output is correct
21 Correct 54 ms 64568 KB Output is correct
22 Correct 52 ms 64504 KB Output is correct
23 Correct 53 ms 64504 KB Output is correct
24 Correct 55 ms 64504 KB Output is correct
25 Correct 54 ms 64508 KB Output is correct
26 Correct 54 ms 64504 KB Output is correct
27 Correct 58 ms 64616 KB Output is correct
28 Correct 54 ms 64636 KB Output is correct
29 Correct 64 ms 64632 KB Output is correct
30 Correct 54 ms 64504 KB Output is correct
31 Correct 67 ms 64632 KB Output is correct
32 Correct 58 ms 64504 KB Output is correct
33 Correct 55 ms 64504 KB Output is correct
34 Correct 55 ms 64632 KB Output is correct
35 Correct 54 ms 64548 KB Output is correct
36 Correct 55 ms 64632 KB Output is correct
37 Correct 55 ms 64484 KB Output is correct
38 Correct 52 ms 64504 KB Output is correct
39 Correct 55 ms 64632 KB Output is correct
40 Correct 54 ms 64504 KB Output is correct
41 Correct 53 ms 64504 KB Output is correct
42 Correct 55 ms 64376 KB Output is correct
43 Runtime error 138 ms 130676 KB Execution killed with signal 8 (could be triggered by violating memory limits)
44 Halted 0 ms 0 KB -