Submission #60534

# Submission time Handle Problem Language Result Execution time Memory
60534 2018-07-24T10:07:09 Z istlemin Palembang Bridges (APIO15_bridge) C++14
9 / 100
2000 ms 748 KB
#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for(ll i = a; i < ll(b); ++i)
#define trav(a, v) for(auto& a : v)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define D(x) cerr << #x << " = " << x << endl

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;


int main() {
    cin.sync_with_stdio(false);
	ll k,n;
	ll totDist = 0;
	vector<pii> intervals;
	vector<ll> points;
	cin>>k>>n;
	rep(i,0,n){
		char a,b;
		ll c,d;
		cin>>a>>c>>b>>d;
		if(a!=b){
			intervals.push_back(pii(c,d));
			points.push_back(c);
			points.push_back(d);
		}else{
			totDist += abs(c-d);
		}
	}
	ll bestDist = 0;
	if(intervals.size()>0){
		bestDist = 1e18;
		sort(all(points));
		points.resize(distance(points.begin(), unique(points.begin(), points.end())) );
		rep(a,0,points.size()){
			rep(b,a,points.size()){
				ll dist = 0;
				rep(i,0,intervals.size()){
					ll dist1 = abs(intervals[i].first-points[a])+abs(intervals[i].second-points[a]);
					ll dist2 = abs(intervals[i].first-points[b])+abs(intervals[i].second-points[b]);
					dist += min(dist1,dist2);
				}
				bestDist = min(dist,bestDist);
			}
		}
	}
	totDist += bestDist;
	totDist += intervals.size();
	cout<<totDist<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 288 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Incorrect 3 ms 560 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 636 KB Output is correct
2 Correct 3 ms 636 KB Output is correct
3 Incorrect 3 ms 636 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 636 KB Output is correct
2 Correct 2 ms 672 KB Output is correct
3 Correct 3 ms 672 KB Output is correct
4 Correct 8 ms 672 KB Output is correct
5 Correct 4 ms 672 KB Output is correct
6 Correct 2 ms 672 KB Output is correct
7 Correct 2 ms 672 KB Output is correct
8 Correct 15 ms 672 KB Output is correct
9 Correct 11 ms 672 KB Output is correct
10 Correct 11 ms 672 KB Output is correct
11 Correct 3 ms 672 KB Output is correct
12 Correct 13 ms 672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 672 KB Output is correct
2 Correct 2 ms 672 KB Output is correct
3 Correct 2 ms 672 KB Output is correct
4 Correct 16 ms 748 KB Output is correct
5 Correct 6 ms 748 KB Output is correct
6 Correct 3 ms 748 KB Output is correct
7 Correct 3 ms 748 KB Output is correct
8 Correct 12 ms 748 KB Output is correct
9 Correct 12 ms 748 KB Output is correct
10 Correct 13 ms 748 KB Output is correct
11 Correct 2 ms 748 KB Output is correct
12 Correct 12 ms 748 KB Output is correct
13 Correct 2 ms 748 KB Output is correct
14 Correct 35 ms 748 KB Output is correct
15 Execution timed out 2092 ms 748 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 748 KB Output is correct
2 Correct 3 ms 748 KB Output is correct
3 Correct 2 ms 748 KB Output is correct
4 Correct 9 ms 748 KB Output is correct
5 Correct 5 ms 748 KB Output is correct
6 Correct 2 ms 748 KB Output is correct
7 Correct 2 ms 748 KB Output is correct
8 Correct 12 ms 748 KB Output is correct
9 Correct 13 ms 748 KB Output is correct
10 Correct 13 ms 748 KB Output is correct
11 Correct 3 ms 748 KB Output is correct
12 Correct 11 ms 748 KB Output is correct
13 Correct 3 ms 748 KB Output is correct
14 Correct 26 ms 748 KB Output is correct
15 Execution timed out 2085 ms 748 KB Time limit exceeded
16 Halted 0 ms 0 KB -