/**
▄█▀ ▀█▀ ▄▀▄ █▀ █▄█▄█ ▄▀▄ █▀ ▄█▀
<⇋⇋⇋⋛∰≓⊂(⌒,_ゝ⌒)⊃≓∰⋛⇋⇋⇋>
♔♕♖♗♘♙ ☜❷☞✪ ィℋ६ ≈ ᗫẵℜℵĬŊĞ ✪☜❷☞ ♚♛♜♝♞♟
♔♕♖♗♘♙ ♚♛♜♝♞♟
˙·٠•●♥ Ƹ̵̡Ӝ̵̨̄Ʒ ♥●•٠·˙
2 5
B 0 A 4
B 1 B 3
A 5 B 7
B 2 A 6
B 1 A 7
**/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <time.h>
#include <map>
#include <deque>
#include <assert.h>
#include <queue>
#include <string>
#include <memory.h>
#include <set>
#include <math.h>
#define sz(s) s.size()
#define pb emplace_back
#define fr first
#define sc second
#define mk make_pair
#define int long long
#define all(s) s.begin(), s.end()
#define ok puts("ok");
using namespace std;
const int N = 2e5 + 5;
const int inf = 1e18 + 7;
int n, k, ans, cnt, a[N], b[N];
char t1[N], t2[N];
vector < int > v;
main(){
cin >> k >> n;
if( k == 1 ){
for( int i = 1; i <= n; i++ ){
cin >> t1[i] >> a[i] >> t2[i] >> b[i];
if( t1[ i ] != t2[ i ] ){
ans ++;
v.pb( a[i] );
v.pb( b[i] );
}
else{
ans += abs( a[i] - b[i] );
}
}
sort( all( v ) );
for( int i = 0; i < sz( v ) / 2; i++ ){
ans -= v[i];
}
for( int i = sz( v ) / 2; i < sz( v ); i++ ){
ans += v[i];
}
cout << ans;
}
else{
for( int i = 1; i <= n; i++ ){
cin >> t1[ i ] >> a[ i ] >> t2[ i ] >> b[ i ];
v.pb( a[i] );
v.pb( b[i] );
}
ans = inf;
for( int i = 0; i < sz( v ); i ++ ){
for( int j = 0; j <= sz( v ); j ++ ){
int sum = 0;
for( int k = 1; k <= n; k ++ ){
if( t1[ k ] == t2[ k ] ){
sum += abs( a[k] - b[k] );
continue;
}
int cur = abs( v[ i ] - a[ k ] ) + abs( v[ i ] - b[ k ] );
int res = abs( v[ j ] - a[ k ] ) + abs( v[ j ] - b[ k ] );
sum += min( res, cur ) + 1;
}
ans = min( ans, sum );
}
}
cout << ans << endl;
}
}
Compilation message
bridge.cpp:50:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
bridge.cpp: In function 'int main()':
bridge.cpp:66:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for( int i = 0; i < sz( v ) / 2; i++ ){
~~^~~~~~~~~~~~~
bridge.cpp:70:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for( int i = sz( v ) / 2; i < sz( v ); i++ ){
^
bridge.cpp:83:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for( int i = 0; i < sz( v ); i ++ ){
^
bridge.cpp:84:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for( int j = 0; j <= sz( v ); j ++ ){
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
596 KB |
Output is correct |
4 |
Correct |
3 ms |
596 KB |
Output is correct |
5 |
Correct |
4 ms |
596 KB |
Output is correct |
6 |
Correct |
3 ms |
596 KB |
Output is correct |
7 |
Correct |
3 ms |
596 KB |
Output is correct |
8 |
Correct |
4 ms |
596 KB |
Output is correct |
9 |
Correct |
3 ms |
596 KB |
Output is correct |
10 |
Correct |
3 ms |
596 KB |
Output is correct |
11 |
Correct |
3 ms |
616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
620 KB |
Output is correct |
2 |
Correct |
2 ms |
620 KB |
Output is correct |
3 |
Correct |
2 ms |
620 KB |
Output is correct |
4 |
Correct |
3 ms |
620 KB |
Output is correct |
5 |
Correct |
3 ms |
620 KB |
Output is correct |
6 |
Correct |
3 ms |
620 KB |
Output is correct |
7 |
Correct |
3 ms |
620 KB |
Output is correct |
8 |
Correct |
3 ms |
636 KB |
Output is correct |
9 |
Correct |
3 ms |
636 KB |
Output is correct |
10 |
Correct |
3 ms |
636 KB |
Output is correct |
11 |
Correct |
3 ms |
636 KB |
Output is correct |
12 |
Correct |
66 ms |
4104 KB |
Output is correct |
13 |
Correct |
137 ms |
4200 KB |
Output is correct |
14 |
Correct |
90 ms |
4200 KB |
Output is correct |
15 |
Correct |
81 ms |
4200 KB |
Output is correct |
16 |
Correct |
98 ms |
4200 KB |
Output is correct |
17 |
Correct |
124 ms |
4200 KB |
Output is correct |
18 |
Correct |
119 ms |
4200 KB |
Output is correct |
19 |
Correct |
134 ms |
4200 KB |
Output is correct |
20 |
Correct |
108 ms |
4200 KB |
Output is correct |
21 |
Correct |
125 ms |
4200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4200 KB |
Output is correct |
2 |
Correct |
2 ms |
4200 KB |
Output is correct |
3 |
Correct |
19 ms |
4200 KB |
Output is correct |
4 |
Correct |
19 ms |
4200 KB |
Output is correct |
5 |
Correct |
6 ms |
4200 KB |
Output is correct |
6 |
Correct |
2 ms |
4200 KB |
Output is correct |
7 |
Correct |
21 ms |
4200 KB |
Output is correct |
8 |
Correct |
21 ms |
4200 KB |
Output is correct |
9 |
Correct |
21 ms |
4200 KB |
Output is correct |
10 |
Correct |
21 ms |
4200 KB |
Output is correct |
11 |
Correct |
21 ms |
4200 KB |
Output is correct |
12 |
Correct |
21 ms |
4200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4200 KB |
Output is correct |
2 |
Correct |
2 ms |
4200 KB |
Output is correct |
3 |
Correct |
19 ms |
4200 KB |
Output is correct |
4 |
Correct |
19 ms |
4200 KB |
Output is correct |
5 |
Correct |
6 ms |
4200 KB |
Output is correct |
6 |
Correct |
2 ms |
4200 KB |
Output is correct |
7 |
Correct |
26 ms |
4200 KB |
Output is correct |
8 |
Correct |
23 ms |
4200 KB |
Output is correct |
9 |
Correct |
21 ms |
4200 KB |
Output is correct |
10 |
Correct |
28 ms |
4200 KB |
Output is correct |
11 |
Correct |
22 ms |
4200 KB |
Output is correct |
12 |
Correct |
21 ms |
4200 KB |
Output is correct |
13 |
Execution timed out |
2063 ms |
4200 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4200 KB |
Output is correct |
2 |
Correct |
2 ms |
4200 KB |
Output is correct |
3 |
Correct |
19 ms |
4200 KB |
Output is correct |
4 |
Correct |
19 ms |
4200 KB |
Output is correct |
5 |
Correct |
6 ms |
4200 KB |
Output is correct |
6 |
Correct |
2 ms |
4200 KB |
Output is correct |
7 |
Correct |
21 ms |
4200 KB |
Output is correct |
8 |
Correct |
21 ms |
4200 KB |
Output is correct |
9 |
Correct |
20 ms |
4200 KB |
Output is correct |
10 |
Correct |
21 ms |
4200 KB |
Output is correct |
11 |
Correct |
21 ms |
4200 KB |
Output is correct |
12 |
Correct |
21 ms |
4200 KB |
Output is correct |
13 |
Execution timed out |
2070 ms |
4200 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |