#include<bits/stdc++.h>
#define X first
#define Y second
#define all(x) begin(x), end(x)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, b, a) for(int i = (b); i >= (a); i--)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define mxx max_element
#define mnn min_element
#define SQR(x) (1LL * (x) * (x))
#define MASK(i) (1LL << (i))
#define Point Vector
#define left Left
#define right Right
#define div Div
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef pair<db, db> pdb;
typedef pair<ld, ld> pld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef pair<ll, int> pli;
typedef pair<ll, pii> plii;
template<class A, class B>
bool maximize(A& x, B y) {
if (x < y) return x = y, true; else return false;
}
template<class A, class B>
bool minimize(A& x, B y) {
if (x > y) return x = y, true; else return false;
}
/* END OF TEMPLATE */
const int N = 2e5 + 7;
int p[N], u[N], d[N], n;
bool checkSub1() {
REP(i, 1, n)
if (p[i] != i - 1) return false;
return true;
}
namespace sub1 {
ll Process() {
ll res = 0, sum_t = 0;
REP(i, 0, n) {
sum_t+=d[i];
res+=1LL * u[i] * sum_t;
}
return res;
}
}
bool checkSub2() {
REP(i, 1, n)
if (p[i] != 0) return false;
// REP(i, 0, n)
// if (d[i] != 1) return false;
return true;
}
namespace sub2 {
ll Process() {
vector<int> node;
ll res = 0, sum_t = 0;
sum_t+=d[0];
res+=sum_t * u[0];
REP(i, 1, n) node.push_back(i);
sort(all(node), [=](int x, int y){
return u[x] > u[y];
});
for (auto x : node) {
sum_t+=d[x];
res+=sum_t * u[x];
}
return res;
}
}
namespace sub3 {
ll Process() {
vector<int> node;
ll res = 0, sum_t = 0;
sum_t+=d[0];
res+=sum_t * u[0];
REP(i, 1, n)
if (u[i] > 0) node.push_back(i);
sort(all(node), [=](int x, int y){
return (ld)d[x] / u[x] < (ld)d[y] / u[y];
});
for (auto x : node) {
sum_t+=d[x];
res+=sum_t * u[x];
}
return res;
}
}
int64_t scheduling_cost(vector<int> P, vector<int> U, vector<int> D) {
n = P.size();
REP(i, 0, n) {
p[i] = P[i];
u[i] = U[i];
d[i] = D[i];
}
if (checkSub1()) {
return sub1::Process();
}
if (checkSub2()) {
return sub3::Process();
}
}
Compilation message
job.cpp: In function 'int64_t scheduling_cost(std::vector<int>, std::vector<int>, std::vector<int>)':
job.cpp:122:1: warning: control reaches end of non-void function [-Wreturn-type]
122 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
12 ms |
2748 KB |
Output is correct |
6 |
Correct |
24 ms |
5452 KB |
Output is correct |
7 |
Correct |
35 ms |
8020 KB |
Output is correct |
8 |
Correct |
47 ms |
10584 KB |
Output is correct |
9 |
Correct |
59 ms |
10420 KB |
Output is correct |
10 |
Correct |
47 ms |
10564 KB |
Output is correct |
11 |
Correct |
0 ms |
596 KB |
Output is correct |
12 |
Correct |
47 ms |
10572 KB |
Output is correct |
13 |
Correct |
47 ms |
10580 KB |
Output is correct |
14 |
Correct |
47 ms |
10452 KB |
Output is correct |
15 |
Correct |
50 ms |
10588 KB |
Output is correct |
16 |
Correct |
49 ms |
10456 KB |
Output is correct |
17 |
Correct |
55 ms |
10580 KB |
Output is correct |
18 |
Correct |
49 ms |
10432 KB |
Output is correct |
19 |
Correct |
47 ms |
10444 KB |
Output is correct |
20 |
Correct |
47 ms |
10580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
82 ms |
10188 KB |
Output is correct |
5 |
Correct |
88 ms |
10364 KB |
Output is correct |
6 |
Correct |
81 ms |
10200 KB |
Output is correct |
7 |
Correct |
81 ms |
10292 KB |
Output is correct |
8 |
Correct |
81 ms |
10188 KB |
Output is correct |
9 |
Correct |
83 ms |
10184 KB |
Output is correct |
10 |
Correct |
88 ms |
10272 KB |
Output is correct |
11 |
Correct |
81 ms |
10188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
4 ms |
856 KB |
Output is correct |
6 |
Correct |
89 ms |
10956 KB |
Output is correct |
7 |
Correct |
90 ms |
10956 KB |
Output is correct |
8 |
Correct |
89 ms |
10952 KB |
Output is correct |
9 |
Correct |
91 ms |
10704 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
4 ms |
860 KB |
Output is correct |
13 |
Correct |
4 ms |
860 KB |
Output is correct |
14 |
Correct |
89 ms |
10832 KB |
Output is correct |
15 |
Correct |
97 ms |
10956 KB |
Output is correct |
16 |
Correct |
89 ms |
10952 KB |
Output is correct |
17 |
Correct |
88 ms |
10956 KB |
Output is correct |
18 |
Correct |
88 ms |
10952 KB |
Output is correct |
19 |
Correct |
89 ms |
10704 KB |
Output is correct |
20 |
Correct |
88 ms |
10952 KB |
Output is correct |
21 |
Correct |
89 ms |
10788 KB |
Output is correct |
22 |
Correct |
92 ms |
10976 KB |
Output is correct |
23 |
Correct |
88 ms |
10952 KB |
Output is correct |
24 |
Correct |
89 ms |
10952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
12 ms |
2748 KB |
Output is correct |
6 |
Correct |
24 ms |
5452 KB |
Output is correct |
7 |
Correct |
35 ms |
8020 KB |
Output is correct |
8 |
Correct |
47 ms |
10584 KB |
Output is correct |
9 |
Correct |
59 ms |
10420 KB |
Output is correct |
10 |
Correct |
47 ms |
10564 KB |
Output is correct |
11 |
Correct |
0 ms |
596 KB |
Output is correct |
12 |
Correct |
47 ms |
10572 KB |
Output is correct |
13 |
Correct |
47 ms |
10580 KB |
Output is correct |
14 |
Correct |
47 ms |
10452 KB |
Output is correct |
15 |
Correct |
50 ms |
10588 KB |
Output is correct |
16 |
Correct |
49 ms |
10456 KB |
Output is correct |
17 |
Correct |
55 ms |
10580 KB |
Output is correct |
18 |
Correct |
49 ms |
10432 KB |
Output is correct |
19 |
Correct |
47 ms |
10444 KB |
Output is correct |
20 |
Correct |
47 ms |
10580 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
82 ms |
10188 KB |
Output is correct |
25 |
Correct |
88 ms |
10364 KB |
Output is correct |
26 |
Correct |
81 ms |
10200 KB |
Output is correct |
27 |
Correct |
81 ms |
10292 KB |
Output is correct |
28 |
Correct |
81 ms |
10188 KB |
Output is correct |
29 |
Correct |
83 ms |
10184 KB |
Output is correct |
30 |
Correct |
88 ms |
10272 KB |
Output is correct |
31 |
Correct |
81 ms |
10188 KB |
Output is correct |
32 |
Correct |
0 ms |
600 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
4 ms |
856 KB |
Output is correct |
37 |
Correct |
89 ms |
10956 KB |
Output is correct |
38 |
Correct |
90 ms |
10956 KB |
Output is correct |
39 |
Correct |
89 ms |
10952 KB |
Output is correct |
40 |
Correct |
91 ms |
10704 KB |
Output is correct |
41 |
Correct |
0 ms |
344 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
4 ms |
860 KB |
Output is correct |
44 |
Correct |
4 ms |
860 KB |
Output is correct |
45 |
Correct |
89 ms |
10832 KB |
Output is correct |
46 |
Correct |
97 ms |
10956 KB |
Output is correct |
47 |
Correct |
89 ms |
10952 KB |
Output is correct |
48 |
Correct |
88 ms |
10956 KB |
Output is correct |
49 |
Correct |
88 ms |
10952 KB |
Output is correct |
50 |
Correct |
89 ms |
10704 KB |
Output is correct |
51 |
Correct |
88 ms |
10952 KB |
Output is correct |
52 |
Correct |
89 ms |
10788 KB |
Output is correct |
53 |
Correct |
92 ms |
10976 KB |
Output is correct |
54 |
Correct |
88 ms |
10952 KB |
Output is correct |
55 |
Correct |
89 ms |
10952 KB |
Output is correct |
56 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
57 |
Halted |
0 ms |
0 KB |
- |