Submission #248341

# Submission time Handle Problem Language Result Execution time Memory
248341 2020-07-12T09:17:23 Z tqbfjotld Minerals (JOI19_minerals) C++14
100 / 100
648 ms 4724 KB
#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;

int pr = 0;
int memo[43005];
int frac[43005];
vector<pair<int,int> > answers;

int dp(int num){ ///determine what ratio to split a group of num materials
    if (num<=1) return 0;
    if (memo[num]!=-1) return memo[num];
    int mn = 999999999;
    int ans = -1;
    for (int x = max(1,num/3); x<=num/2; x++){
        int opt = dp(x)+dp(num-x)+x+num-1;
        if (opt<mn){
            ans = x;
            mn = opt;
        }
    }
    frac[num] = ans;
    return memo[num] = mn;
}

void rec(vector<int> g1, vector<int> g2, bool on){
    if (g1.size()==1){
        answers.push_back({g1[0],g2[0]});
        return;
    }
    /*printf("g1: ");
    for (int x : g1){
        printf("%d ",x);
    }
    printf("\n");
    printf("g2: ");
    for (int x : g2){
        printf("%d ",x);
    }
    printf("\n");*/
    int spl = frac[g1.size()];
    //printf("split %d\n",spl);
    vector<int> g2l,g2r;
    vector<int> g1l,g1r;
    for (int x = 0; x<g1.size(); x++){
        if (x<spl){
            pr = Query(g1[x]);
            g1l.push_back(g1[x]);
        }
        else
            g1r.push_back(g1[x]);
    }
    int cnt = 0;
    for (int x = 1; x<g2.size(); x++){ ///last one can be inferred from remaining, saves 1 query per recurse
        int t = Query(g2[x]);
        if (t!=pr){
            if (on){
                g2l.push_back(g2[x]);
                cnt++;
            }
            else{
                g2r.push_back(g2[x]);
            }
        }
        else{
            if (on){
                g2r.push_back(g2[x]);
            }
            else{
                g2l.push_back(g2[x]);
                cnt++;
            }
        }
        pr = t;
    }
    if (cnt<spl){
        g2l.push_back(g2[0]);
    }
    else{
        g2r.push_back(g2[0]);
    }
    rec(g1l,g2l,!on);
    rec(g1r,g2r,on);
}


void Solve(int N) {

    vector<int> gr1;
    vector<int> gr2;
    for (int i = 1; i<=2*N; i++){
        int t = Query(i);
        if (t==pr){
            gr2.push_back(i);
        }
        else{
            gr1.push_back(i);
        }
        pr = t;
    }
    memset(memo,-1,sizeof(memo));
    for (int x = 1; x<=N; x++){
        dp(x);
    }
    rec(gr1,gr2,true);

    for (auto x : answers) {
        Answer(x.first,x.second);
    }
}

Compilation message

