답안 #164751

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
164751 2019-11-23T07:09:08 Z ho94949 Naan (JOI19_naan) C++17
29 / 100
245 ms 3708 KB
#include<bits/stdc++.h>
using namespace std;
using ll = __int128;
using frac = pair<ll, ll>;
int N, L;
int V[2020][2020];
frac happy[2020];
frac cut[2020];
frac cut2[2020];
int P[2020];
frac X[2020];
bool used[2020];

ll gcdx(ll a, ll b)
{
    if(b==0) return a;
    return gcdx(b, a%b);
}

frac nor(frac t)
{
    ll a, b; tie(a, b) = t;
    ll g = gcdx(a, b);
    return frac(a/g, b/g);
}

frac operator +(frac a, frac b)
{
    ll x, y, z, w;
    tie(x, y) = a; tie(z, w) = b;
    return nor(frac(x*w+y*z, y*w));
}

frac operator -(frac a, frac b)
{
    ll x, y, z, w;
    tie(x, y) = a; tie(z, w) = b;
    return nor(frac(x*w-y*z, y*w));
}

bool operator < (frac a, frac b)
{
    ll x, y, z, w;
    tie(x, y) = a; tie(z, w) = b;
    return x*w < y*z;

}

int main()
{
    scanf("%d%d", &N, &L);
    for(int i=0; i<N; ++i)
    {
        happy[i].second = N;
        for(int j=0; j<L; ++j)
        {
            scanf("%d", &V[i][j]);
            happy[i].first += V[i][j];
        }
        happy[i] = nor(happy[i]);
        cut[i] = cut2[i] = frac(0, 1);
    }

    //cut: happyness now
    //cut2: happyness future

    int phase = 0;
    frac now = frac(0, 1);
    while(phase < N-1)
    {
        int nextint = now.first / now.second + 1;
        frac diff = frac(nextint, 1) - now;
        frac minv = frac(0, 1);
        int mini = -1;
        for(int i=0; i<N; ++i)
        {
            if(used[i]) continue;
            frac h = diff; h.first *= V[i][nextint-1];
            h = nor(h);
            cut2[i] = cut[i] + h;

            if(!(cut2[i] < happy[i]))
            {
                frac np = (happy[i]-cut[i]); np.second *= V[i][nextint-1];
                np = np + now;
                if(mini == -1 || np < minv)
                {
                    mini = i;
                    minv = np;
                }
            }
        }
        if(mini != -1)
        {
            //adjust minv into minv into less than 1e9
            frac nf;
            if(minv.second <= (int)1e9) nf = minv;
            else
            {
                ll nu = (minv.first*(int)1e9 + minv.second -1) / minv.second;
                nf = frac(nu, (int)1e9);
            }
            


            X[phase] = nf;
            P[phase] = mini;
            used[mini] = true;
            for(int i=0; i<N; ++i) cut[i] = frac(0, 1);
            now = nf;
            ++phase;
        }
        else
        {
            for(int i=0; i<N; ++i) cut[i] = cut2[i];
            now = frac(nextint, 1);
        }
    }
    for(int i=0; i<N-1; ++i)
        printf("%lld %lld\n", (long long)X[i].first, (long long)X[i].second);
    for(int i=0; i<N-1; ++i)
        printf("%d ", P[i]+1);
    for(int i=0; i<N; ++i)
        if(!used[i])
            printf("%d\n", i+1);
    
    return 0;
}

Compilation message

naan.cpp: In function 'int main()':
naan.cpp:51: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:57:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &V[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 380 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 380 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 4 ms 504 KB Output is correct
5 Correct 4 ms 452 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 4 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 4 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 4 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 4 ms 376 KB Output is correct
17 Correct 4 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 4 ms 376 KB Output is correct
20 Correct 4 ms 376 KB Output is correct
21 Correct 4 ms 376 KB Output is correct
22 Correct 4 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 4 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 4 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 380 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 380 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 4 ms 504 KB Output is correct
20 Correct 4 ms 452 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 4 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 4 ms 376 KB Output is correct
28 Correct 3 ms 376 KB Output is correct
29 Correct 4 ms 376 KB Output is correct
30 Correct 3 ms 376 KB Output is correct
31 Correct 4 ms 376 KB Output is correct
32 Correct 4 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 4 ms 376 KB Output is correct
35 Correct 4 ms 376 KB Output is correct
36 Correct 4 ms 376 KB Output is correct
37 Correct 4 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 4 ms 376 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 3 ms 376 KB Output is correct
42 Correct 4 ms 376 KB Output is correct
43 Incorrect 245 ms 3708 KB Not a fair distribution.
44 Halted 0 ms 0 KB -