提出 #64779418


ソースコード 拡げる

// #include "my_template.hpp"
// #include "string/run_length_encoding.hpp"
// using namespace std;
// 
// void solve() {
//     INT(N, K);
//     STR(S);
//     int ocnt = 0;
//     REP(i, N) {
//         if (S[i] == 'o') {
//             if (i - 1 >= 0) S[i - 1] = '.';
//             if (i + 1 < N) S[i + 1] = '.';
//             ocnt++;
//         }
//     }
//     if (ocnt == K) {
//         REP(i, N) if (S[i] == '?') S[i] = '.';
//         print(S);
//         return;
//     }
//     auto run = run_length_encoding(S);
//     int omax = 0;
//     FORE(c, cnt, run) {
//         if (c == '?') {
//             omax += (cnt + 1) / 2;
//         }
//     }
// 
//     show(run);
//     assert(ocnt + omax >= K);
//     if (ocnt + omax == K) {
//         string ans;
//         FORE(c, cnt, run) {
//             if (c == '?') {
//                 if (cnt % 2 == 0) {
//                     ans += string(cnt, '?');
//                 } else {
//                     REP(k, cnt) {
//                         if (k % 2 == 0) {
//                             ans += 'o';
//                         } else {
//                             ans += '.';
//                         }
//                     }
//                 }
//             } else {
//                 ans += string(cnt, c);
//             }
//         }
//         print(ans);
//     } else {
//         print(S);
//     }
//     show(S);
//     return;
// }
// 
// int main() {
//     solve();
//     return 0;
// }
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <forward_list>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <optional>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#ifdef RUTHEN_LOCAL
#include <debug.hpp>
#else
#define show(x) true
#endif

// type definition
using i64 = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using f32 = float;
using f64 = double;
using f128 = long double;
template <class T> using pque = std::priority_queue<T>;
template <class T> using pqueg = std::priority_queue<T, std::vector<T>, std::greater<T>>;
// overload
#define overload4(_1, _2, _3, _4, name, ...) name
#define overload3(_1, _2, _3, name, ...) name
#define overload2(_1, _2, name, ...) name
// for loop
#define REP1(a) for (long long _ = 0; _ < (a); _++)
#define REP2(i, a) for (long long i = 0; i < (a); i++)
#define REP3(i, a, b) for (long long i = (a); i < (b); i++)
#define REP4(i, a, b, c) for (long long i = (a); i < (b); i += (c))
#define REP(...) overload4(__VA_ARGS__, REP4, REP3, REP2, REP1)(__VA_ARGS__)
#define RREP1(a) for (long long _ = (a)-1; _ >= 0; _--)
#define RREP2(i, a) for (long long i = (a)-1; i >= 0; i--)
#define RREP3(i, a, b) for (long long i = (b)-1; i >= (a); i--)
#define RREP(...) overload3(__VA_ARGS__, RREP3, RREP2, RREP1)(__VA_ARGS__)
#define FORE1(x, a) for (auto&& x : a)
#define FORE2(x, y, a) for (auto&& [x, y] : a)
#define FORE3(x, y, z, a) for (auto&& [x, y, z] : a)
#define FORE(...) overload4(__VA_ARGS__, FORE3, FORE2, FORE1)(__VA_ARGS__)
#define FORSUB(t, s) for (long long t = (s); t >= 0; t = (t == 0 ? -1 : (t - 1) & (s)))
// function
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(a) std::sort((a).begin(), (a).end())
#define RSORT(a) std::sort((a).rbegin(), (a).rend())
#define REV(a) std::reverse((a).begin(), (a).end())
#define UNIQUE(a)                      \
    std::sort((a).begin(), (a).end()); \
    (a).erase(std::unique((a).begin(), (a).end()), (a).end())
