답안 #251869

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
251869 2020-07-22T13:09:16 Z dantoh000 Naan (JOI19_naan) C++14
100 / 100
1057 ms 85496 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;
int n,l;
ii p[2005][2005];
int vis[2005];
ll a[2005];
int ord[2005];
int main(){
    scanf("%d%d",&n,&l);
    for (int i = 1; i <= n; i++){
        ll s = 0;
        for (int j = 1; j <= l; j++){
            scanf("%lld",&a[j]);
            s += a[j];
        }
        ll o = 0, k = 0;
        for (int j = 1; j <= n; j++){
            while (k < l && (o+a[k])*n < s*j) o += a[k++];
            ll A = 1ll*(k-1)*a[k]*n + s*j - o*n;
            ll B = 1ll*a[k]*n;
            ll D = __gcd(A,B);
            p[i][j] = ii(A/D, B/D);
        }
    }

    for (int i = 1; i <= n; i++){
        ii best = {1,0};
        int cur;
        for (int j = 1; j <= n; j++){
            if (vis[j] == 0){
                if ((__int128)best.first*p[j][i].second > (__int128)best.second*p[j][i].first){
                    best = p[j][i];
                    cur = j;
                }
            }
        }
        ord[i] = cur;
        vis[cur] = 1;
        if (i != n) printf("%lld %lld\n",best.first,best.second);
    }
    for (int i = 1; i <= n; i++){
        printf("%d ",ord[i]);
    }

}

Compilation message

naan.cpp: In function 'int main()':
naan.cpp:11: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:15:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%lld",&a[j]);
             ~~~~~^~~~~~~~~~~~~~
naan.cpp:39:16: warning: 'cur' may be used uninitialized in this function [-Wmaybe-uninitialized]
         ord[i] = cur;
         ~~~~~~~^~~~~
# 결과 실행 시간 메모리 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 2 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 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 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 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 2 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 1 ms 384 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 2 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 3 ms 384 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 1 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 2 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 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 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 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 2 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 1 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 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 2 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 3 ms 384 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 1 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 92 ms 9080 KB Output is correct
44 Correct 481 ms 44980 KB Output is correct
45 Correct 229 ms 18040 KB Output is correct
46 Correct 29 ms 2168 KB Output is correct
47 Correct 314 ms 27512 KB Output is correct
48 Correct 543 ms 61056 KB Output is correct
49 Correct 138 ms 16632 KB Output is correct
50 Correct 742 ms 67704 KB Output is correct
51 Correct 296 ms 25208 KB Output is correct
52 Correct 698 ms 60136 KB Output is correct
53 Correct 572 ms 56440 KB Output is correct
54 Correct 1 ms 384 KB Output is correct
55 Correct 256 ms 37216 KB Output is correct
56 Correct 434 ms 36236 KB Output is correct
57 Correct 336 ms 31300 KB Output is correct
58 Correct 528 ms 56312 KB Output is correct
59 Correct 341 ms 28536 KB Output is correct
60 Correct 882 ms 85112 KB Output is correct
61 Correct 891 ms 85108 KB Output is correct
62 Correct 1057 ms 85024 KB Output is correct
63 Correct 917 ms 85496 KB Output is correct
64 Correct 908 ms 85168 KB Output is correct
65 Correct 880 ms 71864 KB Output is correct
66 Correct 880 ms 71800 KB Output is correct
67 Correct 913 ms 71804 KB Output is correct
68 Correct 349 ms 41748 KB Output is correct
69 Correct 369 ms 37112 KB Output is correct
70 Correct 451 ms 51892 KB Output is correct
71 Correct 574 ms 57296 KB Output is correct