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 <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define fb(i,b,a) for(int i=b;i>=a;i--)
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 100005;
const ll inf = 1e18 + 5;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k) print the k-th smallest number in os(0-based)
int n, K;
array<int,4> niz[maxn];
int main()
{
ios::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
cin >> K >> n;
vector<int> vec;
vector<pii> A;
ll rez = 0;
ff(i,1,n) {
int S, T;
char p, q;
cin >> p >> S >> q >> T;
int P = p - 'A', Q = q - 'A';
if(P == Q)rez += abs(T - S);
else {
vec.pb(S), vec.pb(T);
A.pb({S, T});
}
}
if(!sz(vec))return cout << rez, 0;
sort(all(vec));
vec.erase(unique(all(vec)), vec.end());
if(K == 1){
int ivo = vec[sz(vec) / 2];
for(auto c : A) {
int S = c.fi;
int T = c.se;
rez += abs(S - ivo) + abs(T - ivo) + 1;
}
cout << rez << endl;
return 0;
}
// K = 2
ff(i,0,sz(vec) - 1){
// uzmem indeks gde ih delim
}
return 0;
}
/**
1 5
B 0 A 4
B 1 B 3
A 5 B 7
B 2 A 6
B 1 A 7
// probati bojenje sahovski ili slicno
**/
# | 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... |