Submission #1037828

# Submission time Handle Problem Language Result Execution time Memory
1037828 2024-07-29T08:58:17 Z Halym2007 Palembang Bridges (APIO15_bridge) C++17
9 / 100
2000 ms 4700 KB
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define ll long long
#define pii  pair <int, int>
#define sz size()
const int N = 2e5 + 5;
vector <ll> v;
char s[N], f[N];
ll a[N], b[N];
int k, n;
int main() {
//	freopen ("input.txt", "r", stdin);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> k >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> s[i] >> a[i] >> f[i] >> b[i];
		if (s[i] != f[i]) { 
			v.pb (a[i]);
			v.pb (b[i]);
		}
	}
	sort (v.begin(), v.end());
	if (k == 1) {
		ll idx = 0;
		if (v.empty()) idx = v[(int)v.sz / 2];
		ll sum = 0;
		for (int i = 1; i <= n; ++i) {
			if (s[i] == f[i]) {
				sum += abs (a[i] - b[i]);
			}	
			else {
				sum += abs (idx - a[i]);
				sum += abs (idx - b[i]);
				sum++;
			}
		}
		cout << sum;
	}
	else {
		ll jog = 0;
		for (int i = 1; i <= n; ++i) {
			if (s[i] == f[i]) {
				jog += abs (a[i] - b[i]);
			}
		}
		ll sum = -1;
		if (!v.empty())
		for (int i = 0; i < (int)v.sz; ++i) {
			for (int j = i + 1; j < (int)v.sz; ++j) {
				ll idx = v[i], idx1 = v[j];
				ll sum1 = 0;
				for (int k = 1; k <= n; ++k) {
					if (s[k] != f[k]) {
						ll a1 = abs (idx - a[k]) + abs (idx - b[k]), b1 = abs (idx1 - a[k]) + abs (idx1 - b[k]);
						sum1 += min (a1, b1);
						sum1++;
					}
				}
				if (sum == -1) sum = sum1;
				else sum = min (sum, sum1);
			}
		}
		if (sum == -1) sum = 0;
		cout << jog + sum << "\n";
	}
}
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 4700 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 4700 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 4 ms 2396 KB Output is correct
4 Correct 4 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 6 ms 2396 KB Output is correct
8 Correct 8 ms 2528 KB Output is correct
9 Correct 8 ms 2396 KB Output is correct
10 Correct 5 ms 2528 KB Output is correct
11 Correct 5 ms 2396 KB Output is correct
12 Correct 5 ms 2528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 3 ms 2528 KB Output is correct
4 Correct 3 ms 2396 KB Output is correct
5 Correct 1 ms 2528 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 5 ms 2396 KB Output is correct
8 Correct 5 ms 2392 KB Output is correct
9 Correct 4 ms 2396 KB Output is correct
10 Correct 5 ms 2396 KB Output is correct
11 Correct 5 ms 2520 KB Output is correct
12 Correct 5 ms 2396 KB Output is correct
13 Execution timed out 2059 ms 2392 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 4 ms 2396 KB Output is correct
4 Correct 4 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 5 ms 2396 KB Output is correct
8 Correct 7 ms 2396 KB Output is correct
9 Correct 6 ms 2524 KB Output is correct
10 Correct 6 ms 2396 KB Output is correct
11 Correct 5 ms 2396 KB Output is correct
12 Correct 5 ms 2396 KB Output is correct
13 Execution timed out 2050 ms 2396 KB Time limit exceeded
14 Halted 0 ms 0 KB -