minerals.cpp: In function 'void rec(std::vector<int>, std::vector<int>, bool)':
minerals.cpp:45:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int x = 0; x<g1.size(); x++){
                     ~^~~~~~~~~~
minerals.cpp:54:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int x = 1; x<g2.size(); x++){ ///last one can be inferred from remaining, saves 1 query per recurse
                     ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 512 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 0 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 640 KB Output is correct
2 Correct 4 ms 640 KB Output is correct
3 Correct 12 ms 896 KB Output is correct
4 Correct 35 ms 1272 KB Output is correct
5 Correct 99 ms 1948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 512 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 0 ms 512 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 4 ms 640 KB Output is correct
7 Correct 12 ms 896 KB Output is correct
8 Correct 35 ms 1272 KB Output is correct
9 Correct 99 ms 1948 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 47 ms 1476 KB Output is correct
12 Correct 93 ms 1976 KB Output is correct
13 Correct 89 ms 2056 KB Output is correct
14 Correct 92 ms 2060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 512 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 0 ms 512 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 4 ms 640 KB Output is correct
7 Correct 12 ms 896 KB Output is correct
8 Correct 35 ms 1272 KB Output is correct
9 Correct 99 ms 1948 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 47 ms 1476 KB Output is correct
12 Correct 93 ms 1976 KB Output is correct
13 Correct 89 ms 2056 KB Output is correct
14 Correct 92 ms 2060 KB Output is correct
15 Correct 521 ms 4420 KB Output is correct
16 Correct 522 ms 4340 KB Output is correct
17 Correct 509 ms 4344 KB Output is correct
18 Correct 517 ms 4472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 512 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 0 ms 512 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 4 ms 640 KB Output is correct
7 Correct 12 ms 896 KB Output is correct
8 Correct 35 ms 1272 KB Output is correct
9 Correct 99 ms 1948 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 47 ms 1476 KB Output is correct
12 Correct 93 ms 1976 KB Output is correct
13 Correct 89 ms 2056 KB Output is correct
14 Correct 92 ms 2060 KB Output is correct
15 Correct 521 ms 4420 KB Output is correct
16 Correct 522 ms 4340 KB Output is correct
17 Correct 509 ms 4344 KB Output is correct
18 Correct 517 ms 4472 KB Output is correct
19 Correct 560 ms 4416 KB Output is correct
20 Correct 537 ms 4544 KB Output is correct
21 Correct 526 ms 4480 KB Output is correct
22 Correct 533 ms 4224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 512 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 0 ms 512 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 4 ms 640 KB Output is correct
7 Correct 12 ms 896 KB Output is correct
8 Correct 35 ms 1272 KB Output is correct
9 Correct 99 ms 1948 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 47 ms 1476 KB Output is correct
12 Correct 93 ms 1976 KB Output is correct
13 Correct 89 ms 2056 KB Output is correct
14 Correct 92 ms 2060 KB Output is correct
15 Correct 521 ms 4420 KB Output is correct
16 Correct 522 ms 4340 KB Output is correct
17 Correct 509 ms 4344 KB Output is correct
18 Correct 517 ms 4472 KB Output is correct
19 Correct 560 ms 4416 KB Output is correct
20 Correct 537 ms 4544 KB Output is correct
21 Correct 526 ms 4480 KB Output is correct
22 Correct 533 ms 4224 KB Output is correct
23 Correct 568 ms 4340 KB Output is correct
24 Correct 559 ms 4600 KB Output is correct
25 Correct 571 ms 4484 KB Output is correct
26 Correct 552 ms 4172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 512 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 0 ms 512 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 4 ms 640 KB Output is correct
7 Correct 12 ms 896 KB Output is correct
8 Correct 35 ms 1272 KB Output is correct
9 Correct 99 ms 1948 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 47 ms 1476 KB Output is correct
12 Correct 93 ms 1976 KB Output is correct
13 Correct 89 ms 2056 KB Output is correct
14 Correct 92 ms 2060 KB Output is correct
15 Correct 521 ms 4420 KB Output is correct
16 Correct 522 ms 4340 KB Output is correct
17 Correct 509 ms 4344 KB Output is correct
18 Correct 517 ms 4472 KB Output is correct
19 Correct 560 ms 4416 KB Output is correct
20 Correct 537 ms 4544 KB Output is correct
21 Correct 526 ms 4480 KB Output is correct
22 Correct 533 ms 4224 KB Output is correct
23 Correct 568 ms 4340 KB Output is correct
24 Correct 559 ms 4600 KB Output is correct
25 Correct 571 ms 4484 KB Output is correct
26 Correct 552 ms 4172 KB Output is correct
27 Correct 591 ms 4436 KB Output is correct
28 Correct 645 ms 4564 KB Output is correct
29 Correct 576 ms 4452 KB Output is correct
30 Correct 582 ms 4296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 512 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 0 ms 512 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 4 ms 640 KB Output is correct
7 Correct 12 ms 896 KB Output is correct
8 Correct 35 ms 1272 KB Output is correct
9 Correct 99 ms 1948 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 47 ms 1476 KB Output is correct
12 Correct 93 ms 1976 KB Output is correct
13 Correct 89 ms 2056 KB Output is correct
14 Correct 92 ms 2060 KB Output is correct
15 Correct 521 ms 4420 KB Output is correct
16 Correct 522 ms 4340 KB Output is correct
17 Correct 509 ms 4344 KB Output is correct
18 Correct 517 ms 4472 KB Output is correct
19 Correct 560 ms 4416 KB Output is correct
20 Correct 537 ms 4544 KB Output is correct
21 Correct 526 ms 4480 KB Output is correct
22 Correct 533 ms 4224 KB Output is correct
23 Correct 568 ms 4340 KB Output is correct
24 Correct 559 ms 4600 KB Output is correct
25 Correct 571 ms 4484 KB Output is correct
26 Correct 552 ms 4172 KB Output is correct
27 Correct 591 ms 4436 KB Output is correct
28 Correct 645 ms 4564 KB Output is correct
29 Correct 576 ms 4452 KB Output is correct
30 Correct 582 ms 4296 KB Output is correct
31 Correct 621 ms 4476 KB Output is correct
32 Correct 621 ms 4724 KB Output is correct
33 Correct 620 ms 4596 KB Output is correct
34 Correct 627 ms 4304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 512 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 0 ms 512 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 4 ms 640 KB Output is correct
7 Correct 12 ms 896 KB Output is correct
8 Correct 35 ms 1272 KB Output is correct
9 Correct 99 ms 1948 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 47 ms 1476 KB Output is correct
12 Correct 93 ms 1976 KB Output is correct
13 Correct 89 ms 2056 KB Output is correct
14 Correct 92 ms 2060 KB Output is correct
15 Correct 521 ms 4420 KB Output is correct
16 Correct 522 ms 4340 KB Output is correct
17 Correct 509 ms 4344 KB Output is correct
18 Correct 517 ms 4472 KB Output is correct
19 Correct 560 ms 4416 KB Output is correct
20 Correct 537 ms 4544 KB Output is correct
21 Correct 526 ms 4480 KB Output is correct
22 Correct 533 ms 4224 KB Output is correct
23 Correct 568 ms 4340 KB Output is correct
24 Correct 559 ms 4600 KB Output is correct
25 Correct 571 ms 4484 KB Output is correct
26 Correct 552 ms 4172 KB Output is correct
27 Correct 591 ms 4436 KB Output is correct
28 Correct 645 ms 4564 KB Output is correct
29 Correct 576 ms 4452 KB Output is correct
30 Correct 582 ms 4296 KB Output is correct
31 Correct 621 ms 4476 KB Output is correct
32 Correct 621 ms 4724 KB Output is correct
33 Correct 620 ms 4596 KB Output is correct
34 Correct 627 ms 4304 KB Output is correct
35 Correct 642 ms 4524 KB Output is correct
36 Correct 648 ms 4552 KB Output is correct
37 Correct 636 ms 4548 KB Output is correct
38 Correct 642 ms 4364 KB Output is correct