Submission #825193

# Submission time Handle Problem Language Result Execution time Memory
825193 2023-08-14T15:27:39 Z Amylopectin Let's Win the Election (JOI22_ho_t3) C++14
100 / 100
101 ms 4280 KB
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
const int mxn = 2010,mxi = 1e9 + 10;
struct we
{
    double aa,bb;
    int idx;
};
bool cmp1(const struct we &l,const struct we &r)
{
    return l.aa < r.aa;
}
bool cmp2(const struct we &l,const struct we &r)
{
    if(l.bb == -1)
    {
        return false;
    }
    if(r.bb == -1)
    {
        return true;
    }
    if(l.bb == r.bb)
    {
        return l.aa > r.aa;
    }
    return l.bb < r.bb;
}
struct we soa[mxn] = {},sob[mxn] = {};
int u[mxn] = {};
double dp[mxn][mxn] = {};
int main()
{
    int i,j,k,o,n,m,cn,cm,fn,fm,cru,fru,cou;
    double cva,cmi = mxi,f,p,csu;
    scanf("%d %d",&n,&m);
    for(i=0; i<n; i++)
    {
        scanf("%lf %lf",&soa[i].aa,&soa[i].bb);
    }
    sort(soa,soa+n,cmp1);
    for(i=0; i<n; i++)
    {
        soa[i].idx = i;
        sob[i] = {soa[i].aa,soa[i].bb,i};
    }
    sort(sob,sob+n,cmp2);
    cru = n;
    for(i=0; i<n; i++)
    {
        if(sob[i].bb == -1)
        {
            cru = i;
            break;
        }
    }

    for(i=0; i<=min(cru,m); i++)
    {
        f = i+1;
        dp[0][0] = sob[0].aa / f;
        dp[0][1] = sob[0].bb;
        for(j=2; j<=i; j++)
        {
            dp[0][j] = mxi;
        }
        for(j=0; j<n; j++)
        {
            u[j] = 0;
        }
        fru = m;
        cou = m;
        csu = 0;
        for(j=0; j<m; j++)
        {
            csu += soa[j].aa / f;
        }
        if(i == 0)
        {
            cmi = min(cmi,csu);
        }
        for(j=0; j<min(cru,m); j++)
        {
            if(j > 0)
            {
                for(k=0; k<=i; k++)
                {
                    dp[j][k] = dp[j-1][k] + sob[j].aa / f;
                    if(k > 0)
                    {
                        p = k;
                        dp[j][k] = min(dp[j][k],dp[j-1][k-1] + sob[j].bb / p);
                    }
                }
            }
            if(sob[j].idx >= fru)
            {
                while(u[fru-1] == 1)
                {
                    fru --;
                }
                csu -= soa[fru-1].aa / f;
                fru --;
            }
            else 
            {
                csu -= sob[j].aa / f;
            }
            u[sob[j].idx] = 1;
            cmi = min(cmi,dp[j][i] + csu);
        } 
    }
    printf("%lf\n",cmi);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:36:15: warning: unused variable 'o' [-Wunused-variable]
   36 |     int i,j,k,o,n,m,cn,cm,fn,fm,cru,fru,cou;
      |               ^
Main.cpp:36:21: warning: unused variable 'cn' [-Wunused-variable]
   36 |     int i,j,k,o,n,m,cn,cm,fn,fm,cru,fru,cou;
      |                     ^~
Main.cpp:36:24: warning: unused variable 'cm' [-Wunused-variable]
   36 |     int i,j,k,o,n,m,cn,cm,fn,fm,cru,fru,cou;
      |                        ^~
Main.cpp:36:27: warning: unused variable 'fn' [-Wunused-variable]
   36 |     int i,j,k,o,n,m,cn,cm,fn,fm,cru,fru,cou;
      |                           ^~
Main.cpp:36:30: warning: unused variable 'fm' [-Wunused-variable]
   36 |     int i,j,k,o,n,m,cn,cm,fn,fm,cru,fru,cou;
      |                              ^~
Main.cpp:36:41: warning: variable 'cou' set but not used [-Wunused-but-set-variable]
   36 |     int i,j,k,o,n,m,cn,cm,fn,fm,cru,fru,cou;
      |                                         ^~~
Main.cpp:37:12: warning: unused variable 'cva' [-Wunused-variable]
   37 |     double cva,cmi = mxi,f,p,csu;
      |            ^~~
Main.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
Main.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         scanf("%lf %lf",&soa[i].aa,&soa[i].bb);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 4 ms 1108 KB Output is correct
13 Correct 4 ms 1108 KB Output is correct
14 Correct 2 ms 724 KB Output is correct
15 Correct 38 ms 2620 KB Output is correct
16 Correct 22 ms 2100 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 101 ms 4264 KB Output is correct
19 Correct 24 ms 2260 KB Output is correct
20 Correct 2 ms 696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 308 KB Output is correct
22 Correct 0 ms 312 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 308 KB Output is correct
37 Correct 0 ms 312 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 308 KB Output is correct
22 Correct 0 ms 312 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 308 KB Output is correct
37 Correct 0 ms 312 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 1 ms 596 KB Output is correct
48 Correct 1 ms 596 KB Output is correct
49 Correct 1 ms 596 KB Output is correct
50 Correct 1 ms 696 KB Output is correct
51 Correct 2 ms 724 KB Output is correct
52 Correct 1 ms 596 KB Output is correct
53 Correct 1 ms 564 KB Output is correct
54 Correct 1 ms 596 KB Output is correct
55 Correct 1 ms 596 KB Output is correct
56 Correct 1 ms 596 KB Output is correct
57 Correct 1 ms 596 KB Output is correct
58 Correct 1 ms 596 KB Output is correct
59 Correct 1 ms 596 KB Output is correct
60 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 99 ms 4172 KB Output is correct
2 Correct 100 ms 4280 KB Output is correct
3 Correct 100 ms 4224 KB Output is correct
4 Correct 99 ms 4228 KB Output is correct
5 Correct 100 ms 4176 KB Output is correct
6 Correct 99 ms 4268 KB Output is correct
7 Correct 100 ms 4256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 4 ms 1108 KB Output is correct
13 Correct 4 ms 1108 KB Output is correct
14 Correct 2 ms 724 KB Output is correct
15 Correct 38 ms 2620 KB Output is correct
16 Correct 22 ms 2100 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 101 ms 4264 KB Output is correct
19 Correct 24 ms 2260 KB Output is correct
20 Correct 2 ms 696 KB Output is correct
21 Correct 1 ms 312 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 304 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 308 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 308 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 308 KB Output is correct
36 Correct 1 ms 312 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 0 ms 308 KB Output is correct
42 Correct 0 ms 312 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 0 ms 340 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 0 ms 340 KB Output is correct
51 Correct 0 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 0 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 308 KB Output is correct
57 Correct 0 ms 312 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 0 ms 340 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 468 KB Output is correct
66 Correct 1 ms 468 KB Output is correct
67 Correct 1 ms 596 KB Output is correct
68 Correct 1 ms 596 KB Output is correct
69 Correct 1 ms 596 KB Output is correct
70 Correct 1 ms 696 KB Output is correct
71 Correct 2 ms 724 KB Output is correct
72 Correct 1 ms 596 KB Output is correct
73 Correct 1 ms 564 KB Output is correct
74 Correct 1 ms 596 KB Output is correct
75 Correct 1 ms 596 KB Output is correct
76 Correct 1 ms 596 KB Output is correct
77 Correct 1 ms 596 KB Output is correct
78 Correct 1 ms 596 KB Output is correct
79 Correct 1 ms 596 KB Output is correct
80 Correct 1 ms 596 KB Output is correct
81 Correct 99 ms 4172 KB Output is correct
82 Correct 100 ms 4280 KB Output is correct
83 Correct 100 ms 4224 KB Output is correct
84 Correct 99 ms 4228 KB Output is correct
85 Correct 100 ms 4176 KB Output is correct
86 Correct 99 ms 4268 KB Output is correct
87 Correct 100 ms 4256 KB Output is correct
88 Correct 1 ms 568 KB Output is correct
89 Correct 1 ms 468 KB Output is correct
90 Correct 2 ms 948 KB Output is correct
91 Correct 2 ms 852 KB Output is correct
92 Correct 14 ms 1792 KB Output is correct
93 Correct 14 ms 1816 KB Output is correct
94 Correct 47 ms 2908 KB Output is correct
95 Correct 43 ms 2900 KB Output is correct
96 Correct 73 ms 3656 KB Output is correct
97 Correct 74 ms 3684 KB Output is correct
98 Correct 35 ms 2584 KB Output is correct
99 Correct 35 ms 2612 KB Output is correct
100 Correct 35 ms 2680 KB Output is correct
101 Correct 35 ms 2616 KB Output is correct
102 Correct 35 ms 2588 KB Output is correct
103 Correct 35 ms 2664 KB Output is correct
104 Correct 38 ms 2588 KB Output is correct
105 Correct 38 ms 2572 KB Output is correct