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 std;
using namespace __gnu_pbds;
// VVI
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define ll long long
#define SZ(a) (int)a.size()
#define UNIQUE(a) (a).erase(unique(all(a)), (a).end())
#define mp make_pair
#define mem(a, b) memset(a, b, sizeof(a))
#define all(x) x.begin(), x.end()
//Printings & debugging
#define nn '\n'
#define Setpre(n) cout << fixed << setprecision(n)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define debug printf("I am here\n")
// CONSTANTS
#define md 10000007
#define PI acos(-1)
const long double EPS = 1e-9;
const ll N = 2e5 + 10;
const ll M = 1e9 + 7;
/// INLINE FUNCTIONS
inline ll GCD(ll a, ll b) { return b == 0 ? a : GCD(b, a % b); }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline long double logb(ll base, ll num) { return ( long double )log(num) / ( long double )log(base); }
/// Data structures
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vpll;
typedef vector<vl> vvl;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using QP = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T, typename R>
using ordered_map = tree<T, R, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T, typename R>
using ordered_multimap = tree<T, R, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
namespace io{
template<typename First, typename Second> ostream& operator << ( ostream &os, const pair<First, Second> &p ) { return os << p.first << " " << p.second; }
template<typename First, typename Second> ostream& operator << ( ostream &os, const map<First, Second> &mp ) { for( auto it : mp ) { os << it << endl; } return os; }
template<typename First> ostream& operator << ( ostream &os, const vector<First> &v ) { bool space = false; for( First x : v ) { if( space ) os << " "; space = true; os << x; } return os; }
template<typename First> ostream& operator << ( ostream &os, const set<First> &st ) { bool space = false; for( First x : st ) { if( space ) os << " "; space = true; os << x; } return os; }
template<typename First> ostream& operator << ( ostream &os, const multiset<First> &st ) { bool space = false; for( First x : st ) { if( space ) os << " "; space = true; os << x; } return os; }
template<typename First, typename Second> istream& operator >> ( istream &is, pair<First, Second> &p ) { return is >> p.first >> p.second; }
template<typename First> istream& operator >> ( istream &is, vector<First> &v ) { for( First &x : v ) { is >> x; } return is; }
long long fastread(){ char c; long long d = 1, x = 0; do c = getchar(); while( c == ' ' || c == '\n' ); if( c == '-' ) c = getchar(), d = -1; while( isdigit( c ) ){ x = x * 10 + c - '0'; c = getchar(); } return d * x; }
static bool sep = false;
using std::to_string;
string to_string( bool x ){ return ( x ? "true" : "false" ); }
string to_string( const string & s ){ return "\"" + s + "\""; }
string to_string( const char * s ){ return "\"" + string( s ) + "\""; }
string to_string ( const char & c ) { string s; s += c; return "\'" + s + "\'"; }
template<typename Type> string to_string( vector<Type> );
template<typename First, typename Second> string to_string( pair<First, Second> );
template<typename Collection> string to_string( Collection );
template<typename First, typename Second> string to_string( pair<First, Second> p ){ return "{" + to_string( p.first ) + ", " + to_string( p.second ) + "}"; }
template<typename Type> string to_string( vector<Type> v ) { bool sep = false; string s = "["; for( Type x: v ){ if( sep ) s += ", "; sep = true; s += to_string( x ); } s += "]"; return s; }
template<typename Collection> string to_string( Collection collection ) { bool sep = false; string s = "{"; for( auto x: collection ){ if( sep ) s += ", "; sep = true; s += to_string( x ); } s += "}"; return s; }
void print() { cerr << endl; sep = false; }
template <typename First, typename... Other> void print( First first, Other... other ) { if( sep ) cerr << " | "; sep = true; cerr << to_string( first ); print( other... ); }
} using namespace io;
const ll INF=1e15+500;
// ll mul(ll x) {return x==0 ? 1 : mul(x-1)*10;}
const int MAXN=2e5+5;
const ll MOD=1e9+7;
#define p(i,n) for(ll i=0; i<n; i++)
#define rp(i,n) for(ll i=n-1; i>=0; i--)
#define grid_ll vector<vector<ll>>
#define grid_char vector<vector<char>>
void ADD(ll& a, ll b, ll m) {a = ((a % m) + (b % m)) % m;return;}
void MUL(ll& a, ll b, ll m) {a = ((a % m) * (b % m)) % m;}
void SUB(ll& a, ll b, ll m) {a = ((a % m) - (b % m) + m) % m;}
void MIN(ll& a, ll b) {a = min(a, b);}
void MAX(ll& a, ll b) {a = max(a, b);}
ll INV(ll p, ll q, ll m) { ll e = m - 2; while (e) { if (e & 1) MUL(p, q, m); MUL(q, q, m); e >>= 1;} return p;}
#define f first
#define s second
struct lazysegtree{
vector<pll> st;
vector<ll> lazy;
lazysegtree(ll n){
st.assign(4*n,{-INF,INF});
lazy.assign(4*n, 0);
}
void push(ll node, ll lo, ll hi){
if (lazy[node]!=0){
st[node].f+=lazy[node];
st[node].s+=lazy[node];
}
if (lo!=hi){
lazy[2*node]+=lazy[node];
lazy[2*node+1]+=lazy[node];
}
lazy[node]=0;
}
pll combine(pll a, pll b){
return mp(max(a.f,b.f),min(a.s,b.s));
}
void build(vector<ll>& v, ll node, ll lo, ll hi){
if (lo==hi) st[node]=mp(v[lo],v[lo]);
else {
ll mid=(lo+hi)/2;
build(v,2*node,lo,mid); build(v,2*node+1,mid+1,hi);
st[node]=combine(st[2*node],st[2*node+1]);
}
}
void upd(ll node,ll lo, ll hi, ll l , ll r, ll val){
push(node,lo,hi);
if (lo>r or hi<l) return;
if (lo>=l and hi<=r){
lazy[node]+=val;
push(node,lo,hi);
return;
}
ll mid=(lo+hi)/2;
upd(2*node,lo,mid,l,r,val); upd(2*node+1,mid+1,hi,l,r,val);
st[node]=combine(st[2*node],st[2*node+1]);
}
pll query(ll node,ll lo,ll hi, ll l,ll r){
push(node,lo,hi);
if (lo>r or hi<l ) return mp(-INF,INF);
if (lo>=l and hi<=r) return st[node];
ll mid=(lo+hi)/2;
pll up=query(2*node,lo,mid,l,r);
pll down=query(2*node+1,mid+1,hi,l,r);
return combine(up,down);
}
};
signed main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt" , "w" , stdout);
#endif
fast
ll k,n; cin>>k>>n;
vector<ll> p; vector<ll> q;
ll ans=0; ll mid=0;
for(ll i=0; i<n; i++){
char x,y; ll a,b;
cin>>x>>a>>y>>b;
if (x==y){
ans+=abs(b-a);
}
else {
p.push_back(a);
q.push_back(b);
mid+=(b+a)/2;
}
}
ll sz=p.size();
mid=mid/sz;
for(ll i=0; i<sz; i++){
ans+=(abs(p[i]-mid)+1+abs(mid-q[i]));
}
cout<<ans<<nn;
}
Compilation message (stderr)
bridge.cpp: In function 'int main()':
bridge.cpp:152:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
152 | freopen("input.txt", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bridge.cpp:153:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
153 | freopen("output.txt" , "w" , stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |