Submission #21501414


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 2000000030;
constexpr ll INF= 2000000000000000001;
constexpr ll MOD = 1000000007;
const double PI = 3.14159265358979323846;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

template<typename T> 
vector<T> make_vector(size_t s) {
    return vector<T>(s);
}

template<typename T,typename... Args>
auto make_vector(size_t s,Args... args) {
    return vector(s,make_vector<T>(args...));
}

template<typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

template<typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll mod(ll val, ll M) {
    val = val % M;
    if(val < 0) {
        val += M;
    }
    return val;
}

template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    ll L;
    int N;
    cin >> L >> N;
    vector<ll> A;
    vector<ll> B;
    ll Sum = 0;
    for(int i = 0;i < N;i++) {
        ll x,y;
        cin >> x >> y;
        A.push_back(x + y - (L - 1));
        B.push_back(x - y);
    }
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    A.erase(unique(A.begin(),A.end()),A.end());
    B.erase(unique(B.begin(),B.end()),B.end());
    for(auto x:A) {
        Sum += L - abs(x);
    }
    for(auto x:B) {
        Sum += L - abs(x);
    }
    vector<ll> B0;
    vector<ll> B1;
    for(auto x:B) {
        if(x % 2 == 0) B0.push_back(x);
        else B1.push_back(x);
    }
    for(auto x:A) {
        int cnt = L - 1 - abs(x);
        if(cnt % 2 == 0) {
            auto itr = lower_bound(B0.begin(),B0.end(),-cnt);
            auto itr2 = upper_bound(B0.begin(),B0.end(),cnt);
            Sum -= distance(itr,itr2);
        }
        else {
            auto itr = lower_bound(B1.begin(),B1.end(),-cnt);
            auto itr2 = upper_bound(B1.begin(),B1.end(),cnt);
            Sum -= distance(itr,itr2);
        }
    }
    cout << Sum << endl;
}

Submission Info

Submission Time
Task sengoku - 戦国時代 (Sengoku)
User AItale
Language C++ (GCC 9.2.1)
Score 100
Code Size 2379 Byte
Status AC
Exec Time 88 ms
Memory 6392 KiB

Judge Result

Set Name Set01 Set02 Set03 Set04 Set05 Set06 Set07 Set08 Set09 Set10 Set11 Set12 Set13 Set14 Set15 Set16 Set17 Set18 Set19 Set20
Score / Max Score 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5
Status
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
Set Name Test Cases
Set01 01
Set02 02
Set03 03
Set04 04
Set05 05
Set06 06
Set07 07
Set08 08
Set09 09
Set10 10
Set11 11
Set12 12
Set13 13
Set14 14
Set15 15
Set16 16
Set17 17
Set18 18
Set19 19
Set20 20
Case Name Status Exec Time Memory
01 AC 9 ms 3592 KiB
02 AC 2 ms 3528 KiB
03 AC 4 ms 3632 KiB
04 AC 5 ms 3496 KiB
05 AC 4 ms 3552 KiB
06 AC 3 ms 3468 KiB
07 AC 4 ms 3500 KiB
08 AC 5 ms 3516 KiB
09 AC 83 ms 5948 KiB
10 AC 82 ms 6300 KiB
11 AC 83 ms 6392 KiB
12 AC 86 ms 6200 KiB
13 AC 85 ms 6244 KiB
14 AC 8 ms 3604 KiB
15 AC 86 ms 6328 KiB
16 AC 83 ms 6140 KiB
17 AC 85 ms 6164 KiB
18 AC 85 ms 6168 KiB
19 AC 83 ms 6300 KiB
20 AC 88 ms 6272 KiB