제출 #163085

#제출 시각아이디문제언어결과실행 시간메모리
163085georgerapeanuNaan (JOI19_naan)C++11
24 / 100
9 ms400 KiB
#include <cstdio>
#include <algorithm>

using namespace std;

const int NMAX = 2000;
const int LMAX = 2000;
const int NUM_LIM = 2e7;

int n,l;
int v[NMAX + 5][LMAX + 5];
bool taken[NMAX + 5];
int perm[NMAX + 5];

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

    return gcd(b,a % b);
}

long long lst_cost[NMAX + 5]; /// apromiated real value * NUM_LIM
long long target_cost[NMAX + 5];
long long  split[NMAX + 5];

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]);
            target_cost[i] = target_cost[i] + v[i][j] * NUM_LIM;
        }
        target_cost[i] = (target_cost[i] / n + (target_cost[i] % n != 0));
    }

    long long last_pos = 0;

    int cnt_splits = 0;

    while(cnt_splits < n - 1){
        bool expand = false;
        for(int i = 1;i <= n;i++){
            if(taken[i]){
                continue;
            }
            lst_cost[i] = lst_cost[i] + ((last_pos / NUM_LIM + 1) * NUM_LIM - last_pos) * v[i][last_pos / NUM_LIM + 1];
            expand |= (target_cost[i] <= lst_cost[i]);
        }


        last_pos = (last_pos / NUM_LIM + 1) * NUM_LIM;

        if(expand == false){
            continue;
        }

        long long bst_frac = 0;
        int id = -1;

        for(int i = 1;i <= n;i++){
            if(taken[i]){
                continue;
            }
            if(target_cost[i] <= lst_cost[i]){
                long long tmp = lst_cost[i] - target_cost[i];
                tmp = tmp / v[i][last_pos / NUM_LIM] + (tmp % v[i][last_pos / NUM_LIM] != 0);
                if(id == -1 || bst_frac <= tmp){
                    bst_frac = tmp;
                    id = i;
                }
            }
        }
       
        last_pos = last_pos - bst_frac;

        for(int i = 1;i <= n;i++){
            if(taken[i]){
                continue;
            }
            lst_cost[i] = 0;
        }

        split[++cnt_splits] = last_pos;
        taken[id] = true;
        perm[cnt_splits] = id;
    }

    for(int i = 1;i <= n;i++){
        if(taken[i] == false){
            perm[n] = i;
        }
    }

    for(int i = 1;i < n;i++){
        printf("%lld %lld\n",split[i] / gcd(split[i],NUM_LIM),(long long)(NUM_LIM / gcd(split[i],NUM_LIM)));
    }

    for(int i = 1;i <= n;i++){
        printf("%d ",perm[i]);
    }

    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

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]);
             ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...