# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1031589 |
2024-07-23T02:15:39 Z |
pcc |
Shortcut (IOI16_shortcut) |
C++17 |
|
1 ms |
348 KB |
#include "shortcut.h"
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC taget("avx2,popcnt,sse4")
#define pll pair<ll,ll>
#define fs first
#define sc second
#define pii pair<int,int>
#define ll long long
const ll inf = 1e18;
const int mxn = 255;
ll pref[mxn];
ll arr[mxn];
int C,N;
int trans[mxn];
vector<pll> paths[mxn];
ll dp[mxn][mxn];
ll dist[mxn];
namespace DIJKSTRA{
priority_queue<pll,vector<pll>,greater<pll>> pq;
void GO(int s){
fill(dist,dist+mxn,inf);
dist[s] = arr[s];
pq.push(pll(arr[s],s));
while(!pq.empty()){
auto [d,now] = pq.top();
pq.pop();
if(dist[now] != d)continue;
for(auto [nxt,w]:paths[now]){
if(dist[nxt]>d+w){
dist[nxt] = d+w;
pq.push(pll(dist[nxt],nxt));
}
}
}
return;
}
}
ll calc(int a,int b){
for(auto &i:paths)i.clear();
for(int i = 1;i<N;i++){
paths[i].push_back(pll(i-1,pref[i]-pref[i-1]));
paths[i-1].push_back(pll(i,pref[i]-pref[i-1]));
}
paths[b].push_back(pll(a,C));
paths[a].push_back(pll(b,C));
ll ans = 0;
for(int i = 0;i<N;i++){
DIJKSTRA::GO(i);
for(int j = 0;j<N;j++)dist[j] += arr[j];
ans = max(ans,*max_element(dist,dist+N));
}
return ans;
}
long long find_shortcut(int n, std::vector<int> l, std::vector<int> d, int c){
N = n,C = c;
for(int i = 0;i+1<N;i++){
pref[i+1] = pref[i]+l[i];
}
for(int i = 0;i<N;i++)arr[i] = d[i];
ll ans = inf;
for(int i = 0;i<N;i++){
for(int j = 0;j<=i;j++){
dp[j][i] = calc(j,i);
//cerr<<j<<' '<<i<<":"<<dp[j][i]<<endl;
ans = min(ans,dp[j][i]);
}
}
for(int i = 1;i<N;i++){
for(int j = 0;j<i;j++){
if(dp[trans[i]][i]<dp[j][i])trans[i] = j;
}
}
return ans;
}
Compilation message
shortcut.cpp:6: warning: ignoring '#pragma GCC taget' [-Wunknown-pragmas]
6 | #pragma GCC taget("avx2,popcnt,sse4")
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
348 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
348 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
348 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
348 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
348 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
348 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
348 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
348 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |