답안 #164753

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
164753 2019-11-23T07:39:38 Z ho94949 Naan (JOI19_naan) C++17
29 / 100
1934 ms 12096 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
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;
            //cout << "?" << (long long)h.first << " " << (long long)h.second <<endl;
            //cout << "!" << (long long)cut2[i].first << " " << (long long)cut2[i].second <<endl;

            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)
            {
                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 380 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 380 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 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 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 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 376 KB Output is correct
5 Correct 3 ms 376 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 4 ms 376 KB Output is correct
11 Correct 3 ms 376 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 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 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 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 380 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 380 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 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 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 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 376 KB Output is correct
20 Correct 3 ms 376 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 4 ms 376 KB Output is correct
26 Correct 3 ms 376 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 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 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 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 Correct 308 ms 3840 KB Output is correct
44 Incorrect 1934 ms 12096 KB X_i is not increasing
45 Halted 0 ms 0 KB -