#define LEN(a) (int)((a).size())
#define MIN(a) *std::min_element((a).begin(), (a).end())
#define MAX(a) *std::max_element((a).begin(), (a).end())
#define SUM1(a) std::accumulate((a).begin(), (a).end(), 0LL)
#define SUM2(a, x) std::accumulate((a).begin(), (a).end(), (x))
#define SUM(...) overload2(__VA_ARGS__, SUM2, SUM1)(__VA_ARGS__)
#define LB(a, x) std::distance((a).begin(), std::lower_bound((a).begin(), (a).end(), (x)))
#define UB(a, x) std::distance((a).begin(), std::upper_bound((a).begin(), (a).end(), (x)))
template <class T, class U> inline bool chmin(T& a, const U& b) { return (a > T(b) ? a = b, 1 : 0); }
template <class T, class U> inline bool chmax(T& a, const U& b) { return (a < T(b) ? a = b, 1 : 0); }
template <class T, class S> inline T floor(const T x, const S y) {
    assert(y);
    return (y < 0 ? floor(-x, -y) : (x > 0 ? x / y : x / y - (x % y == 0 ? 0 : 1)));
}
template <class T, class S> inline T ceil(const T x, const S y) {
    assert(y);
    return (y < 0 ? ceil(-x, -y) : (x > 0 ? (x + y - 1) / y : x / y));
}
template <class T, class S> std::pair<T, T> inline divmod(const T x, const S y) {
    T q = floor(x, y);
    return {q, x - q * y};
}
// 10 ^ n
constexpr long long TEN(int n) { return (n == 0) ? 1 : 10LL * TEN(n - 1); }
// 1 + 2 + ... + n
#define TRI1(n) ((n) * ((n) + 1LL) / 2)
// l + (l + 1) + ... + r
#define TRI2(l, r) (((l) + (r)) * ((r) - (l) + 1LL) / 2)
#define TRI(...) overload2(__VA_ARGS__, TRI2, TRI1)(__VA_ARGS__)
// bit operation
// bit[i] (= 0 or 1)
#define IBIT(bit, i) (((bit) >> (i)) & 1)
// (0, 1, 2, 3, 4) -> (0, 1, 3, 7, 15)
#define MASK(n) ((1LL << (n)) - 1)
#define POW2(n) (1LL << (n))
// (0, 1, 2, 3, 4) -> (0, 1, 1, 2, 1)
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(i64 x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(i64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2)
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(i64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
// binary search (integer)
template <class T, class F> T bin_search(T ok, T ng, F& f) {
    // assert(f(ok) and !f(ng));
    while ((ok > ng ? ok - ng : ng - ok) > 1) {
        T md = (ng + ok) >> 1;
        (f(md) ? ok : ng) = md;
    }
    return ok;
}
// binary search (real number)
template <class T, class F> T bin_search_real(T ok, T ng, F& f, const int iter = 100) {
    // assert(f(ok) and !f(ng));
    for (int _ = 0; _ < iter; _++) {
        T md = (ng + ok) / 2;
        (f(md) ? ok : ng) = md;
    }
    return ok;
}
// floor(sqrt(x))
template <class T> constexpr T sqrt_floor(T x) { return T(sqrtl(x)); }
// check if [l1, r1) and [l2, r2) intersect
template <class T> constexpr bool intersect(const T l1, const T r1, const T l2, const T r2) { return std::max(l1, l2) < std::min(r1, r2); }
// check if [a.first, a.second) and [b.first, b.second) intersect
template <class T> constexpr bool intersect(const std::pair<T, T>& a, const std::pair<T, T>& b) { return intersect(a.first, a.second, b.first, b.second); }
// rotate matrix counterclockwise by pi / 2
template <class T> void rot(std::vector<std::vector<T>>& a) {
    if ((int)(a.size()) == 0) return;
    if ((int)(a[0].size()) == 0) return;
    int n = (int)(a.size()), m = (int)(a[0].size());
    std::vector res(m, std::vector<T>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            res[m - 1 - j][i] = a[i][j];
        }
    }
    a.swap(res);
}
// const value
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// infinity
template <class T> constexpr T INF = 0;
template <> constexpr int INF<int> = 1'000'000'000;                 // 1e9
template <> constexpr i64 INF<i64> = i64(INF<int>) * INF<int> * 2;  // 2e18
template <> constexpr u32 INF<u32> = INF<int>;                      // 1e9
template <> constexpr u64 INF<u64> = INF<i64>;                      // 2e18
template <> constexpr f32 INF<f32> = INF<i64>;                      // 2e18
template <> constexpr f64 INF<f64> = INF<i64>;                      // 2e18
template <> constexpr f128 INF<f128> = INF<i64>;                    // 2e18
// I/O
// input
template <class T> std::istream& operator>>(std::istream& is, std::vector<T>& v) {
    for (auto&& i : v) is >> i;
    return is;
}
template <class... T> void in(T&... a) { (std::cin >> ... >> a); }
void scan() {}
template <class Head, class... Tail> void scan(Head& head, Tail&... tail) {
    in(head);
    scan(tail...);
}
// input macro
#define INT(...)     \
    int __VA_ARGS__; \
    scan(__VA_ARGS__)
#define I64(...)     \
    i64 __VA_ARGS__; \
    scan(__VA_ARGS__)
#define U32(...)     \
    u32 __VA_ARGS__; \
    scan(__VA_ARGS__)
#define U64(...)     \
    u64 __VA_ARGS__; \
    scan(__VA_ARGS__)
#define F32(...)     \
    f32 __VA_ARGS__; \
    scan(__VA_ARGS__)
#define F64(...)     \
    f64 __VA_ARGS__; \
    scan(__VA_ARGS__)
#define F128(...)     \
    f128 __VA_ARGS__; \
    scan(__VA_ARGS__)
#define STR(...)             \
    std::string __VA_ARGS__; \
    scan(__VA_ARGS__)
#define CHR(...)      \
    char __VA_ARGS__; \
    scan(__VA_ARGS__)
#define VEC(type, name, size)     \
    std::vector<type> name(size); \
    scan(name)
#define VEC2(type, name1, name2, size)          \
    std::vector<type> name1(size), name2(size); \
    for (int i = 0; i < size; i++) scan(name1[i], name2[i])
#define VEC3(type, name1, name2, name3, size)                \
    std::vector<type> name1(size), name2(size), name3(size); \
    for (int i = 0; i < size; i++) scan(name1[i], name2[i], name3[i])
#define VEC4(type, name1, name2, name3, name4, size)                      \
    std::vector<type> name1(size), name2(size), name3(size), name4(size); \
    for (int i = 0; i < size; i++) scan(name1[i], name2[i], name3[i], name4[i])
#define VV(type, name, h, w)                       \
    std::vector name((h), std::vector<type>((w))); \
    scan(name)
// output
template <class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
    auto n = v.size();
    for (size_t i = 0; i < n; i++) {
        if (i) os << ' ';
        os << v[i];
    }
    return os;
}
template <class... T> void out(const T&... a) { (std::cout << ... << a); }
void print() { out('\n'); }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {
    out(head);
    if (sizeof...(Tail)) out(' ');
    print(tail...);
}
// for interactive problems
void printi() { std::cout << std::endl; }
template <class Head, class... Tail> void printi(Head&& head, Tail&&... tail) {
    out(head);
    if (sizeof...(Tail)) out(' ');
    printi(tail...);
}
// bool output
void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void NO(bool t = 1) { YES(!t); }
void No(bool t = 1) { Yes(!t); }
void no(bool t = 1) { yes(!t); }
void POSSIBLE(bool t = 1) { print(t ? "POSSIBLE" : "IMPOSSIBLE"); }
void Possible(bool t = 1) { print(t ? "Possible" : "Impossible"); }
void possible(bool t = 1) { print(t ? "possible" : "impossible"); }
void IMPOSSIBLE(bool t = 1) { POSSIBLE(!t); }
void Impossible(bool t = 1) { Possible(!t); }
void impossible(bool t = 1) { possible(!t); }
void FIRST(bool t = 1) { print(t ? "FIRST" : "SECOND"); }
void First(bool t = 1) { print(t ? "First" : "Second"); }
void first(bool t = 1) { print(t ? "first" : "second"); }
void SECOND(bool t = 1) { FIRST(!t); }
void Second(bool t = 1) { First(!t); }
void second(bool t = 1) { first(!t); }
// I/O speed up
struct SetUpIO {
    SetUpIO() {
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        std::cout << std::fixed << std::setprecision(20);
    }
} set_up_io;

