답안 #171001

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
171001 2019-12-27T02:07:29 Z errorgorn Naan (JOI19_naan) C++14
100 / 100
1130 ms 210360 KB
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
struct fraction{
    long long a,b;
    fraction(){
        a=0;
        b=1;
    }
    fraction (long long i, long long _a, long long _b){
        a=_a;
        b=_b;
        a+=i*b;
    }
    long long whole(){
        return a/b;
    }
    bool bigger(fraction *i){
        if (whole()!=i->whole()){
            return whole()<i->whole();
        }
        else{
            return (a-(b*whole()))*i->b<(i->a-(i->b*whole()))*b;
        }
	}
};
int n,l;
long long arr[2005][2005];
fraction *split[2005][2005];
vector<int> rem;
int perm[2005];
int main(){
    //freopen("input.txt","r",stdin);
    scanf("%d%d",&n,&l);
    long long total,curr_total;
    long long inc,val;
    int pointer;
    for (int x=1;x<=n;x++){
        total=0;
        for (int y=0;y<l;y++){
            scanf("%lld",&arr[x][y]);
            arr[x][y]*=n;
            total+=arr[x][y];
        }
        inc=total/n;
        val=inc;
        pointer=0;
        curr_total=0;
        while (val!=total){
            while (val<curr_total+arr[x][pointer]){
                split[x][val/inc]=new fraction(pointer, val-curr_total,arr[x][pointer]);
                val+=inc;
            }
            curr_total+=arr[x][pointer];
            pointer++;
        }
        rem.push_back(x);
    }
    pointer=1;
    int best_index;
    int index;
    while (rem.size()>1){
        best_index=-1;
        for (int x=0;x<rem.size();x++){
            index=rem[x];
            if (best_index==-1 || split[index][pointer]->bigger(split[best_index][pointer])){
                best_index=index;
            }
        }
        printf("%lld %lld\n",split[best_index][pointer]->a,split[best_index][pointer]->b);
        rem.erase(find(rem.begin(),rem.end(),best_index));
        perm[pointer]=best_index;
        pointer++;
    }
    for (int x=1;x<n;x++){
        printf("%d ",perm[x]);
    }
    printf("%d\n",rem[0]);
}

Compilation message

naan.cpp: In function 'int main()':
naan.cpp:65:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int x=0;x<rem.size();x++){
                      ~^~~~~~~~~~~
naan.cpp:35: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:42:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%lld",&arr[x][y]);
             ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 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 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 3 ms 504 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 3 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
17 Correct 3 ms 504 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 3 ms 508 KB Output is correct
20 Correct 3 ms 504 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 4 ms 504 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 508 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 3 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 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 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 3 ms 504 KB Output is correct
20 Correct 3 ms 504 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 3 ms 508 KB Output is correct
35 Correct 3 ms 504 KB Output is correct
36 Correct 3 ms 504 KB Output is correct
37 Correct 4 ms 504 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 3 ms 376 KB Output is correct
40 Correct 3 ms 508 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 3 ms 504 KB Output is correct
43 Correct 80 ms 20884 KB Output is correct
44 Correct 505 ms 107656 KB Output is correct
45 Correct 247 ms 39980 KB Output is correct
46 Correct 32 ms 4344 KB Output is correct
47 Correct 332 ms 65144 KB Output is correct
48 Correct 574 ms 155896 KB Output is correct
49 Correct 148 ms 41540 KB Output is correct
50 Correct 786 ms 186200 KB Output is correct
51 Correct 307 ms 67036 KB Output is correct
52 Correct 728 ms 153008 KB Output is correct
53 Correct 608 ms 144888 KB Output is correct
54 Correct 3 ms 376 KB Output is correct
55 Correct 287 ms 90232 KB Output is correct
56 Correct 435 ms 95612 KB Output is correct
57 Correct 359 ms 83320 KB Output is correct
58 Correct 598 ms 143760 KB Output is correct
59 Correct 366 ms 75396 KB Output is correct
60 Correct 1126 ms 201828 KB Output is correct
61 Correct 1113 ms 201384 KB Output is correct
62 Correct 1109 ms 200644 KB Output is correct
63 Correct 1109 ms 201584 KB Output is correct
64 Correct 1130 ms 210360 KB Output is correct
65 Correct 979 ms 196968 KB Output is correct
66 Correct 956 ms 197120 KB Output is correct
67 Correct 975 ms 197112 KB Output is correct
68 Correct 472 ms 105048 KB Output is correct
69 Correct 458 ms 92556 KB Output is correct
70 Correct 558 ms 129276 KB Output is correct
71 Correct 713 ms 140284 KB Output is correct