QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#62220#2544. Flatland CurrencyhinataWA 567ms22280kbC++143.3kb2022-11-17 17:10:572022-11-17 17:10:58

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-17 17:10:58]
  • 评测
  • 测评结果:WA
  • 用时:567ms
  • 内存:22280kb
  • [2022-11-17 17:10:57]
  • 提交

answer

#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define int long long

const int N = 1e5 + 10;
int val[N], cost[N], n, m, tot;
int ans;
int f[100005];

void DP(){
    for(int i = 1; i <= n ;++i){
        for(int j = m; j >= cost[i]; --j){
            f[j] = max(f[j], f[j - cost[i]] + val[i]);
        }
    }
    printf("%lld\n", f[m] + tot);
}

namespace BF2{
    const int MAXN = 1e6 + 10;
    vector<int> v[5];
    int f1[MAXN], f2[MAXN];
    void dfs1(int x, int now, int cot){
        // printf("dsgk %d %d %d\n", x, now, cot);
        if(cot > m) return;
        if(x > 2){
            // printf("dfs1 : %lld %lld\n", now, cot);
            f1[now] = min(f1[now], cot);
            return;
        }
        dfs1(x + 1, now, cot);
        for(int k = 0; k < v[x].size(); ++k){
            dfs1(x + 1, now + x * (k + 1), cot + v[x][k]);
        }
    }
    int find(int v){
        int l = 0, r = MAXN - 1;
        while(l < r){
            int mid = l + r + 1 >> 1;
            if(f2[mid] <= v) l = mid;
            else r = mid - 1;
        }
        return l;
    }
    void dfs2(int x, int now, int cot){
        if(cot > m) return;
        if(x > 4){
            f2[now] = min(f2[now], cot);
            return;
        }
        dfs2(x + 1, now, cot);
        for(int k = 0; k < v[x].size(); ++k){
            dfs2(x + 1, now + x * (k + 1), cot + v[x][k]);
        }
    }
    void solve(){
        for(int i = 1; i <= n; ++i){
            if(val[i] >= 0){
                v[val[i]].push_back(cost[i]);
            }
        }
        for(int i = 1; i <= 4; ++i){
            sort(v[i].begin(), v[i].end());
            for(int j = 1; j < v[i].size(); ++j){
                v[i][j] += v[i][j - 1];
                if(v[i][j] > 1e14 + 1) v[i][j] = 1e14 + 1;
            }
        }
        // for(int i = 1; i <= 4; ++i){
        //     printf("i = %lld\n", i);
        //     for(int j = 0; j < v[i].size(); ++j){
        //         printf("%lld ", v[i][j]);
        //     }
        //     printf("\n");
        // }
        // printf("m = %lld\n", m);
        memset(f1, 0x3f, sizeof(f1));
        memset(f2, 0x3f, sizeof(f2));
        dfs1(1, 0, 0);
        for(int i = MAXN - 2; i >= 0; --i){
            f1[i] = min(f1[i], f1[i + 1]);
        }
        f1[0] = 0;
        dfs2(3, 0, 0);
        for(int i = MAXN - 2; i >= 0; --i){
            f2[i] = min(f2[i], f2[i + 1]);
        }
        f2[0] = 0;
        for(int i = 0; i <= 60000; ++i){
            ans = max(ans, i + find(m - f1[i]));
        }
        // for(int i = 0; i <= )
        printf("%lld\n", ans + tot);
    }
}

signed main(){
    // freopen("DD.in", "r", stdin);
    // freopen("DD.out", "w", stdout);
    scanf("%lld %lld", &n, &m);
    tot = m % 5; m -= m % 5;
    for(int i = 1; i <= n; ++i){
        int x; scanf("%lld", &x);
        cost[i] = x + (5 - x % 5) % 5;
        val[i] = (5 - x % 5) % 5;
    }
    // for(int i = 1; i <= n; ++i) printf("%lld ", cost[i]); printf("\n");
    // for(int i = 1; i <= n; ++i) printf("%lld ", val[i]); printf("\n");

    // BF2::solve(); return 0;
    if(m <= 100000) DP();
    else BF2 :: solve();
 
    return 0;
}

/*
5 57
9 14 31 18 27

4 50
11 11 11 11
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 5604kb

input:

5 57
9 14 31 18 27

output:

8

result:

ok answer is '8'

Test #2:

score: 0
Accepted
time: 2ms
memory: 7608kb

input:

4 50
11 11 11 11

output:

12

result:

ok answer is '12'

Test #3:

score: 0
Accepted
time: 567ms
memory: 21968kb

input:

100000 89648823509660
921733427 402270498 51157221 585477094 435728758 913951087 580580944 557082810 585086423 837912728 799129405 867009344 751591136 714946046 464999915 256043168 416678301 183246216 569365122 479031618 435168577 31068363 903791719 497652990 960987871 223120213 395437892 112869678 ...

output:

200414

result:

ok answer is '200414'

Test #4:

score: 0
Accepted
time: 288ms
memory: 22180kb

input:

99999 3234700062922
394766137 401419056 55997758 205712163 585962152 750591556 245421581 607883471 437707305 758188075 522354844 202404802 307099733 99935245 321784033 643800024 481548024 43007287 404431495 848761213 352455926 541535791 702868758 875691279 485597478 119612707 776231855 48839061 1144...

output:

61505

result:

ok answer is '61505'

Test #5:

score: -100
Wrong Answer
time: 548ms
memory: 22280kb

input:

99998 86112926227914
869872247 684744959 824877228 56916375 758945367 128605666 283377693 33576989 443651099 153762116 163983342 366835792 816402292 863078123 487517337 884155303 155032070 26565182 354013355 820537114 239071699 443320558 470694592 531705267 151650392 734780493 229014960 750198362 64...

output:

199929

result:

wrong answer expected '200044', found '199929'