template <class T> std::vector<std::pair<T, int>> run_length_encoding(const std::vector<T>& s) {
    assert((int)(s.size()) > 0);
    std::vector<std::pair<T, int>> res = {{s.front(), 0}};
    for (auto&& si : s) {
        if (si != res.back().first) {
            res.emplace_back(si, 0);
        }
        res.back().second++;
    }
    return res;
}

std::vector<std::pair<char, int>> run_length_encoding(const std::string& s) {
    const int n = (int)(s.size());
    std::vector<char> s2(n);
    for (int i = 0; i < n; i++) s2[i] = s[i];
    return run_length_encoding(s2);
}
using namespace std;

void solve() {
    INT(N, K);
    STR(S);
    int ocnt = 0;
    REP(i, N) {
        if (S[i] == 'o') {
            if (i - 1 >= 0) S[i - 1] = '.';
            if (i + 1 < N) S[i + 1] = '.';
            ocnt++;
        }
    }
    if (ocnt == K) {
        REP(i, N) if (S[i] == '?') S[i] = '.';
        print(S);
        return;
    }
    auto run = run_length_encoding(S);
    int omax = 0;
    FORE(c, cnt, run) {
        if (c == '?') {
            omax += (cnt + 1) / 2;
        }
    }

    show(run);
    assert(ocnt + omax >= K);
    if (ocnt + omax == K) {
        string ans;
        FORE(c, cnt, run) {
            if (c == '?') {
                if (cnt % 2 == 0) {
                    ans += string(cnt, '?');
                } else {
                    REP(k, cnt) {
                        if (k % 2 == 0) {
                            ans += 'o';
                        } else {
                            ans += '.';
                        }
                    }
                }
            } else {
                ans += string(cnt, c);
            }
        }
        print(ans);
    } else {
        print(S);
    }
    show(S);
    return;
}

