답안 #278022

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
278022 2020-08-21T08:57:51 Z 반딧불(#5119) Shopping Plans (CCO20_day2problem3) C++17
0 / 25
212 ms 19052 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;

typedef long long ll;

struct dat{
    ll a, b, c, d;
    dat(ll a, ll b, ll c, ll d): a(a), b(b), c(c), d(d){}
    bool operator<(const dat &r)const{
        return a>r.a;
    }
};

int n, m, k;
vector<ll> arr[4002];
priority_queue<dat> pq;
ll ans[4002];
ll weight[4002];
vector<int> ansVec[4002];
set<ll> st;
ll sum = 0;

int main(){
    scanf("%d %d %d", &n, &m, &k);
    for(int i=1; i<=n; i++){
        int x; ll y;
        scanf("%d %lld", &x, &y);
        arr[x].push_back(y);
    }
    for(int i=1; i<=m; i++){
        int x, y;
        scanf("%d %d", &x, &y);
    }

    for(int i=1; i<=m; i++) sort(arr[i].begin(), arr[i].end());
    for(int i=1; i<=m; i++){
        if(arr[i].empty()){
            while(k--) printf("-1\n");
            return 0;
        }
        sum += arr[i][0];
    }

    for(int i=0; i<m; i++){
        weight[i] = rand();
    }

    vector<int> zeroVec (m, 0);
    st.insert(0);
    pq.push(dat(sum, 0, 0, 0));

    k = min(k, 200);

    for(int d=1; d<=k; d++){
//        printf("%d ", d);
        if(pq.empty()) break;
        auto tmp = pq.top(); pq.pop();

        vector<int> tv;
        if(!tmp.b) tv = zeroVec;
        else{
            tv = ansVec[tmp.b];
            tv[tmp.c]++;
        }
        ansVec[d] = tv;

        ans[d] = tmp.a;
        for(int i=0; i<m; i++){
            if(tv[i] == (int)arr[i+1].size()-1) continue;
            tv[i]++;
            ll tsh = tmp.d + weight[i] * (arr[i+1][tv[i]] - arr[i+1][tv[i]-1]);
            if(st.find(tsh) == st.end())
                st.insert(tsh), pq.push(dat(tmp.a + arr[i+1][tv[i]] - arr[i+1][tv[i]-1], d, i, tsh));
            tv[i]--;
        }
    }

    for(int d=1; d<=k; d++){
        printf("%lld\n", ans[d] ? ans[d] : -1);
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   28 |     scanf("%d %d %d", &n, &m, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   31 |         scanf("%d %lld", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   36 |         scanf("%d %d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 191 ms 18480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 212 ms 19052 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 191 ms 18480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 1152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 191 ms 18480 KB Output isn't correct
2 Halted 0 ms 0 KB -