Submission #375265

# Submission time Handle Problem Language Result Execution time Memory
375265 2021-03-09T05:42:56 Z daniel920712 Naan (JOI19_naan) C++14
5 / 100
4 ms 512 KB
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>

using namespace std;

long long all[2005][2005];
long long sum[2005][2005]={0};
long long tt[2005];
vector < pair < long long , long long > > ans;
long long F(long long a,long long b)
{
    if(b==0) return a;
    return F(b,a%b);
}
int main()
{
    long long N,M,a,b,x1,y1,x2,y2,c,i,j,ok=1,now=0,z,x3,y3,t;
    scanf("%lld %lld",&N,&M);
    for(i=0;i<N;i++)
    {
        sum[i][0]=0;
        for(j=0;j<M;j++)
        {
            scanf("%lld",&all[i][j]);
            sum[i][j]=sum[i][j-1]+all[i][j];
        }
    }
    for(i=0;i<N;i++) tt[i]=i;
    do
    {
        ans.clear();
        x1=0;
        y1=1;
        now=0;


        a=0;
        b=1;

        for(i=0;i<M;i++)
        {
            x3=1;
            y3=1;
            while(1)
            {
                x2=x1*y3+x3*y1*all[tt[now]][i];
                y2=y1*y3;
                t=F(x2,y2);
                x2/=t;
                y2/=t;
                if(x2*N>=sum[tt[now]][M-1]*y2)
                {

                    x2=sum[tt[now]][M-1]*y1-x1*N;
                    y2=y1*N*all[tt[now]][i];

                    t=F(x2,y2);
                    x2/=t;
                    y2/=t;



                    x3=x3*y2-x2*y3;
                    y3*=y2;

                    t=F(x3,y3);
                    x3/=t;
                    y3/=t;

                    if(now<=N-1)
                    {

                        if(now<N-1) ans.push_back(make_pair(x2*b+a*y2,b*y2));

                        a=x2*b+a*y2;
                        b*=y2;
                        t=F(a,b);
                        a/=t;
                        b/=t;

                        now++;
                        y1=y3;
                        x1=x3*all[tt[now]][i];

                        t=F(x1,y1);
                        x1/=t;
                        y1/=t;
                        //printf("bb %lld %lld\n",x2,y2);
                    }
                    if(now==N) break;
                }
                else
                {

                    a=x3*b+a*y3;
                    b*=y3;
                    t=F(a,b);
                    a/=t;
                    b/=t;


                    x1=x2;
                    y1=y2;

                    t=F(x1,y1);
                    x1/=t;
                    y1/=t;
                    break;
                }

            }
            if(now==N) break;
        }
        if(now==N)
        {
            for(auto i:ans) printf("%lld %lld\n",i.first,i.second);
            for(i=0;i<N;i++) printf("%lld ",tt[i]+1);
            return 0;
        }
    }while(next_permutation(tt,tt+N));
    printf("-1\n");
    return 0;
}

Compilation message

naan.cpp: In function 'int main()':
naan.cpp:20:35: warning: unused variable 'c' [-Wunused-variable]
   20 |     long long N,M,a,b,x1,y1,x2,y2,c,i,j,ok=1,now=0,z,x3,y3,t;
      |                                   ^
naan.cpp:20:41: warning: unused variable 'ok' [-Wunused-variable]
   20 |     long long N,M,a,b,x1,y1,x2,y2,c,i,j,ok=1,now=0,z,x3,y3,t;
      |                                         ^~
naan.cpp:20:52: warning: unused variable 'z' [-Wunused-variable]
   20 |     long long N,M,a,b,x1,y1,x2,y2,c,i,j,ok=1,now=0,z,x3,y3,t;
      |                                                    ^
naan.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |     scanf("%lld %lld",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
naan.cpp:27:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   27 |             scanf("%lld",&all[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 4 ms 492 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 2 ms 500 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
21 Correct 2 ms 492 KB Output is correct
22 Correct 2 ms 492 KB Output is correct
23 Incorrect 0 ms 364 KB Not a fair distribution.
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 4 ms 492 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 2 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 2 ms 492 KB Output is correct
34 Correct 2 ms 500 KB Output is correct
35 Correct 2 ms 492 KB Output is correct
36 Correct 2 ms 492 KB Output is correct
37 Correct 2 ms 492 KB Output is correct
38 Incorrect 0 ms 364 KB Not a fair distribution.
39 Halted 0 ms 0 KB -