int main() {
    solve();
    return 0;
}

提出情報

提出日時
問題 D - Logical Filling
ユーザ ruthen71
言語 C++ 23 (gcc 12.2)
得点 400
コード長 14374 Byte
結果 AC
実行時間 5 ms
メモリ 5544 KiB

コンパイルエラー

Main.cpp: In function ‘void solve()’:
Main.cpp:387:14: warning: statement has no effect [-Wunused-value]
  387 |     show(run);
      |              ^
Main.cpp:412:12: warning: statement has no effect [-Wunused-value]
  412 |     show(S);
      |            ^

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 3
AC × 43
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.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, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3420 KiB
00_sample_01.txt AC 1 ms 3420 KiB
00_sample_02.txt AC 1 ms 3460 KiB
01_random_00.txt AC 2 ms 3928 KiB
01_random_01.txt AC 5 ms 5544 KiB
01_random_02.txt AC 4 ms 5512 KiB
01_random_03.txt AC 1 ms 3624 KiB
01_random_04.txt AC 2 ms 3876 KiB
01_random_05.txt AC 2 ms 3904 KiB
01_random_06.txt AC 3 ms 4340 KiB
01_random_07.txt AC 4 ms 4332 KiB
01_random_08.txt AC 1 ms 3576 KiB
01_random_09.txt AC 3 ms 4368 KiB
01_random_10.txt AC 3 ms 4196 KiB
01_random_11.txt AC 3 ms 4056 KiB
01_random_12.txt AC 2 ms 4144 KiB
01_random_13.txt AC 3 ms 4268 KiB
01_random_14.txt AC 3 ms 4296 KiB
01_random_15.txt AC 3 ms 4200 KiB
01_random_16.txt AC 2 ms 4160 KiB
01_random_17.txt AC 3 ms 4356 KiB
01_random_18.txt AC 3 ms 4252 KiB
01_random_19.txt AC 3 ms 4212 KiB
01_random_20.txt AC 1 ms 3580 KiB
01_random_21.txt AC 1 ms 3432 KiB
01_random_22.txt AC 2 ms 3700 KiB
01_random_23.txt AC 1 ms 3456 KiB
01_random_24.txt AC 1 ms 3308 KiB
01_random_25.txt AC 1 ms 3460 KiB
01_random_26.txt AC 1 ms 3428 KiB
01_random_27.txt AC 2 ms 3512 KiB
01_random_28.txt AC 2 ms 3552 KiB
01_random_29.txt AC 2 ms 3584 KiB
01_random_30.txt AC 2 ms 3576 KiB
01_random_31.txt AC 2 ms 3580 KiB
01_random_32.txt AC 2 ms 3584 KiB
01_random_33.txt AC 2 ms 3556 KiB
01_random_34.txt AC 2 ms 3544 KiB
01_random_35.txt AC 2 ms 3584 KiB
01_random_36.txt AC 2 ms 3580 KiB
01_random_37.txt AC 2 ms 3712 KiB
01_random_38.txt AC 2 ms 3764 KiB
01_random_39.txt AC 2 ms 3744 KiB