답안 #163942

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
163942 2019-11-16T11:14:37 Z georgerapeanu Naan (JOI19_naan) C++11
100 / 100
1852 ms 101024 KB
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

const int NMAX = 2000;
const int LMAX = 2000;

int n,l;
int v[NMAX + 5][LMAX + 5];
pair<long long,long long> split[NMAX + 5][NMAX + 5];
long long sum[NMAX + 5];
bool seen[NMAX + 5];
vector<int> perm;

long long gcd(long long a,long long b){
    if(!b){
        return a;
    }
    return gcd(b,a % b);
}

bool cmp_frac(const pair<long long,long long> &a,const pair<long long,long long> &b){
    return (long double)a.first / a.second < (long double)b.first / b.second;
}

int main(){

    scanf("%d %d",&n,&l);

    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= l;j++){
            scanf("%d",&v[i][j]);
            sum[i] += v[i][j];
        }
    }

    for(int i = 1;i <= n;i++){
        long long curr = 0;
        int last = 0;

        for(int j = 1;j <= n;j++){
            while(last < l && cmp_frac({curr,1},{sum[i] * j,n})){
                last++;
                curr += v[i][last];
            }
            if(j == n){
                split[i][j] = {l,1};
            }
            else{
                split[i][j] = {1LL * last * n * v[i][last] + sum[i] * j - curr * n,n * v[i][last]};
            }
        }
    }

    for(int i = 1;i <= n;i++){
        int id = -1;
        for(int j = 1;j <= n;j++){
            long long g = gcd(split[j][i].first,split[j][i].second);
            split[j][i].first /= g;
            split[j][i].second /= g;
            if(seen[j]){
                continue;
            }
            if(id == -1 || cmp_frac(split[j][i],split[id][i])){
                id = j;
            }
        }

        if(i < n){
            printf("%lld %lld\n",split[id][i].first,split[id][i].second);
        }
        perm.push_back(id);
        seen[id] = true;
    }

    for(auto it:perm){
        printf("%d ",it);
    }

    return 0;
}

Compilation message

naan.cpp: In function 'int main()':
naan.cpp:30: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:34: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 252 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 4 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 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 3 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 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 3 ms 380 KB Output is correct
6 Correct 2 ms 248 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 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 2 ms 336 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 3 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 3 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 3 ms 376 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 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 4 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 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 3 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 3 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 380 KB Output is correct
21 Correct 2 ms 248 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 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 2 ms 336 KB Output is correct
28 Correct 3 ms 376 KB Output is correct
29 Correct 3 ms 376 KB Output is correct
30 Correct 3 ms 376 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
33 Correct 3 ms 376 KB Output is correct
34 Correct 3 ms 376 KB Output is correct
35 Correct 3 ms 376 KB Output is correct
36 Correct 3 ms 376 KB Output is correct
37 Correct 3 ms 376 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 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 3 ms 376 KB Output is correct
43 Correct 164 ms 11004 KB Output is correct
44 Correct 990 ms 55836 KB Output is correct
45 Correct 358 ms 23680 KB Output is correct
46 Correct 34 ms 3196 KB Output is correct
47 Correct 594 ms 35448 KB Output is correct
48 Correct 1534 ms 72168 KB Output is correct
49 Correct 319 ms 22008 KB Output is correct
50 Correct 1814 ms 83452 KB Output is correct
51 Correct 586 ms 33708 KB Output is correct
52 Correct 1472 ms 73804 KB Output is correct
53 Correct 1347 ms 69680 KB Output is correct
54 Correct 3 ms 376 KB Output is correct
55 Correct 722 ms 43512 KB Output is correct
56 Correct 824 ms 46448 KB Output is correct
57 Correct 674 ms 40936 KB Output is correct
58 Correct 1237 ms 69996 KB Output is correct
59 Correct 656 ms 37468 KB Output is correct
60 Correct 1575 ms 100880 KB Output is correct
61 Correct 1602 ms 100972 KB Output is correct
62 Correct 1851 ms 100792 KB Output is correct
63 Correct 1709 ms 101024 KB Output is correct
64 Correct 1630 ms 100980 KB Output is correct
65 Correct 1852 ms 87544 KB Output is correct
66 Correct 1850 ms 87608 KB Output is correct
67 Correct 1639 ms 87624 KB Output is correct
68 Correct 635 ms 52840 KB Output is correct
69 Correct 592 ms 46956 KB Output is correct
70 Correct 806 ms 64504 KB Output is correct
71 Correct 970 ms 69876 KB Output is correct