답안 #600591

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
600591 2022-07-21T05:58:37 Z 반딧불(#8467) Long Distance Coach (JOI17_coach) C++17
0 / 100
0 ms 340 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll X, W, T;
int n, k;
ll arr[200002];
ll off[200002], cost[200002];
ll DP[12][600];
ll ans = 1e18;

int main(){
    scanf("%lld %d %d %lld %lld", &X, &k, &n, &W, &T);
    for(int i=1; i<=k; i++) scanf("%lld", &arr[i]);
    arr[++k] = X;
    for(int i=0; i<n; i++) scanf("%lld %lld", &off[i], &cost[i]);
    for(int i=0; i<=k; i++) for(int j=0; j<600; j++) DP[i][j] = 1e18;
    DP[0][(1<<n)-1] = W;
    for(int i=1; i<=k; i++){ /// ���� ������ ��ȣ
        vector<pair<ll, int> > last;
        ll now = arr[i];
        for(int j=0; j<n; j++){
            if(now%T < off[j] || (now - now%T + off[j] < arr[i-1])) continue;
            last.push_back(make_pair(now - (now%T - off[j]), j));
        }
        sort(last.rbegin(), last.rend()); /// ������ prefix�� ���� ����

        ll addedCost[12] = {0};
        ll driverCost = ((arr[i] / T) - (arr[i-1] / T)) * W;
        for(int j=0; j<n; j++){
            addedCost[j] = ((arr[i] - off[j] + T) / T - (arr[i-1] - off[j] + T) / T) * W;
        }

        for(int j=0; j<(1<<n); j++){
            ll basic = DP[i-1][j] + driverCost;
            for(int s=0; s<n; s++) if((j>>s)&1) basic += addedCost[s];
            int newJ = j;
            for(int s=0; s<(int)last.size(); s++){
                int x = last[s].second;
                if(!(j&(1<<x))) continue;
                newJ ^= (1<<x), basic += cost[x] - W;
                DP[i][newJ] = min(DP[i][newJ], basic);
            }
        }
    }

    for(int i=1; i<=k; i++) for(int j=0; j<(1<<n); j++){
//        printf("%d %d: %lld\n", i, j, DP[i][j]);
    }

    for(int i=0; i<600; i++) ans = min(ans, DP[k][i]);
    printf("%lld", ans);
}

Compilation message

coach.cpp: In function 'int main()':
coach.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%lld %d %d %lld %lld", &X, &k, &n, &W, &T);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
coach.cpp:16:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     for(int i=1; i<=k; i++) scanf("%lld", &arr[i]);
      |                             ~~~~~^~~~~~~~~~~~~~~~~
coach.cpp:18:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     for(int i=0; i<n; i++) scanf("%lld %lld", &off[i], &cost[i]);
      |                            ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -