結果

問題 No.2482 Sandglasses
ユーザー nono00nono00
提出日時 2023-09-22 23:24:19
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 3,127 bytes
コンパイル時間 3,718 ms
コンパイル使用メモリ 274,960 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2024-04-28 09:03:34
合計ジャッジ時間 9,270 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 84 ms
6,400 KB
testcase_04 AC 84 ms
6,528 KB
testcase_05 AC 84 ms
6,400 KB
testcase_06 AC 84 ms
6,528 KB
testcase_07 AC 85 ms
6,528 KB
testcase_08 AC 84 ms
6,528 KB
testcase_09 AC 84 ms
6,400 KB
testcase_10 AC 84 ms
6,528 KB
testcase_11 AC 84 ms
6,528 KB
testcase_12 AC 85 ms
6,528 KB
testcase_13 AC 84 ms
6,528 KB
testcase_14 AC 86 ms
6,528 KB
testcase_15 AC 84 ms
6,528 KB
testcase_16 AC 84 ms
6,528 KB
testcase_17 AC 84 ms
6,528 KB
testcase_18 AC 85 ms
6,528 KB
testcase_19 AC 85 ms
6,400 KB
testcase_20 AC 84 ms
6,528 KB
testcase_21 AC 84 ms
6,528 KB
testcase_22 AC 84 ms
6,528 KB
testcase_23 AC 82 ms
6,528 KB
testcase_24 AC 83 ms
6,400 KB
testcase_25 AC 83 ms
6,528 KB
testcase_26 AC 83 ms
6,528 KB
testcase_27 AC 84 ms
6,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

namespace nono {

void naive() {
    int n, k, t;
    std::cin >> n >> k >> t;
    std::vector<char> a(n);
    std::vector<int> b(n);
    for (int i = 0; i < n; i++) std::cin >> a[i];
    for (int i = 0; i < n; i++) std::cin >> b[i];
    std::vector<bool> under(n);
    for (int i = 0; i < n; i++) {
        if (a[i] == 'B') {
            under[i] = true;
        }
    }
    std::map<std::vector<int>, int> mp;
    mp[b] = 0;
    for (int i = 0; i < t; i++) {
        {  //  砂移動パート
            for (int j = 0; j < n; j++) {
                if (under[j]) {
                    b[j]++;
                } else {
                    b[j]--;
                }
            }
        }
        {  //  ひっくり返しパート
            for (int j = 0; j < n; j++) {
                if (b[j] == k) {
                    under[j] = false;
                } else if (b[j] == 0) {
                    under[j] = true;
                }
            }
            for (int j = 0; j < n; j++) {
                for (int l = 0; l < n; l++) {
                    if (b[j] == b[l]) {
                        under[j] = (under[j] ? false : true);
                        under[l] = (under[l] ? false : true);
                    }
                }
            }
        }
        {  //  出力パート
        }
        if (mp.contains(b)) {
            std::cerr << "already state!!!" << std::endl;
            std::cerr << "prev: " << mp[b] << ", new: " << i + 1 << std::endl;
        }
        mp[b] = i + 1;
    }

    for (int j = 0; j < n; j++) {
        std::cerr << b[j] << ' ';
    }
    std::cerr << std::endl;
}

void solve() {
    int n, k, t;
    std::cin >> n >> k >> t;
    std::vector<char> a(n);
    std::vector<int> b(n);
    for (int i = 0; i < n; i++) std::cin >> a[i];
    for (int i = 0; i < n; i++) std::cin >> b[i];
    std::vector<int> c(n);
    t %= 2 * k;
    for (int i = 0; i < n; i++) {
        int now = b[i];
        bool plus = (a[i] == 'B');
        int s = t;
        while (s > 0) {
            if (plus) {
                if (now + s >= k) {
                    s -= k - now;
                    now = k;
                } else {
                    now += s;
                    s -= s;
                }
            } else {
                if (now <= s) {
                    s -= now;
                    now = 0;
                } else {
                    now -= s;
                    s -= s;
                }
            }
            plus ^= true;
        }
        c[i] = now;
    }
    std::ranges::sort(c);
    std::vector<int> index(n);
    std::iota(index.begin(), index.end(), 0);
    std::ranges::sort(index, [&](int lhs, int rhs) { return b[lhs] < b[rhs]; });
    std::vector<int> ans(n);
    for (int i = 0; i < n; i++) {
        ans[index[i]] = c[i];
    }
    for (int i = 0; i < n; i++) {
        std::cout << ans[i] << (i + 1 < n ? ' ' : '\n');
    }
}

}  //  namespace nono

int main() {
    std::cin.tie(0)->sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);

    int t = 1;
    while (t--) nono::solve();
}
0