Submission #55060761


Source Code Expand

#include <bits/stdc++.h>
#define endl '\n'
#define int long long

using namespace std;
using i64 = long long;

const int N = 2e5 + 5;
int n, t;
int a[N];
string s;
vector<int> x, y; // 逆行 顺行

signed main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> n >> t >> s, s = " " + s;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        if (s[i] == '0') {
            x.push_back(a[i]);
        } else {
            y.push_back(a[i]);
        }
    }
    sort(x.begin(), x.end()), sort(y.begin(), y.end());
    i64 ans = 0;
    for (auto i : x) {
        int l = lower_bound(y.begin(), y.end(), i - 2 * t) - y.begin();
        int r = upper_bound(y.begin(), y.end(), i) - y.begin();
        ans += r - l;
    }
    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task D - Ghost Ants
User NoobDidi
Language C++ 20 (gcc 12.2)
Score 350
Code Size 811 Byte
Status AC
Exec Time 34 ms
Memory 7052 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 350 / 350
Status
AC × 2
AC × 28
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3568 KiB
00_sample_01.txt AC 1 ms 3380 KiB
01_random_00.txt AC 32 ms 7012 KiB
01_random_01.txt AC 20 ms 5416 KiB
01_random_02.txt AC 33 ms 6804 KiB
01_random_03.txt AC 26 ms 6228 KiB
01_random_04.txt AC 33 ms 6876 KiB
01_random_05.txt AC 17 ms 5068 KiB
01_random_06.txt AC 33 ms 6920 KiB
01_random_07.txt AC 26 ms 6000 KiB
01_random_08.txt AC 31 ms 7052 KiB
01_random_09.txt AC 29 ms 6252 KiB
01_random_10.txt AC 34 ms 6644 KiB
01_random_11.txt AC 31 ms 6412 KiB
01_random_12.txt AC 33 ms 6968 KiB
01_random_13.txt AC 25 ms 6200 KiB
01_random_14.txt AC 32 ms 6980 KiB
01_random_15.txt AC 17 ms 5040 KiB
01_random_16.txt AC 33 ms 6988 KiB
01_random_17.txt AC 24 ms 6140 KiB
01_random_18.txt AC 33 ms 7028 KiB
01_random_19.txt AC 28 ms 6336 KiB
01_random_20.txt AC 17 ms 6700 KiB
01_random_21.txt AC 17 ms 6744 KiB
01_random_22.txt AC 19 ms 6776 KiB
01_random_23.txt AC 19 ms 6744 KiB
01_random_24.txt AC 22 ms 6948 KiB
01_random_25.txt AC 23 ms 7040 KiB