Submission #967215

# Submission time Handle Problem Language Result Execution time Memory
967215 2024-04-21T14:08:11 Z ByeWorld Palembang Bridges (APIO15_bridge) C++14
0 / 100
1 ms 348 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 = 4e18+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';

		vector <int> cc; cc.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 {
				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, all = cc.size()-1, las = 1;
		for(int i=1; i<=all; i++){
				int te = 0, le = cc[i];

				for(auto ed : seg){
					int l = ed.fi, r = ed.se;

					// if(l<=le && le<=r) te += (r-l);
					// else if(l<=ri && ri<=r) te += (r-l);
					// else {
						te += abs(l-le)+abs(r-le);
					// }
				}
				MN = min(MN, te);
		}
		ans += seg.size();
		cout << ans+MN << '\n';
	} else {
		vector <int> cc; cc.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 {
				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, 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(auto ed : seg){
					int l = ed.fi, r = ed.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 += seg.size();
		cout << ans+MN << '\n';
	}
}

Compilation message

bridge.cpp: In function 'int main()':
bridge.cpp:58:36: warning: unused variable 'las' [-Wunused-variable]
   58 |   int MN = INF, all = cc.size()-1, las = 1;
      |                                    ^~~
bridge.cpp:92:36: warning: unused variable 'las' [-Wunused-variable]
   92 |   int MN = INF, all = cc.size()-1, las = 1;
      |                                    ^~~
# 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 1 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 -