답안 #164754

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
164754 2019-11-23T07:40:44 Z ho94949 Naan (JOI19_naan) C++17
29 / 100
4000 ms 17140 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];
frac now[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;
    for(int i=0; i<N; ++i) now[i] = frac(0, 1);
    while(phase < N-1)
    {

        int nextint = L;
        for(int i=0; i<N; ++i)
            nextint = min(nextint, (int)(now[i].first / now[i].second + 1));

        frac minv = frac(0, 1);
        int mini = -1;
        for(int i=0; i<N; ++i)
        {
            if(used[i]) continue;
            frac diff = frac(nextint, 1) - now[i];
            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[i];
                if(mini == -1 || np < minv)
                {
                    mini = i;
                    minv = np;
                }
            }
        }
        if(mini != -1)
        {

            X[phase] = minv;
            P[phase] = mini;
            used[mini] = true;
            for(int i=0; i<N; ++i) cut[i] = frac(0, 1);

            int mseg = minv.first/minv.second;
//            cout << mseg <<endl;

            for(int i=0; i<N; ++i)
            {
                if(used[i]) continue;
                int base = N*V[i][mseg];
                ll nbj = (minv.first*base+minv.second-1)/minv.second;
                now[i] = nor(frac(nbj, base));
                //cout << "*" << (long long)nbj << " " << base <<endl;
            }
            ++phase;
        }
        else
        {
            for(int i=0; i<N; ++i) cut[i] = cut2[i];
            for(int i=0; i<N; ++i) now[i] = 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:52: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:58: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 3 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 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 3 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 380 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
5 Correct 4 ms 424 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 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 4 ms 376 KB Output is correct
11 Correct 3 ms 380 KB Output is correct
12 Correct 2 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 4 ms 380 KB Output is correct
16 Correct 4 ms 376 KB Output is correct
17 Correct 4 ms 376 KB Output is correct
18 Correct 4 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 5 ms 380 KB Output is correct
22 Correct 4 ms 376 KB Output is correct
23 Correct 2 ms 380 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 3 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 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 3 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 380 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 3 ms 380 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 4 ms 376 KB Output is correct
20 Correct 4 ms 424 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 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 4 ms 376 KB Output is correct
26 Correct 3 ms 380 KB Output is correct
27 Correct 2 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 4 ms 380 KB Output is correct
31 Correct 4 ms 376 KB Output is correct
32 Correct 4 ms 376 KB Output is correct
33 Correct 4 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 5 ms 380 KB Output is correct
37 Correct 4 ms 376 KB Output is correct
38 Correct 2 ms 380 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 Correct 254 ms 3768 KB Output is correct
44 Correct 1569 ms 11496 KB Output is correct
45 Correct 532 ms 6572 KB Output is correct
46 Correct 56 ms 1912 KB Output is correct
47 Correct 928 ms 9128 KB Output is correct
48 Correct 1459 ms 12380 KB Output is correct
49 Correct 317 ms 6700 KB Output is correct
50 Correct 1831 ms 17140 KB Output is correct
51 Correct 578 ms 9592 KB Output is correct
52 Correct 1493 ms 14944 KB Output is correct
53 Correct 1302 ms 14712 KB Output is correct
54 Correct 3 ms 376 KB Output is correct
55 Correct 1341 ms 7204 KB Output is correct
56 Correct 1406 ms 11644 KB Output is correct
57 Correct 1281 ms 10840 KB Output is correct
58 Correct 2210 ms 15004 KB Output is correct
59 Correct 1391 ms 10112 KB Output is correct
60 Correct 3108 ms 16780 KB Output is correct
61 Correct 3265 ms 16864 KB Output is correct
62 Execution timed out 4037 ms 16572 KB Time limit exceeded
63 Halted 0 ms 0 KB -