# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
71022 |
2018-08-24T02:40:21 Z |
funcsr |
Wiring (IOI17_wiring) |
C++17 |
|
120 ms |
13992 KB |
#include "wiring.h"
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define INF (1LL<<60)
#define _1 first
#define _2 second
using namespace std;
typedef pair<int, int> P;
inline void chmin(long long &x, long long v) { if(x>v)x=v; }
int N;
long long dp[2][401][401];
long long cost[401];
long long solveAB(vector<int> A, vector<int> B) {
if (A[0] > B[0]) swap(A, B);
long long sum = 0;
rep(i, A.size()-1) sum += 1LL*(i+1)*(A[i+1]-A[i]);
sum += 1LL*(max(A.size(), B.size()))*(B[0]-A[A.size()-1]);
rep(i, B.size()-1) sum += 1LL*(B.size()-1-i)*(B[i+1]-B[i]);
return sum;
}
long long min_total_length(vector<int> R, vector<int> B) {
//return solveAB(R, B);
if (R.size() < B.size()) swap(R, B);
//cout<<"red={";for(int x :R)cout<<x<<",";cout<<"}\n";
vector<P> all;
for (int x : R) all.pb(P(x, 0));
for (int x : B) all.pb(P(x, 1));
sort(all(all));
N = all.size();
rep(i, N) {
cost[i] = INF;
if (all[i]._2 == 0) {
auto it = lower_bound(all(B), all[i]._1);
if (it != B.end()) chmin(cost[i], *it-all[i]._1);
if (it != B.begin()) chmin(cost[i], all[i]._1-*(--it));
}
else {
auto it = lower_bound(all(R), all[i]._1);
if (it != R.end()) chmin(cost[i], *it-all[i]._1);
if (it != R.begin()) chmin(cost[i], all[i]._1-*(--it));
}
}
vector<pair<long long, long long> > vs;
rep(i, N) if (all[i]._2 == 0) vs.pb(P(cost[i], i));
sort(all(vs), greater<pair<long long, long long> >());
vs.resize(N-2*min(R.size(),B.size()));
//cout<<"ok:";rep(i, vs.size()) cout<<vs[i]._2<<",";cout<<"\n";
//rep(i, N) cost[i] = INF;
//for (P p : vs) cost[p._2] = p._1;
//rep(i,N)cout<<cost[i]<<",";cout<<"\n";
rep(j, N+1) rep(k, N+1) dp[0][j][k] = INF;
dp[0][0][0] = 0;
rep(i, N) {
rep(j, N+1) rep(k, N+1) dp[1][j][k] = INF;
int pos = all[i]._1, color = all[i]._2;
rep(j, N) {
rep(k, N) {
if (j > 0 && k > 0) continue;
// [
if (color == 0) chmin(dp[1][j+1][k], dp[0][j][k]-pos);
if (color == 1) chmin(dp[1][j][k+1], dp[0][j][k]-pos);
// ]
if (color == 1 && j > 0) chmin(dp[1][j-1][k], dp[0][j][k]+pos);
if (color == 0 && k > 0) chmin(dp[1][j][k-1], dp[0][j][k]+pos);
// .
if (color == 0) chmin(dp[1][j][k], dp[0][j][k] + cost[i]);
}
}
swap(dp[0], dp[1]);
}
return dp[0][0][0];
}
Compilation message
wiring.cpp: In function 'long long int solveAB(std::vector<int>, std::vector<int>)':
wiring.cpp:7:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i, n) for (int i=0; i<(n); i++)
^
wiring.cpp:24:3: note: in expansion of macro 'rep'
rep(i, A.size()-1) sum += 1LL*(i+1)*(A[i+1]-A[i]);
^~~
wiring.cpp:7:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i, n) for (int i=0; i<(n); i++)
^
wiring.cpp:26:3: note: in expansion of macro 'rep'
rep(i, B.size()-1) sum += 1LL*(B.size()-1-i)*(B[i+1]-B[i]);
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
2812 KB |
Output is correct |
2 |
Incorrect |
14 ms |
2884 KB |
3rd lines differ - on the 1st token, expected: '14340', found: '17422' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
2996 KB |
Output is correct |
2 |
Correct |
120 ms |
3088 KB |
Output is correct |
3 |
Runtime error |
109 ms |
13992 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
13992 KB |
Output is correct |
2 |
Incorrect |
10 ms |
13992 KB |
3rd lines differ - on the 1st token, expected: '17703', found: '19052' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
13992 KB |
3rd lines differ - on the 1st token, expected: '27', found: '30' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
2812 KB |
Output is correct |
2 |
Incorrect |
14 ms |
2884 KB |
3rd lines differ - on the 1st token, expected: '14340', found: '17422' |
3 |
Halted |
0 ms |
0 KB |
- |