답안 #279645

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
279645 2020-08-22T08:56:11 Z MKopchev Naan (JOI19_naan) C++14
100 / 100
1058 ms 134520 KB
#include<bits/stdc++.h>
using namespace std;

const int nmax=2e3+42;

int n,m;

int inp[nmax][nmax],pref[nmax];

int outp[nmax];
bool used[nmax];

struct number
{
    long long whole,up,down;
};

number compress(number a)
{
    long long g=__gcd(a.up,a.down);
    a.up=a.up/g;
    a.down=a.down/g;
    return a;
}

number add(number a,number b)
{
    a.whole=a.whole+b.whole;
    a.up=a.up*b.down+a.down*b.up;
    a.down=a.down*b.down;

    a.whole=a.whole+a.up/a.down;
    a.up=a.up/a.down;

    return compress(a);
}

bool at_most(number a,number b)
{
    if(a.whole!=b.whole)return a.whole<b.whole;

    return a.up*b.down<=a.down*b.up;
}

number cut[nmax][nmax];

int pointer[nmax];

int main()
{
    scanf("%i%i",&n,&m);

    for(int i=1;i<=n;i++)
    {
        pointer[i]=1;
        for(int j=1;j<=m;j++)
        {
            scanf("%i",&inp[i][j]);
            pref[i]+=inp[i][j];
        }
    }

    for(int j=1;j<=n;j++)
    {
        int id=1,sum=0;

        for(int t=1;t<=n;t++)
        {
            pair<long long,long long> wanted={1LL*t*pref[j],n};

            while(id<=m&&wanted.second*(sum+inp[j][id])<=wanted.first)
            {
                sum=sum+inp[j][id];
                id++;
            }

            cut[j][t].whole=id-1;
            cut[j][t].up=wanted.first-sum*wanted.second;
            cut[j][t].down=wanted.second*inp[j][min(m,id)];

            //cout<<j<<" "<<t<<" -> "<<cut[j][t].whole<<" "<<cut[j][t].up<<" "<<cut[j][t].down<<endl;

            cut[j][t]=compress(cut[j][t]);

            //cout<<j<<" "<<t<<" -> "<<id<<" "<<cut[j][t].whole<<" "<<cut[j][t].up<<" "<<cut[j][t].down<<endl;
        }
    }

    for(int t=1;t<=n;t++)
    {
        number mini;mini.whole=m;mini.up=0;mini.down=1;

        int which=-1;

        for(int j=1;j<=n;j++)
            if(used[j]==0)
            {
                if(at_most(cut[j][t],mini))
                {
                    mini=cut[j][t];
                    which=j;
                }
            }

        mini=compress(mini);

        if(t!=n)printf("%lld %lld\n",mini.up+mini.whole*mini.down,mini.down);

        outp[t]=which;
        used[which]=1;
    }



    for(int i=1;i<=n;i++)printf("%i ",outp[i]);
    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]
   51 |     scanf("%i%i",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
naan.cpp:58:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   58 |             scanf("%i",&inp[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 512 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 2 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 2 ms 384 KB Output is correct
43 Correct 90 ms 13432 KB Output is correct
44 Correct 514 ms 60664 KB Output is correct
45 Correct 282 ms 27416 KB Output is correct
46 Correct 36 ms 3320 KB Output is correct
47 Correct 364 ms 43244 KB Output is correct
48 Correct 553 ms 103032 KB Output is correct
49 Correct 145 ms 28028 KB Output is correct
50 Correct 798 ms 116088 KB Output is correct
51 Correct 334 ms 42104 KB Output is correct
52 Correct 721 ms 96752 KB Output is correct
53 Correct 640 ms 92184 KB Output is correct
54 Correct 1 ms 384 KB Output is correct
55 Correct 261 ms 58984 KB Output is correct
56 Correct 440 ms 59804 KB Output is correct
57 Correct 369 ms 52472 KB Output is correct
58 Correct 567 ms 92796 KB Output is correct
59 Correct 375 ms 47224 KB Output is correct
60 Correct 964 ms 134448 KB Output is correct
61 Correct 1018 ms 134264 KB Output is correct
62 Correct 1058 ms 134080 KB Output is correct
63 Correct 990 ms 134520 KB Output is correct
64 Correct 983 ms 134392 KB Output is correct
65 Correct 934 ms 121268 KB Output is correct
66 Correct 947 ms 120952 KB Output is correct
67 Correct 853 ms 120952 KB Output is correct
68 Correct 368 ms 67832 KB Output is correct
69 Correct 399 ms 59188 KB Output is correct
70 Correct 469 ms 83992 KB Output is correct
71 Correct 597 ms 89852 KB Output is correct