提出 #17136359


ソースコード 拡げる

#include <iostream>
#include <vector>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    std::vector<std::pair<int, int>> v(n);
    for (int i = 0; i < n; i++) {
        int x, y;
        std::cin >> x >> y;
        --x; --y;
        v[x].first = y;
        v[x].second = i;
    }

    std::vector<int> comp(n), used(n);
    int s = 0, t = 0;
    for (int i = 0; i < n; i++) {
        const int y = v[i].first;
        comp[i] = t;
        used[y] = 1;
        if (y > n - 1 - i) s++;
        if (used[n - 1 - i]) s++;
        if (s == i + 1) t++;
    }

    std::vector<int> ret(n);
    for (int i = 0; i < n;) {
        int j = i + 1;
        while (j < n && comp[j] == comp[i]) j++;
        const int r = j - i;
        while (i < j) ret[v[i++].second] = r;
    }

    for (const int r : ret) std::cout << r << '\n';

    return 0;
}

提出情報

提出日時
問題 A - Reachable Towns
ユーザ CharlotteL
言語 C++ (GCC 9.2.1)
得点 300
コード長 896 Byte
結果 AC
実行時間 117 ms
メモリ 7176 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 2
AC × 24
セット名 テストケース
Sample example_00, example_01
All example_00, example_01, manyperm_00, manyperm_01, manyperm_02, manyperm_03, max_random_00, max_random_01, random_00, random_01, small_00, small_01, small_02, small_03, small_04, small_05, small_06, small_07, small_08, small_09, special1_00, special1_01, special1_02, special1_03
ケース名 結果 実行時間 メモリ
example_00 AC 12 ms 3400 KiB
example_01 AC 2 ms 3488 KiB
manyperm_00 AC 113 ms 7060 KiB
manyperm_01 AC 111 ms 7064 KiB
manyperm_02 AC 117 ms 7148 KiB
manyperm_03 AC 110 ms 6984 KiB
max_random_00 AC 108 ms 7176 KiB
max_random_01 AC 113 ms 7064 KiB
random_00 AC 76 ms 5532 KiB
random_01 AC 87 ms 6000 KiB
small_00 AC 7 ms 3396 KiB
small_01 AC 2 ms 3540 KiB
small_02 AC 2 ms 3520 KiB
small_03 AC 4 ms 3396 KiB
small_04 AC 2 ms 3520 KiB
small_05 AC 2 ms 3584 KiB
small_06 AC 2 ms 3468 KiB
small_07 AC 2 ms 3540 KiB
small_08 AC 2 ms 3632 KiB
small_09 AC 3 ms 3588 KiB
special1_00 AC 75 ms 5480 KiB
special1_01 AC 88 ms 5956 KiB
special1_02 AC 38 ms 4120 KiB
special1_03 AC 94 ms 6264 KiB