Submission #967211

# Submission time Handle Problem Language Result Execution time Memory
967211 2024-04-21T13:59:33 Z ByeWorld Palembang Bridges (APIO15_bridge) C++14
0 / 100
1 ms 600 KB
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
const int MAXN = 2e5+10;
const int INF = 1e18+10;
typedef pair<int,int> pii;
typedef pair<int,pii> ipii;

int K, n;
int ans;
vector <int> vec;
vector <pii> seg;
int pr[MAXN];

signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> K >> n;
	if(K==1){
		exit(0);
		vec.pb(-1);
		for(int i=1; i<=n; i++){
			char x, y; int a, b;
			cin >> x >> a >> y >> b; a++; b++;
			if(x==y) ans += abs(a-b);
			else {
				vec.pb(a); vec.pb(b);
			}
		}
		sort(vec.begin(), vec.end()); 

		int MN = INF, siz = vec.size()-1;
		for(int i=1; i<=siz; i++){
			ans += abs(vec[(siz+1)/2]-vec[i]);
		}
		ans += siz/2;
		cout << ans << '\n';
	} else {
		vector <int> cc; cc.pb(-1);
		seg.pb({-1, -1});
		for(int i=1; i<=n; i++){
			char x, y; int a, b;
			cin >> x >> a >> y >> b; a++; b++;
			if(x==y) ans += abs(a-b);
			else {
				if(a > b) swap(a, b);
				seg.pb({a, b});
				cc.pb(a); cc.pb(b);
			}
		}
		sort(seg.begin(), seg.end()); 
		sort(cc.begin(), cc.end());
		cc.resize(unique(cc.begin(), cc.end()) - cc.begin());

		// cout << ans << " ans\n";
		int MN = INF, siz = seg.size()-1, all = cc.size()-1, las = 1;
		for(int i=1; i<=all; i++){
			for(int j=i; j<=all; j++){
				int te = 0, le = cc[i], ri = cc[j];

				for(int k=1; k<=siz; k++){
					int l = seg[k].fi, r = seg[k].se;

					// if(l<=le && le<=r) te += (r-l);
					// else if(l<=ri && ri<=r) te += (r-l);
					// else {
						te += min(abs(l-le)+abs(r-le), abs(l-ri)+abs(r-ri));
					// }
				}
				MN = min(MN, te);
			}
		}
		ans += siz;
		cout << ans+MN << '\n';
	}
}

Compilation message

bridge.cpp: In function 'int main()':
bridge.cpp:35:7: warning: unused variable 'MN' [-Wunused-variable]
   35 |   int MN = INF, siz = vec.size()-1;
      |       ^~
bridge.cpp:59:56: warning: unused variable 'las' [-Wunused-variable]
   59 |   int MN = INF, siz = seg.size()-1, all = cc.size()-1, las = 1;
      |                                                        ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -