Submission #396283

# Submission time Handle Problem Language Result Execution time Memory
396283 2021-04-29T16:34:57 Z SavicS Palembang Bridges (APIO15_bridge) C++14
22 / 100
46 ms 4432 KB
#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));
    
    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;
}
/**

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
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 24 ms 2084 KB Output is correct
13 Correct 46 ms 4432 KB Output is correct
14 Correct 35 ms 3200 KB Output is correct
15 Correct 27 ms 2792 KB Output is correct
16 Correct 32 ms 3752 KB Output is correct
17 Correct 34 ms 4400 KB Output is correct
18 Correct 41 ms 4016 KB Output is correct
19 Correct 45 ms 4356 KB Output is correct
20 Correct 34 ms 3888 KB Output is correct
21 Correct 41 ms 4172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -