QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#138469 | #4363. Branch Assignment | PetroTarnavskyi# | TL | 132ms | 203084kb | C++17 | 1.5kb | 2023-08-11 19:33:47 | 2023-08-11 19:33:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FILL(a, b) memset(a, b, sizeof(a))
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int N = 5000 + 47;
vector<PII> g[2][N];
int d[2][N];
LL dp[N][N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n, b, groups, m;
cin >> n >> b >> groups >> m;
FOR(i, 0, m){
int u, v, w;
cin >> u >> v >> w;
u--; v--;
g[0][u].PB(MP(v, w));
g[1][v].PB(MP(u, w));
}
FOR(t, 0, 2){
FOR(i, 0, n)
d[t][i] = 1e9;
d[t][b] = 0;
set<PII> q;
q.insert(MP(0, b));
while(SZ(q)){
int v = q.begin()->S;
q.erase(q.begin());
for(auto [to, w] : g[t][v]){
if(d[t][to] <= d[t][v] + w)
continue;
q.erase(MP(d[t][to], to));
d[t][to] = d[t][v] + w;
q.insert(MP(d[t][to], to));
}
}
}
FOR(i, 0, n)
d[0][i] += d[1][i];
sort(d[0], d[0] + b);
n = b;
FOR(i, 0, N)
FOR(j, 0, N)
dp[i][j] = 1e18;
dp[0][0] = 0;
vector<LL> pref(n + 1, 0);
FOR(i, 0, n)
pref[i + 1] = pref[i] + d[0][i];
FOR(k, 0, groups){
FOR(i, 1, n + 1)
{
FOR (j, 0, i)
dp[i][k + 1] = min(dp[i][k + 1], (pref[i] - pref[j]) * (i - j - 1) + dp[j][k]);
}
}
cout << dp[n][groups] << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 202776kb
input:
5 4 2 10 5 2 1 2 5 1 3 5 5 4 5 0 1 5 1 2 3 1 3 2 5 2 4 5 2 1 1 3 4 2
output:
13
result:
ok single line: '13'
Test #2:
score: 0
Accepted
time: 1ms
memory: 202704kb
input:
5 4 2 10 5 2 1 2 5 1 3 5 5 4 5 10 1 5 1 2 3 1 3 2 5 2 4 5 2 1 1 3 4 2
output:
24
result:
ok single line: '24'
Test #3:
score: 0
Accepted
time: 12ms
memory: 202712kb
input:
5 4 3 8 1 5 15 5 1 15 2 5 2 5 2 3 3 5 1 5 3 1 4 5 2 5 4 0
output:
4
result:
ok single line: '4'
Test #4:
score: 0
Accepted
time: 12ms
memory: 202772kb
input:
2 1 1 2 1 2 5 2 1 3
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 12ms
memory: 202772kb
input:
9 4 2 11 1 2 1 2 3 2 3 4 3 4 6 4 6 8 5 8 9 6 9 7 7 7 5 8 5 8 8 7 6 9 6 1 10
output:
304
result:
ok single line: '304'
Test #6:
score: 0
Accepted
time: 132ms
memory: 203084kb
input:
5000 4999 2 9998 1 2 10000 2 1 10000 2 3 10000 3 2 10000 3 4 10000 4 3 10000 4 5 10000 5 4 10000 5 6 10000 6 5 10000 6 7 10000 7 6 10000 7 8 10000 8 7 10000 8 9 10000 9 8 10000 9 10 10000 10 9 10000 10 11 10000 11 10 10000 11 12 10000 12 11 10000 12 13 10000 13 12 10000 13 14 10000 14 13 10000 14 15...
output:
589335814500000
result:
ok single line: '589335814500000'
Test #7:
score: -100
Time Limit Exceeded
input:
5000 4999 100 9998 1 2 1 2 3 1 3 4 1 4 5 1 5 6 1 6 7 1 7 8 1 8 9 1 9 10 1 10 11 1 11 12 1 12 13 1 13 14 1 14 15 1 15 16 1 16 17 1 17 18 1 18 19 1 19 20 1 20 21 1 21 22 1 22 23 1 23 24 1 24 25 1 25 26 1 26 27 1 27 28 1 28 29 1 29 30 1 30 31 1 31 32 1 32 33 1 33 34 1 34 35 1 35 36 1 36 37 1 37 38 1 38...