답안 #278015

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
278015 2020-08-21T08:47:18 Z 반딧불(#5119) Shopping Plans (CCO20_day2problem3) C++17
0 / 25
4000 ms 30872 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

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

ll hsh(vector<int>& v){
    ll ret = 0;
    for(auto &x: v) ret *= 26137, ret += x, ret %= 1000000007;
    return ret;
}

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];
    }

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

    for(int d=1; d<=k; 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 = hsh(tv);
            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));
            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:30:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |     scanf("%d %d %d", &n, &m, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   33 |         scanf("%d %lld", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   38 |         scanf("%d %d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4086 ms 30872 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4066 ms 30708 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4086 ms 30872 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 10368 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4086 ms 30872 KB Time limit exceeded
2 Halted 0 ms 0 KB -