# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
735507 | Cutebol | Palembang Bridges (APIO15_bridge) | C++17 | 5 ms | 452 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
void fopn(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define Ganyu ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0);
#define int long long
#define endl "\n"
#define ff first
#define ss second
const int N = 2e5 + 5 ;
const int inf = 1e9 ;
const int mod = 1e9 + 7 ;
int n , k , ans = inf ;
int b[N] , d[N] ;
char a[N] , c[N] ;
int ch ( int x ){
int sum = 0 ;
for ( int i = 0 ; i < n ; i ++ ) sum += ( a[i] != c[i] ) ? abs(b[i]-x)+abs(d[i]-x)+1 : abs(b[i]-d[i]) ;
return sum ;
}
void solve(){
cin >> k >> n ;
set <int> t ;
for ( int i = 0 ; i < n ; i ++ ) cin >> a[i] >> b[i] >> c[i] >> d[i] ;
for ( int i = 0 ; i < n ; i ++ ) ans = min({ ch(b[i]) , ans , ch(d[i]) }) ;
cout << ans ;
}
signed main(){
// fopn("") ;
// Ganyu ;
int t = 1 ;
// cin >> t ;
while ( t -- ) solve() ;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |