Submission #124452

# Submission time Handle Problem Language Result Execution time Memory
124452 2019-07-03T11:04:08 Z songc Naan (JOI19_naan) C++14
0 / 100
220 ms 255864 KB
#include <bits/stdc++.h>
using namespace std;
typedef __int128 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[2020][2020], C[2020][2020];

int main(){
    LL a;
    scanf("%d %d", &N, &L);
    for (int i=1; i<=N; i++) {
        for (int j=1; j<=L; j++) {
            scanf("%lld", &a);
          	A[i][j].q = a;
            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", (LL)Min.q, (LL)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:41:29: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type 'LL* {aka __int128*}' [-Wformat=]
             scanf("%lld", &a);
                           ~~^
naan.cpp:76:60: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type 'LL {aka __int128}' [-Wformat=]
         if (i<N) printf("%lld %lld\n", (LL)Min.q, (LL)Min.p);
                                        ~~~~~~~~~           ^
naan.cpp:76:60: warning: format '%lld' expects argument of type 'long long int', but argument 3 has type 'LL {aka __int128}' [-Wformat=]
naan.cpp:38: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:41:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%lld", &a);
             ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 220 ms 255840 KB Integer parameter [name=A_i] equals to -9223372036854775805, violates the range [1, 2000000000000]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 197 ms 255864 KB Not a fair distribution.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 220 ms 255840 KB Integer parameter [name=A_i] equals to -9223372036854775805, violates the range [1, 2000000000000]
2 Halted 0 ms 0 KB -